xref: /llvm-project/lldb/test/API/api/multithreaded/some_cmd.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1""" Test command for checking the Python commands can run in a stop-hook """
2import lldb
3
4did_run = False
5
6
7class SomeCommand:
8    def __init__(self, debugger, unused):
9        self.dbg = debugger
10
11    def __call__(self, debugger, command, exe_ctx, result):
12        global did_run
13        did_run = True
14        result.PutCString("some output\n")
15
16    def get_short_help(self):
17        return "Test command - sets a variable."
18
19
20class OtherCommand:
21    def __init__(self, debugger, unused):
22        self.dbg = debugger
23
24    def __call__(self, debugger, command, exe_ctx, result):
25        global did_run
26        if did_run:
27            result.SetStatus(lldb.eReturnStatusSuccessFinishNoResult)
28        else:
29            result.SetStatus(lldb.eReturnStatusFailed)
30
31    def get_short_help(self):
32        return "Test command - sets a variable."
33
34
35def __lldb_init_module(debugger, unused):
36    print("Adding command some-cmd and report-cmd")
37    debugger.HandleCommand("command script add -c some_cmd.SomeCommand some-cmd")
38    debugger.HandleCommand("command script add -c some_cmd.OtherCommand report-cmd")
39