Changes in tools/gdb/utils-gdb.py [262d4d51:2e94d94f]
- File:
-
- 1 edited
-
tools/gdb/utils-gdb.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tools/gdb/utils-gdb.py
r262d4d51 r2e94d94f 23 23 gdb.execute('handle SIGUSR1 nostop noprint pass') 24 24 25 CfaTypes = collections.namedtuple('CfaTypes', 'cluster_ptr processor_ptr thread_ptr int_ptr uintptrthread_state yield_state')25 CfaTypes = collections.namedtuple('CfaTypes', 'cluster_ptr processor_ptr thread_ptr int_ptr 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'),58 57 thread_state = gdb.lookup_type('enum __Coroutine_State'), 59 58 yield_state = gdb.lookup_type('enum __Preemption_Reason')) … … 90 89 return argv 91 90 92 def single_field(obj):93 """94 If the struct only has one field return it, otherwise error95 """96 97 _type = obj.type98 if len(_type.fields()) != 1:99 return None100 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 None109 110 return dlist[fs[0]]111 112 def fix_dlink(ptr):113 """114 Remove the higher order bit from the pointer115 """116 ptype = ptr.type117 size = ptype.sizeof118 if size == 8:119 bit = 1 << ((size*8)-1)120 mask = bit - 1121 elif size == 4:122 bit = 0123 mask = 1124 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 131 91 class ClusterIter: 132 92 def __init__(self, root): … … 179 139 def check(self): 180 140 # check if this is the last value 181 if not fix_dlink(self.curr): 141 addr = int(self.curr) 142 mask = 1 << ((8 * int(gdb.parse_and_eval('sizeof(void*)'))) - 1) 143 if 0 != (mask & addr): 182 144 raise StopIteration 183 145 … … 206 168 return self.curr 207 169 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 None 175 176 return dlist[fs[0]] 177 208 178 def proc_list(cluster): 209 179 """ … … 213 183 proclist = cluster['_X5procsS19__cluster_proc_list_1'] 214 184 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']185 idle = start_from_dlist(proclist['_X5idlesS5dlist_S9processorS5dlink_S9processor___1']) 186 active = start_from_dlist(proclist['_X7activesS5dlist_S9processorS5dlink_S9processor___1']) 217 187 return ProcIter(active.cast(cfa_t.processor_ptr)), ProcIter(idle.cast(cfa_t.processor_ptr)) 218 188 … … 291 261 292 262 cfa_t = get_cfa_types() 293 head = single_field(cluster['_X7threadsS5dlist_S7thread$S18__thread_user_link__1']) 294 root = head['_X4nextPY13__tE_generic__1'].cast(cfa_t.thread_ptr) 263 root = cluster['_X7threadsS8__dllist_S7thread$__1']['_X4headPY15__TYPE_generic__1'].cast(cfa_t.thread_ptr) 295 264 296 265 if root == 0x0 or root.address == 0x0: … … 313 282 threads.append(t) 314 283 315 curr = fix_dlink(single_field(curr['cltr_link'])['_X4nextPY13__tE_generic__1']).cast(cfa_t.thread_ptr)284 curr = curr['node']['next'] 316 285 if curr == root or curr == 0x0: 317 286 break … … 440 409 441 410 def print_formatted(self, marked, tid, name, state, address): 442 # print(marked, tid, name, state, address)443 411 print('{:>1} {:>4} {:>20} {:>10} {:>20}'.format('*' if marked else ' ', tid, name, state, address)) 444 412 445 413 def print_thread(self, thread, tid, marked): 446 # print("print", thread, tid, marked)447 414 cfa_t = get_cfa_types() 448 415 ys = str(thread['preempted'].cast(cfa_t.yield_state)) … … 472 439 473 440 self.print_formatted(False, '', 'Name', 'State', 'Address') 441 474 442 for t in threads: 475 443 if not t.is_system() or print_system:
Note:
See TracChangeset
for help on using the changeset viewer.