xref: /llvm-project/lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py (revision caea440a11e47bf86b0e43feb28a9287e4fbe3f8)
1import os,struct, signal
2
3from typing import Any, Dict
4
5import lldb
6from lldb.plugins.scripted_process import ScriptedProcess
7from lldb.plugins.scripted_process import ScriptedThread
8
9class InvalidScriptedProcess(ScriptedProcess):
10    def __init__(self, target: lldb.SBTarget, args : lldb.SBStructuredData):
11        super().__init__(target, args)
12
13    def get_memory_region_containing_address(self, addr: int) -> lldb.SBMemoryRegionInfo:
14        return None
15
16    def get_thread_with_id(self, tid: int):
17        return {}
18
19    def get_registers_for_thread(self, tid: int):
20        return {}
21
22    def read_memory_at_address(self, addr: int, size: int) -> lldb.SBData:
23        return None
24
25    def get_loaded_images(self):
26        return self.loaded_images
27
28    def get_process_id(self) -> int:
29        return 666
30
31    def should_stop(self) -> bool:
32        return True
33
34    def is_alive(self) -> bool:
35        return True
36
37    def get_scripted_thread_plugin(self):
38        return InvalidScriptedThread.__module__ + "." + InvalidScriptedThread.__name__
39
40
41class InvalidScriptedThread(ScriptedThread):
42    def __init__(self, process, args):
43        super().__init__(process, args)
44
45    def get_thread_id(self) -> int:
46        return 0x19
47
48    def get_name(self) -> str:
49        return InvalidScriptedThread.__name__ + ".thread-1"
50
51    def get_state(self) -> int:
52        return lldb.eStateInvalid
53
54    def get_stop_reason(self) -> Dict[str, Any]:
55        return { "type": lldb.eStopReasonSignal, "data": {
56            "signal": signal.SIGINT
57        } }
58
59    def get_stackframes(self):
60        class ScriptedStackFrame:
61            def __init__(idx, cfa, pc, symbol_ctx):
62                self.idx = idx
63                self.cfa = cfa
64                self.pc = pc
65                self.symbol_ctx = symbol_ctx
66
67
68        symbol_ctx = lldb.SBSymbolContext()
69        frame_zero = ScriptedStackFrame(0, 0x42424242, 0x5000000, symbol_ctx)
70        self.frames.append(frame_zero)
71
72        return self.frame_zero[0:0]
73
74    def get_register_context(self) -> str:
75        return None
76
77def __lldb_init_module(debugger, dict):
78    if not 'SKIP_SCRIPTED_PROCESS_LAUNCH' in os.environ:
79        debugger.HandleCommand(
80            "process launch -C %s.%s" % (__name__,
81                                     InvalidScriptedProcess.__name__))
82    else:
83        print("Name of the class that will manage the scripted process: '%s.%s'"
84                % (__name__, InvalidScriptedProcess.__name__))