xref: /llvm-project/lldb/test/API/functionalities/plugins/python_os_plugin/operating_system2.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1515bc8c1Sserge-sans-paille#!/usr/bin/env python
299451b44SJordan Rupprecht
399451b44SJordan Rupprechtimport lldb
499451b44SJordan Rupprechtimport struct
599451b44SJordan Rupprecht
699451b44SJordan Rupprecht
799451b44SJordan Rupprechtclass OperatingSystemPlugIn(object):
899451b44SJordan Rupprecht    """Class that provides data for an instance of a LLDB 'OperatingSystemPython' plug-in class"""
999451b44SJordan Rupprecht
1099451b44SJordan Rupprecht    def __init__(self, process):
11*2238dcc3SJonas Devlieghere        """Initialization needs a valid.SBProcess object.
1299451b44SJordan Rupprecht
1399451b44SJordan Rupprecht        This plug-in will get created after a live process is valid and has stopped for the
14*2238dcc3SJonas Devlieghere        first time."""
1599451b44SJordan Rupprecht        self.process = None
1699451b44SJordan Rupprecht        self.registers = None
1799451b44SJordan Rupprecht        self.threads = None
1899451b44SJordan Rupprecht        if isinstance(process, lldb.SBProcess) and process.IsValid():
1999451b44SJordan Rupprecht            self.process = process
2099451b44SJordan Rupprecht            self.threads = None  # Will be an dictionary containing info for each thread
2199451b44SJordan Rupprecht
2299451b44SJordan Rupprecht    def get_target(self):
2399451b44SJordan Rupprecht        # NOTE: Don't use "lldb.target" when trying to get your target as the "lldb.target"
2499451b44SJordan Rupprecht        # tracks the current target in the LLDB command interpreter which isn't the
2599451b44SJordan Rupprecht        # correct thing to use for this plug-in.
2699451b44SJordan Rupprecht        return self.process.target
2799451b44SJordan Rupprecht
2899451b44SJordan Rupprecht    def create_thread(self, tid, context):
2999451b44SJordan Rupprecht        if tid == 0x444444444:
3099451b44SJordan Rupprecht            thread_info = {
31*2238dcc3SJonas Devlieghere                "tid": tid,
32*2238dcc3SJonas Devlieghere                "name": "four",
33*2238dcc3SJonas Devlieghere                "queue": "queue4",
34*2238dcc3SJonas Devlieghere                "state": "stopped",
35*2238dcc3SJonas Devlieghere                "stop_reason": "none",
36*2238dcc3SJonas Devlieghere            }
3799451b44SJordan Rupprecht            self.threads.append(thread_info)
3899451b44SJordan Rupprecht            return thread_info
3999451b44SJordan Rupprecht        return None
4099451b44SJordan Rupprecht
4199451b44SJordan Rupprecht    def get_thread_info(self):
4299451b44SJordan Rupprecht        if not self.threads:
4399451b44SJordan Rupprecht            # The sample dictionary below shows the values that can be returned for a thread
4499451b44SJordan Rupprecht            # tid => thread ID (mandatory)
4599451b44SJordan Rupprecht            # name => thread name (optional key/value pair)
4699451b44SJordan Rupprecht            # queue => thread dispatch queue name (optional key/value pair)
4799451b44SJordan Rupprecht            # state => thred state (mandatory, set to 'stopped' for now)
4899451b44SJordan Rupprecht            # stop_reason => thread stop reason. (mandatory, usually set to 'none')
4999451b44SJordan Rupprecht            #  Possible values include:
5099451b44SJordan Rupprecht            #   'breakpoint' if the thread is stopped at a breakpoint
5199451b44SJordan Rupprecht            #   'none' thread is just stopped because the process is stopped
5299451b44SJordan Rupprecht            #   'trace' the thread just single stepped
5399451b44SJordan Rupprecht            #   The usual value for this while threads are in memory is 'none'
5499451b44SJordan Rupprecht            # register_data_addr => the address of the register data in memory (optional key/value pair)
5599451b44SJordan Rupprecht            #   Specifying this key/value pair for a thread will avoid a call to get_register_data()
5699451b44SJordan Rupprecht            #   and can be used when your registers are in a thread context structure that is contiguous
5799451b44SJordan Rupprecht            #   in memory. Don't specify this if your register layout in memory doesn't match the layout
5899451b44SJordan Rupprecht            # described by the dictionary returned from a call to the
5999451b44SJordan Rupprecht            # get_register_info() method.
60*2238dcc3SJonas Devlieghere            self.threads = [{"tid": 0x111111111, "core": 0}]
6199451b44SJordan Rupprecht        return self.threads
6299451b44SJordan Rupprecht
6399451b44SJordan Rupprecht    def get_register_info(self):
6499451b44SJordan Rupprecht        if self.registers is None:
6599451b44SJordan Rupprecht            self.registers = dict()
66*2238dcc3SJonas Devlieghere            self.registers["sets"] = ["GPR"]
67*2238dcc3SJonas Devlieghere            self.registers["registers"] = [
68*2238dcc3SJonas Devlieghere                {
69*2238dcc3SJonas Devlieghere                    "name": "rax",
70*2238dcc3SJonas Devlieghere                    "bitsize": 64,
71*2238dcc3SJonas Devlieghere                    "offset": 0,
72*2238dcc3SJonas Devlieghere                    "encoding": "uint",
73*2238dcc3SJonas Devlieghere                    "format": "hex",
74*2238dcc3SJonas Devlieghere                    "set": 0,
75*2238dcc3SJonas Devlieghere                    "gcc": 0,
76*2238dcc3SJonas Devlieghere                    "dwarf": 0,
77*2238dcc3SJonas Devlieghere                },
78*2238dcc3SJonas Devlieghere                {
79*2238dcc3SJonas Devlieghere                    "name": "rbx",
80*2238dcc3SJonas Devlieghere                    "bitsize": 64,
81*2238dcc3SJonas Devlieghere                    "offset": 8,
82*2238dcc3SJonas Devlieghere                    "encoding": "uint",
83*2238dcc3SJonas Devlieghere                    "format": "hex",
84*2238dcc3SJonas Devlieghere                    "set": 0,
85*2238dcc3SJonas Devlieghere                    "gcc": 3,
86*2238dcc3SJonas Devlieghere                    "dwarf": 3,
87*2238dcc3SJonas Devlieghere                },
88*2238dcc3SJonas Devlieghere                {
89*2238dcc3SJonas Devlieghere                    "name": "rcx",
90*2238dcc3SJonas Devlieghere                    "bitsize": 64,
91*2238dcc3SJonas Devlieghere                    "offset": 16,
92*2238dcc3SJonas Devlieghere                    "encoding": "uint",
93*2238dcc3SJonas Devlieghere                    "format": "hex",
94*2238dcc3SJonas Devlieghere                    "set": 0,
95*2238dcc3SJonas Devlieghere                    "gcc": 2,
96*2238dcc3SJonas Devlieghere                    "dwarf": 2,
97*2238dcc3SJonas Devlieghere                    "generic": "arg4",
98*2238dcc3SJonas Devlieghere                    "alt-name": "arg4",
99*2238dcc3SJonas Devlieghere                },
100*2238dcc3SJonas Devlieghere                {
101*2238dcc3SJonas Devlieghere                    "name": "rdx",
102*2238dcc3SJonas Devlieghere                    "bitsize": 64,
103*2238dcc3SJonas Devlieghere                    "offset": 24,
104*2238dcc3SJonas Devlieghere                    "encoding": "uint",
105*2238dcc3SJonas Devlieghere                    "format": "hex",
106*2238dcc3SJonas Devlieghere                    "set": 0,
107*2238dcc3SJonas Devlieghere                    "gcc": 1,
108*2238dcc3SJonas Devlieghere                    "dwarf": 1,
109*2238dcc3SJonas Devlieghere                    "generic": "arg3",
110*2238dcc3SJonas Devlieghere                    "alt-name": "arg3",
111*2238dcc3SJonas Devlieghere                },
112*2238dcc3SJonas Devlieghere                {
113*2238dcc3SJonas Devlieghere                    "name": "rdi",
114*2238dcc3SJonas Devlieghere                    "bitsize": 64,
115*2238dcc3SJonas Devlieghere                    "offset": 32,
116*2238dcc3SJonas Devlieghere                    "encoding": "uint",
117*2238dcc3SJonas Devlieghere                    "format": "hex",
118*2238dcc3SJonas Devlieghere                    "set": 0,
119*2238dcc3SJonas Devlieghere                    "gcc": 5,
120*2238dcc3SJonas Devlieghere                    "dwarf": 5,
121*2238dcc3SJonas Devlieghere                    "generic": "arg1",
122*2238dcc3SJonas Devlieghere                    "alt-name": "arg1",
123*2238dcc3SJonas Devlieghere                },
124*2238dcc3SJonas Devlieghere                {
125*2238dcc3SJonas Devlieghere                    "name": "rsi",
126*2238dcc3SJonas Devlieghere                    "bitsize": 64,
127*2238dcc3SJonas Devlieghere                    "offset": 40,
128*2238dcc3SJonas Devlieghere                    "encoding": "uint",
129*2238dcc3SJonas Devlieghere                    "format": "hex",
130*2238dcc3SJonas Devlieghere                    "set": 0,
131*2238dcc3SJonas Devlieghere                    "gcc": 4,
132*2238dcc3SJonas Devlieghere                    "dwarf": 4,
133*2238dcc3SJonas Devlieghere                    "generic": "arg2",
134*2238dcc3SJonas Devlieghere                    "alt-name": "arg2",
135*2238dcc3SJonas Devlieghere                },
136*2238dcc3SJonas Devlieghere                {
137*2238dcc3SJonas Devlieghere                    "name": "rbp",
138*2238dcc3SJonas Devlieghere                    "bitsize": 64,
139*2238dcc3SJonas Devlieghere                    "offset": 48,
140*2238dcc3SJonas Devlieghere                    "encoding": "uint",
141*2238dcc3SJonas Devlieghere                    "format": "hex",
142*2238dcc3SJonas Devlieghere                    "set": 0,
143*2238dcc3SJonas Devlieghere                    "gcc": 6,
144*2238dcc3SJonas Devlieghere                    "dwarf": 6,
145*2238dcc3SJonas Devlieghere                    "generic": "fp",
146*2238dcc3SJonas Devlieghere                    "alt-name": "fp",
147*2238dcc3SJonas Devlieghere                },
148*2238dcc3SJonas Devlieghere                {
149*2238dcc3SJonas Devlieghere                    "name": "rsp",
150*2238dcc3SJonas Devlieghere                    "bitsize": 64,
151*2238dcc3SJonas Devlieghere                    "offset": 56,
152*2238dcc3SJonas Devlieghere                    "encoding": "uint",
153*2238dcc3SJonas Devlieghere                    "format": "hex",
154*2238dcc3SJonas Devlieghere                    "set": 0,
155*2238dcc3SJonas Devlieghere                    "gcc": 7,
156*2238dcc3SJonas Devlieghere                    "dwarf": 7,
157*2238dcc3SJonas Devlieghere                    "generic": "sp",
158*2238dcc3SJonas Devlieghere                    "alt-name": "sp",
159*2238dcc3SJonas Devlieghere                },
160*2238dcc3SJonas Devlieghere                {
161*2238dcc3SJonas Devlieghere                    "name": "r8",
162*2238dcc3SJonas Devlieghere                    "bitsize": 64,
163*2238dcc3SJonas Devlieghere                    "offset": 64,
164*2238dcc3SJonas Devlieghere                    "encoding": "uint",
165*2238dcc3SJonas Devlieghere                    "format": "hex",
166*2238dcc3SJonas Devlieghere                    "set": 0,
167*2238dcc3SJonas Devlieghere                    "gcc": 8,
168*2238dcc3SJonas Devlieghere                    "dwarf": 8,
169*2238dcc3SJonas Devlieghere                    "generic": "arg5",
170*2238dcc3SJonas Devlieghere                    "alt-name": "arg5",
171*2238dcc3SJonas Devlieghere                },
172*2238dcc3SJonas Devlieghere                {
173*2238dcc3SJonas Devlieghere                    "name": "r9",
174*2238dcc3SJonas Devlieghere                    "bitsize": 64,
175*2238dcc3SJonas Devlieghere                    "offset": 72,
176*2238dcc3SJonas Devlieghere                    "encoding": "uint",
177*2238dcc3SJonas Devlieghere                    "format": "hex",
178*2238dcc3SJonas Devlieghere                    "set": 0,
179*2238dcc3SJonas Devlieghere                    "gcc": 9,
180*2238dcc3SJonas Devlieghere                    "dwarf": 9,
181*2238dcc3SJonas Devlieghere                    "generic": "arg6",
182*2238dcc3SJonas Devlieghere                    "alt-name": "arg6",
183*2238dcc3SJonas Devlieghere                },
184*2238dcc3SJonas Devlieghere                {
185*2238dcc3SJonas Devlieghere                    "name": "r10",
186*2238dcc3SJonas Devlieghere                    "bitsize": 64,
187*2238dcc3SJonas Devlieghere                    "offset": 80,
188*2238dcc3SJonas Devlieghere                    "encoding": "uint",
189*2238dcc3SJonas Devlieghere                    "format": "hex",
190*2238dcc3SJonas Devlieghere                    "set": 0,
191*2238dcc3SJonas Devlieghere                    "gcc": 10,
192*2238dcc3SJonas Devlieghere                    "dwarf": 10,
193*2238dcc3SJonas Devlieghere                },
194*2238dcc3SJonas Devlieghere                {
195*2238dcc3SJonas Devlieghere                    "name": "r11",
196*2238dcc3SJonas Devlieghere                    "bitsize": 64,
197*2238dcc3SJonas Devlieghere                    "offset": 88,
198*2238dcc3SJonas Devlieghere                    "encoding": "uint",
199*2238dcc3SJonas Devlieghere                    "format": "hex",
200*2238dcc3SJonas Devlieghere                    "set": 0,
201*2238dcc3SJonas Devlieghere                    "gcc": 11,
202*2238dcc3SJonas Devlieghere                    "dwarf": 11,
203*2238dcc3SJonas Devlieghere                },
204*2238dcc3SJonas Devlieghere                {
205*2238dcc3SJonas Devlieghere                    "name": "r12",
206*2238dcc3SJonas Devlieghere                    "bitsize": 64,
207*2238dcc3SJonas Devlieghere                    "offset": 96,
208*2238dcc3SJonas Devlieghere                    "encoding": "uint",
209*2238dcc3SJonas Devlieghere                    "format": "hex",
210*2238dcc3SJonas Devlieghere                    "set": 0,
211*2238dcc3SJonas Devlieghere                    "gcc": 12,
212*2238dcc3SJonas Devlieghere                    "dwarf": 12,
213*2238dcc3SJonas Devlieghere                },
214*2238dcc3SJonas Devlieghere                {
215*2238dcc3SJonas Devlieghere                    "name": "r13",
216*2238dcc3SJonas Devlieghere                    "bitsize": 64,
217*2238dcc3SJonas Devlieghere                    "offset": 104,
218*2238dcc3SJonas Devlieghere                    "encoding": "uint",
219*2238dcc3SJonas Devlieghere                    "format": "hex",
220*2238dcc3SJonas Devlieghere                    "set": 0,
221*2238dcc3SJonas Devlieghere                    "gcc": 13,
222*2238dcc3SJonas Devlieghere                    "dwarf": 13,
223*2238dcc3SJonas Devlieghere                },
224*2238dcc3SJonas Devlieghere                {
225*2238dcc3SJonas Devlieghere                    "name": "r14",
226*2238dcc3SJonas Devlieghere                    "bitsize": 64,
227*2238dcc3SJonas Devlieghere                    "offset": 112,
228*2238dcc3SJonas Devlieghere                    "encoding": "uint",
229*2238dcc3SJonas Devlieghere                    "format": "hex",
230*2238dcc3SJonas Devlieghere                    "set": 0,
231*2238dcc3SJonas Devlieghere                    "gcc": 14,
232*2238dcc3SJonas Devlieghere                    "dwarf": 14,
233*2238dcc3SJonas Devlieghere                },
234*2238dcc3SJonas Devlieghere                {
235*2238dcc3SJonas Devlieghere                    "name": "r15",
236*2238dcc3SJonas Devlieghere                    "bitsize": 64,
237*2238dcc3SJonas Devlieghere                    "offset": 120,
238*2238dcc3SJonas Devlieghere                    "encoding": "uint",
239*2238dcc3SJonas Devlieghere                    "format": "hex",
240*2238dcc3SJonas Devlieghere                    "set": 0,
241*2238dcc3SJonas Devlieghere                    "gcc": 15,
242*2238dcc3SJonas Devlieghere                    "dwarf": 15,
243*2238dcc3SJonas Devlieghere                },
244*2238dcc3SJonas Devlieghere                {
245*2238dcc3SJonas Devlieghere                    "name": "rip",
246*2238dcc3SJonas Devlieghere                    "bitsize": 64,
247*2238dcc3SJonas Devlieghere                    "offset": 128,
248*2238dcc3SJonas Devlieghere                    "encoding": "uint",
249*2238dcc3SJonas Devlieghere                    "format": "hex",
250*2238dcc3SJonas Devlieghere                    "set": 0,
251*2238dcc3SJonas Devlieghere                    "gcc": 16,
252*2238dcc3SJonas Devlieghere                    "dwarf": 16,
253*2238dcc3SJonas Devlieghere                    "generic": "pc",
254*2238dcc3SJonas Devlieghere                    "alt-name": "pc",
255*2238dcc3SJonas Devlieghere                },
256*2238dcc3SJonas Devlieghere                {
257*2238dcc3SJonas Devlieghere                    "name": "rflags",
258*2238dcc3SJonas Devlieghere                    "bitsize": 64,
259*2238dcc3SJonas Devlieghere                    "offset": 136,
260*2238dcc3SJonas Devlieghere                    "encoding": "uint",
261*2238dcc3SJonas Devlieghere                    "format": "hex",
262*2238dcc3SJonas Devlieghere                    "set": 0,
263*2238dcc3SJonas Devlieghere                    "generic": "flags",
264*2238dcc3SJonas Devlieghere                    "alt-name": "flags",
265*2238dcc3SJonas Devlieghere                },
266*2238dcc3SJonas Devlieghere                {
267*2238dcc3SJonas Devlieghere                    "name": "cs",
268*2238dcc3SJonas Devlieghere                    "bitsize": 64,
269*2238dcc3SJonas Devlieghere                    "offset": 144,
270*2238dcc3SJonas Devlieghere                    "encoding": "uint",
271*2238dcc3SJonas Devlieghere                    "format": "hex",
272*2238dcc3SJonas Devlieghere                    "set": 0,
273*2238dcc3SJonas Devlieghere                },
274*2238dcc3SJonas Devlieghere                {
275*2238dcc3SJonas Devlieghere                    "name": "fs",
276*2238dcc3SJonas Devlieghere                    "bitsize": 64,
277*2238dcc3SJonas Devlieghere                    "offset": 152,
278*2238dcc3SJonas Devlieghere                    "encoding": "uint",
279*2238dcc3SJonas Devlieghere                    "format": "hex",
280*2238dcc3SJonas Devlieghere                    "set": 0,
281*2238dcc3SJonas Devlieghere                },
282*2238dcc3SJonas Devlieghere                {
283*2238dcc3SJonas Devlieghere                    "name": "gs",
284*2238dcc3SJonas Devlieghere                    "bitsize": 64,
285*2238dcc3SJonas Devlieghere                    "offset": 160,
286*2238dcc3SJonas Devlieghere                    "encoding": "uint",
287*2238dcc3SJonas Devlieghere                    "format": "hex",
288*2238dcc3SJonas Devlieghere                    "set": 0,
289*2238dcc3SJonas Devlieghere                },
29099451b44SJordan Rupprecht            ]
29199451b44SJordan Rupprecht        return self.registers
29299451b44SJordan Rupprecht
29399451b44SJordan Rupprecht    def get_register_data(self, tid):
29499451b44SJordan Rupprecht        return struct.pack(
295*2238dcc3SJonas Devlieghere            "21Q",
29699451b44SJordan Rupprecht            tid + 1,
29799451b44SJordan Rupprecht            tid + 2,
29899451b44SJordan Rupprecht            tid + 3,
29999451b44SJordan Rupprecht            tid + 4,
30099451b44SJordan Rupprecht            tid + 5,
30199451b44SJordan Rupprecht            tid + 6,
30299451b44SJordan Rupprecht            tid + 7,
30399451b44SJordan Rupprecht            tid + 8,
30499451b44SJordan Rupprecht            tid + 9,
30599451b44SJordan Rupprecht            tid + 10,
30699451b44SJordan Rupprecht            tid + 11,
30799451b44SJordan Rupprecht            tid + 12,
30899451b44SJordan Rupprecht            tid + 13,
30999451b44SJordan Rupprecht            tid + 14,
31099451b44SJordan Rupprecht            tid + 15,
31199451b44SJordan Rupprecht            tid + 16,
31299451b44SJordan Rupprecht            tid + 17,
31399451b44SJordan Rupprecht            tid + 18,
31499451b44SJordan Rupprecht            tid + 19,
31599451b44SJordan Rupprecht            tid + 20,
316*2238dcc3SJonas Devlieghere            tid + 21,
317*2238dcc3SJonas Devlieghere        )
318