brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.3 KiB · de9900c Raw
312 lines · python
1import lldb2import struct3 4from lldb.plugins.operating_system import OperatingSystem5 6 7class OperatingSystemPlugIn(OperatingSystem):8    """Class that provides data for an instance of a LLDB 'OperatingSystemPython' plug-in class"""9 10    def __init__(self, process):11        super().__init__(process)12 13    def create_thread(self, tid, context):14        if tid == 0x444444444:15            thread_info = {16                "tid": tid,17                "name": "four",18                "queue": "queue4",19                "state": "stopped",20                "stop_reason": "none",21            }22            self.threads.append(thread_info)23            return thread_info24        return None25 26    def get_thread_info(self):27        if self.process.state != lldb.eStateStopped:28            print("Error: get_thread_info called with state not stopped")29            return []30 31        if not self.threads:32            self.threads = [33                {34                    "tid": 0x111111111,35                    "name": "one",36                    "queue": "queue1",37                    "state": "stopped",38                    "stop_reason": "breakpoint",39                },40                {41                    "tid": 0x222222222,42                    "name": "two",43                    "queue": "queue2",44                    "state": "stopped",45                    "stop_reason": "none",46                },47                {48                    "tid": 0x333333333,49                    "name": "three",50                    "queue": "queue3",51                    "state": "stopped",52                    "stop_reason": "trace",53                },54            ]55        return self.threads56 57    def get_register_info(self):58        if self.registers is None:59            self.registers = dict()60            self.registers["sets"] = ["GPR"]61            self.registers["registers"] = [62                {63                    "name": "rax",64                    "bitsize": 64,65                    "offset": 0,66                    "encoding": "uint",67                    "format": "hex",68                    "set": 0,69                    "gcc": 0,70                    "dwarf": 0,71                },72                {73                    "name": "rbx",74                    "bitsize": 64,75                    "offset": 8,76                    "encoding": "uint",77                    "format": "hex",78                    "set": 0,79                    "gcc": 3,80                    "dwarf": 3,81                },82                {83                    "name": "rcx",84                    "bitsize": 64,85                    "offset": 16,86                    "encoding": "uint",87                    "format": "hex",88                    "set": 0,89                    "gcc": 2,90                    "dwarf": 2,91                    "generic": "arg4",92                    "alt-name": "arg4",93                },94                {95                    "name": "rdx",96                    "bitsize": 64,97                    "offset": 24,98                    "encoding": "uint",99                    "format": "hex",100                    "set": 0,101                    "gcc": 1,102                    "dwarf": 1,103                    "generic": "arg3",104                    "alt-name": "arg3",105                },106                {107                    "name": "rdi",108                    "bitsize": 64,109                    "offset": 32,110                    "encoding": "uint",111                    "format": "hex",112                    "set": 0,113                    "gcc": 5,114                    "dwarf": 5,115                    "generic": "arg1",116                    "alt-name": "arg1",117                },118                {119                    "name": "rsi",120                    "bitsize": 64,121                    "offset": 40,122                    "encoding": "uint",123                    "format": "hex",124                    "set": 0,125                    "gcc": 4,126                    "dwarf": 4,127                    "generic": "arg2",128                    "alt-name": "arg2",129                },130                {131                    "name": "rbp",132                    "bitsize": 64,133                    "offset": 48,134                    "encoding": "uint",135                    "format": "hex",136                    "set": 0,137                    "gcc": 6,138                    "dwarf": 6,139                    "generic": "fp",140                    "alt-name": "fp",141                },142                {143                    "name": "rsp",144                    "bitsize": 64,145                    "offset": 56,146                    "encoding": "uint",147                    "format": "hex",148                    "set": 0,149                    "gcc": 7,150                    "dwarf": 7,151                    "generic": "sp",152                    "alt-name": "sp",153                },154                {155                    "name": "r8",156                    "bitsize": 64,157                    "offset": 64,158                    "encoding": "uint",159                    "format": "hex",160                    "set": 0,161                    "gcc": 8,162                    "dwarf": 8,163                    "generic": "arg5",164                    "alt-name": "arg5",165                },166                {167                    "name": "r9",168                    "bitsize": 64,169                    "offset": 72,170                    "encoding": "uint",171                    "format": "hex",172                    "set": 0,173                    "gcc": 9,174                    "dwarf": 9,175                    "generic": "arg6",176                    "alt-name": "arg6",177                },178                {179                    "name": "r10",180                    "bitsize": 64,181                    "offset": 80,182                    "encoding": "uint",183                    "format": "hex",184                    "set": 0,185                    "gcc": 10,186                    "dwarf": 10,187                },188                {189                    "name": "r11",190                    "bitsize": 64,191                    "offset": 88,192                    "encoding": "uint",193                    "format": "hex",194                    "set": 0,195                    "gcc": 11,196                    "dwarf": 11,197                },198                {199                    "name": "r12",200                    "bitsize": 64,201                    "offset": 96,202                    "encoding": "uint",203                    "format": "hex",204                    "set": 0,205                    "gcc": 12,206                    "dwarf": 12,207                },208                {209                    "name": "r13",210                    "bitsize": 64,211                    "offset": 104,212                    "encoding": "uint",213                    "format": "hex",214                    "set": 0,215                    "gcc": 13,216                    "dwarf": 13,217                },218                {219                    "name": "r14",220                    "bitsize": 64,221                    "offset": 112,222                    "encoding": "uint",223                    "format": "hex",224                    "set": 0,225                    "gcc": 14,226                    "dwarf": 14,227                },228                {229                    "name": "r15",230                    "bitsize": 64,231                    "offset": 120,232                    "encoding": "uint",233                    "format": "hex",234                    "set": 0,235                    "gcc": 15,236                    "dwarf": 15,237                },238                {239                    "name": "rip",240                    "bitsize": 64,241                    "offset": 128,242                    "encoding": "uint",243                    "format": "hex",244                    "set": 0,245                    "gcc": 16,246                    "dwarf": 16,247                    "generic": "pc",248                    "alt-name": "pc",249                },250                {251                    "name": "rflags",252                    "bitsize": 64,253                    "offset": 136,254                    "encoding": "uint",255                    "format": "hex",256                    "set": 0,257                    "generic": "flags",258                    "alt-name": "flags",259                },260                {261                    "name": "cs",262                    "bitsize": 64,263                    "offset": 144,264                    "encoding": "uint",265                    "format": "hex",266                    "set": 0,267                },268                {269                    "name": "fs",270                    "bitsize": 64,271                    "offset": 152,272                    "encoding": "uint",273                    "format": "hex",274                    "set": 0,275                },276                {277                    "name": "gs",278                    "bitsize": 64,279                    "offset": 160,280                    "encoding": "uint",281                    "format": "hex",282                    "set": 0,283                },284            ]285        return self.registers286 287    def get_register_data(self, tid):288        return struct.pack(289            "21Q",290            tid + 1,291            tid + 2,292            tid + 3,293            tid + 4,294            tid + 5,295            tid + 6,296            tid + 7,297            tid + 8,298            tid + 9,299            tid + 10,300            tid + 11,301            tid + 12,302            tid + 13,303            tid + 14,304            tid + 15,305            tid + 16,306            tid + 17,307            tid + 18,308            tid + 19,309            tid + 20,310            tid + 21,311        )312