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