Greg Clayton | 88b980b | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import lldb |
Greg Clayton | b8f126a | 2012-08-24 05:45:15 +0000 | [diff] [blame] | 4 | import struct |
Greg Clayton | 88b980b | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 5 | |
Greg Clayton | 2e7f313 | 2012-10-18 22:40:37 +0000 | [diff] [blame] | 6 | class OperatingSystemPlugIn(object): |
Greg Clayton | 88b980b | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 7 | """Class that provides data for an instance of a LLDB 'OperatingSystemPython' plug-in class""" |
| 8 | |
| 9 | def __init__(self, process): |
Greg Clayton | a69d235 | 2012-09-12 00:47:53 +0000 | [diff] [blame] | 10 | '''Initialization needs a valid.SBProcess object. |
| 11 | |
| 12 | This plug-in will get created after a live process is valid and has stopped for the |
| 13 | first time.''' |
Greg Clayton | a63665a | 2012-08-24 02:01:39 +0000 | [diff] [blame] | 14 | self.process = None |
| 15 | self.registers = None |
| 16 | self.threads = None |
Greg Clayton | 88b980b | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 17 | if type(process) is lldb.SBProcess and process.IsValid(): |
| 18 | self.process = process |
Enrico Granata | 7ccb19a | 2012-08-24 01:53:47 +0000 | [diff] [blame] | 19 | self.threads = None # Will be an dictionary containing info for each thread |
Greg Clayton | 88b980b | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 20 | |
Greg Clayton | a69d235 | 2012-09-12 00:47:53 +0000 | [diff] [blame] | 21 | def get_target(self): |
| 22 | # NOTE: Don't use "lldb.target" when trying to get your target as the "lldb.target" |
| 23 | # tracks the current target in the LLDB command interpreter which isn't the |
| 24 | # correct thing to use for this plug-in. |
| 25 | return self.process.target |
Greg Clayton | 52ebc0a | 2013-01-18 23:41:08 +0000 | [diff] [blame] | 26 | |
| 27 | def create_thread(self, tid, context): |
| 28 | if tid == 0x444444444: |
Greg Clayton | 36da2aa | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 29 | thread_info = { 'tid' : tid, 'name' : 'four' , 'queue' : 'queue4', 'state' : 'stopped', 'stop_reason' : 'none' } |
Greg Clayton | 52ebc0a | 2013-01-18 23:41:08 +0000 | [diff] [blame] | 30 | self.threads.append(thread_info) |
| 31 | return thread_info |
| 32 | return None |
Greg Clayton | a69d235 | 2012-09-12 00:47:53 +0000 | [diff] [blame] | 33 | |
Greg Clayton | 88b980b | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 34 | def get_thread_info(self): |
| 35 | if not self.threads: |
Greg Clayton | a69d235 | 2012-09-12 00:47:53 +0000 | [diff] [blame] | 36 | # The sample dictionary below shows the values that can be returned for a thread |
| 37 | # tid => thread ID (mandatory) |
| 38 | # name => thread name (optional key/value pair) |
| 39 | # queue => thread dispatch queue name (optional key/value pair) |
| 40 | # state => thred state (mandatory, set to 'stopped' for now) |
| 41 | # stop_reason => thread stop reason. (mandatory, usually set to 'none') |
| 42 | # Possible values include: |
| 43 | # 'breakpoint' if the thread is stopped at a breakpoint |
| 44 | # 'none' thread is just stopped because the process is stopped |
| 45 | # 'trace' the thread just single stepped |
| 46 | # The usual value for this while threads are in memory is 'none' |
Greg Clayton | 75a4fe6 | 2013-01-09 02:05:38 +0000 | [diff] [blame] | 47 | # register_data_addr => the address of the register data in memory (optional key/value pair) |
| 48 | # Specifying this key/value pair for a thread will avoid a call to get_register_data() |
| 49 | # and can be used when your registers are in a thread context structure that is contiguous |
| 50 | # in memory. Don't specify this if your register layout in memory doesn't match the layout |
| 51 | # described by the dictionary returned from a call to the get_register_info() method. |
Greg Clayton | 88b980b | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 52 | self.threads = [ |
| 53 | { 'tid' : 0x111111111, 'name' : 'one' , 'queue' : 'queue1', 'state' : 'stopped', 'stop_reason' : 'breakpoint'}, |
| 54 | { 'tid' : 0x222222222, 'name' : 'two' , 'queue' : 'queue2', 'state' : 'stopped', 'stop_reason' : 'none' }, |
Greg Clayton | 91a9f21 | 2012-10-25 17:56:31 +0000 | [diff] [blame] | 55 | { 'tid' : 0x333333333, 'name' : 'three', 'queue' : 'queue3', 'state' : 'stopped', 'stop_reason' : 'trace' , 'register_data_addr' : 0x100000000 } |
Greg Clayton | 88b980b | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 56 | ] |
| 57 | return self.threads |
| 58 | |
| 59 | def get_register_info(self): |
Greg Clayton | a63665a | 2012-08-24 02:01:39 +0000 | [diff] [blame] | 60 | if self.registers == None: |
| 61 | self.registers = dict() |
Greg Clayton | 88b980b | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 62 | triple = self.process.target.triple |
| 63 | if triple: |
| 64 | arch = triple.split('-')[0] |
| 65 | if arch == 'x86_64': |
Greg Clayton | a63665a | 2012-08-24 02:01:39 +0000 | [diff] [blame] | 66 | self.registers['sets'] = ['GPR', 'FPU', 'EXC'] |
| 67 | self.registers['registers'] = [ |
Greg Clayton | 88b980b | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 68 | { 'name':'rax' , 'bitsize' : 64, 'offset' : 0, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 0, 'dwarf' : 0}, |
| 69 | { 'name':'rbx' , 'bitsize' : 64, 'offset' : 8, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 3, 'dwarf' : 3}, |
| 70 | { 'name':'rcx' , 'bitsize' : 64, 'offset' : 16, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 2, 'dwarf' : 2, 'generic':'arg4', 'alt-name':'arg4', }, |
| 71 | { 'name':'rdx' , 'bitsize' : 64, 'offset' : 24, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 1, 'dwarf' : 1, 'generic':'arg3', 'alt-name':'arg3', }, |
| 72 | { 'name':'rdi' , 'bitsize' : 64, 'offset' : 32, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 5, 'dwarf' : 5, 'generic':'arg1', 'alt-name':'arg1', }, |
| 73 | { 'name':'rsi' , 'bitsize' : 64, 'offset' : 40, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 4, 'dwarf' : 4, 'generic':'arg2', 'alt-name':'arg2', }, |
| 74 | { 'name':'rbp' , 'bitsize' : 64, 'offset' : 48, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 6, 'dwarf' : 6, 'generic':'fp' , 'alt-name':'fp', }, |
| 75 | { 'name':'rsp' , 'bitsize' : 64, 'offset' : 56, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 7, 'dwarf' : 7, 'generic':'sp' , 'alt-name':'sp', }, |
| 76 | { 'name':'r8' , 'bitsize' : 64, 'offset' : 64, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 8, 'dwarf' : 8, 'generic':'arg5', 'alt-name':'arg5', }, |
| 77 | { 'name':'r9' , 'bitsize' : 64, 'offset' : 72, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 9, 'dwarf' : 9, 'generic':'arg6', 'alt-name':'arg6', }, |
| 78 | { 'name':'r10' , 'bitsize' : 64, 'offset' : 80, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 10, 'dwarf' : 10}, |
| 79 | { 'name':'r11' , 'bitsize' : 64, 'offset' : 88, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 11, 'dwarf' : 11}, |
| 80 | { 'name':'r12' , 'bitsize' : 64, 'offset' : 96, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 12, 'dwarf' : 12}, |
| 81 | { 'name':'r13' , 'bitsize' : 64, 'offset' : 104, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 13, 'dwarf' : 13}, |
| 82 | { 'name':'r14' , 'bitsize' : 64, 'offset' : 112, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 14, 'dwarf' : 14}, |
| 83 | { 'name':'r15' , 'bitsize' : 64, 'offset' : 120, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 15, 'dwarf' : 15}, |
| 84 | { 'name':'rip' , 'bitsize' : 64, 'offset' : 128, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 16, 'dwarf' : 16, 'generic':'pc', 'alt-name':'pc' }, |
| 85 | { 'name':'rflags' , 'bitsize' : 64, 'offset' : 136, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'generic':'flags', 'alt-name':'flags' }, |
| 86 | { 'name':'cs' , 'bitsize' : 64, 'offset' : 144, 'encoding':'uint' , 'format':'hex' , 'set': 0 }, |
| 87 | { 'name':'fs' , 'bitsize' : 64, 'offset' : 152, 'encoding':'uint' , 'format':'hex' , 'set': 0 }, |
| 88 | { 'name':'gs' , 'bitsize' : 64, 'offset' : 160, 'encoding':'uint' , 'format':'hex' , 'set': 0 }, |
| 89 | ] |
Greg Clayton | a63665a | 2012-08-24 02:01:39 +0000 | [diff] [blame] | 90 | return self.registers |
Greg Clayton | 88b980b | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 91 | |
| 92 | def get_register_data(self, tid): |
| 93 | if tid == 0x111111111: |
Greg Clayton | b8f126a | 2012-08-24 05:45:15 +0000 | [diff] [blame] | 94 | return struct.pack('21Q',1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21); |
Greg Clayton | 88b980b | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 95 | elif tid == 0x222222222: |
Greg Clayton | b8f126a | 2012-08-24 05:45:15 +0000 | [diff] [blame] | 96 | return struct.pack('21Q',11,12,13,14,15,16,17,18,19,110,111,112,113,114,115,116,117,118,119,120,121); |
Greg Clayton | 88b980b | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 97 | elif tid == 0x333333333: |
Greg Clayton | b8f126a | 2012-08-24 05:45:15 +0000 | [diff] [blame] | 98 | return struct.pack('21Q',21,22,23,24,25,26,27,28,29,210,211,212,213,214,215,216,217,218,219,220,221); |
Greg Clayton | 52ebc0a | 2013-01-18 23:41:08 +0000 | [diff] [blame] | 99 | elif tid == 0x444444444: |
| 100 | return struct.pack('21Q',31,32,33,34,35,36,37,38,39,310,311,312,313,314,315,316,317,318,319,320,321); |
| 101 | else: |
| 102 | return struct.pack('21Q',41,42,43,44,45,46,47,48,49,410,411,412,413,414,415,416,417,418,419,420,421); |
| 103 | return None |
Greg Clayton | 88b980b | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 104 | |