Changeset 262d4d51
- Timestamp:
- Dec 5, 2022, 4:25:55 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 258aaab8
- Parents:
- d4c8b59
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/gdb/utils-gdb.py
rd4c8b59 r262d4d51 23 23 gdb.execute('handle SIGUSR1 nostop noprint pass') 24 24 25 CfaTypes = collections.namedtuple('CfaTypes', 'cluster_ptr processor_ptr thread_ptr int_ptr thread_state yield_state')25 CfaTypes = collections.namedtuple('CfaTypes', 'cluster_ptr processor_ptr thread_ptr int_ptr uintptr thread_state yield_state') 26 26 27 27 class ThreadInfo: … … 55 55 thread_ptr = gdb.lookup_type('struct thread$').pointer(), 56 56 int_ptr = gdb.lookup_type('int').pointer(), 57 uintptr = gdb.lookup_type('uintptr_t'), 57 58 thread_state = gdb.lookup_type('enum __Coroutine_State'), 58 59 yield_state = gdb.lookup_type('enum __Preemption_Reason')) … … 89 90 return argv 90 91 92 def single_field(obj): 93 """ 94 If the struct only has one field return it, otherwise error 95 """ 96 97 _type = obj.type 98 if len(_type.fields()) != 1: 99 return None 100 101 return obj[_type.fields()[0].name] 102 103 104 def start_from_dlist(dlist): 105 fs = dlist.type.fields() 106 if len(fs) != 1: 107 print("Error, can't understand dlist type for", dlist, dlist.name, dlist.type) 108 return None 109 110 return dlist[fs[0]] 111 112 def fix_dlink(ptr): 113 """ 114 Remove the higher order bit from the pointer 115 """ 116 ptype = ptr.type 117 size = ptype.sizeof 118 if size == 8: 119 bit = 1 << ((size*8)-1) 120 mask = bit - 1 121 elif size == 4: 122 bit = 0 123 mask = 1 124 else: 125 print("Unexpected pointer size while fixing dlink", size) 126 127 cfa_t = get_cfa_types() 128 uptr = ptr.cast(cfa_t.uintptr) 129 return ptr if 0 == uptr & mask else gdb.Value(b'\x00'*size, ptype) 130 91 131 class ClusterIter: 92 132 def __init__(self, root): … … 139 179 def check(self): 140 180 # check if this is the last value 141 addr = int(self.curr) 142 mask = 1 << ((8 * int(gdb.parse_and_eval('sizeof(void*)'))) - 1) 143 if 0 != (mask & addr): 181 if not fix_dlink(self.curr): 144 182 raise StopIteration 145 183 … … 168 206 return self.curr 169 207 170 def start_from_dlist(dlist):171 fs = dlist.type.fields()172 if len(fs) != 1:173 print("Error, can't understand dlist type for", dlist, dlist.name, dlist.type)174 return None175 176 return dlist[fs[0]]177 178 208 def proc_list(cluster): 179 209 """ … … 183 213 proclist = cluster['_X5procsS19__cluster_proc_list_1'] 184 214 185 idle = start_from_dlist(proclist['_X5idlesS5dlist_S9processorS5dlink_S9processor___1']) 186 active = start_from_dlist(proclist['_X7activesS5dlist_S9processorS5dlink_S9processor___1']) 215 idle = start_from_dlist(proclist['_X5idlesS5dlist_S9processorS5dlink_S9processor___1'])['_X4nextPY13__tE_generic__1'] 216 active = start_from_dlist(proclist['_X7activesS5dlist_S9processorS5dlink_S9processor___1'])['_X4nextPY13__tE_generic__1'] 187 217 return ProcIter(active.cast(cfa_t.processor_ptr)), ProcIter(idle.cast(cfa_t.processor_ptr)) 188 218 … … 261 291 262 292 cfa_t = get_cfa_types() 263 root = cluster['_X7threadsS8__dllist_S7thread$__1']['_X4headPY15__TYPE_generic__1'].cast(cfa_t.thread_ptr) 293 head = single_field(cluster['_X7threadsS5dlist_S7thread$S18__thread_user_link__1']) 294 root = head['_X4nextPY13__tE_generic__1'].cast(cfa_t.thread_ptr) 264 295 265 296 if root == 0x0 or root.address == 0x0: … … 282 313 threads.append(t) 283 314 284 curr = curr['node']['next']315 curr = fix_dlink(single_field(curr['cltr_link'])['_X4nextPY13__tE_generic__1']).cast(cfa_t.thread_ptr) 285 316 if curr == root or curr == 0x0: 286 317 break … … 409 440 410 441 def print_formatted(self, marked, tid, name, state, address): 442 # print(marked, tid, name, state, address) 411 443 print('{:>1} {:>4} {:>20} {:>10} {:>20}'.format('*' if marked else ' ', tid, name, state, address)) 412 444 413 445 def print_thread(self, thread, tid, marked): 446 # print("print", thread, tid, marked) 414 447 cfa_t = get_cfa_types() 415 448 ys = str(thread['preempted'].cast(cfa_t.yield_state)) … … 439 472 440 473 self.print_formatted(False, '', 'Name', 'State', 'Address') 441 442 474 for t in threads: 443 475 if not t.is_system() or print_system:
Note: See TracChangeset
for help on using the changeset viewer.