Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/gdb/utils-gdb.py

    r262d4d51 r2e94d94f  
    2323gdb.execute('handle SIGUSR1 nostop noprint pass')
    2424
    25 CfaTypes = collections.namedtuple('CfaTypes', 'cluster_ptr processor_ptr thread_ptr int_ptr uintptr thread_state yield_state')
     25CfaTypes = collections.namedtuple('CfaTypes', 'cluster_ptr processor_ptr thread_ptr int_ptr thread_state yield_state')
    2626
    2727class ThreadInfo:
     
    5555                thread_ptr = gdb.lookup_type('struct thread$').pointer(),
    5656                int_ptr = gdb.lookup_type('int').pointer(),
    57                 uintptr = gdb.lookup_type('uintptr_t'),
    5857                thread_state = gdb.lookup_type('enum __Coroutine_State'),
    5958                yield_state = gdb.lookup_type('enum __Preemption_Reason'))
     
    9089        return argv
    9190
    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 
    13191class ClusterIter:
    13292        def __init__(self, root):
     
    179139        def check(self):
    180140                # 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):
    182144                        raise StopIteration
    183145
     
    206168                return self.curr
    207169
     170def 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
    208178def proc_list(cluster):
    209179        """
     
    213183        proclist = cluster['_X5procsS19__cluster_proc_list_1']
    214184
    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'])
    217187        return ProcIter(active.cast(cfa_t.processor_ptr)), ProcIter(idle.cast(cfa_t.processor_ptr))
    218188
     
    291261
    292262                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)
    295264
    296265                if root == 0x0 or root.address == 0x0:
     
    313282                        threads.append(t)
    314283
    315                         curr = fix_dlink(single_field(curr['cltr_link'])['_X4nextPY13__tE_generic__1']).cast(cfa_t.thread_ptr)
     284                        curr = curr['node']['next']
    316285                        if curr == root or curr == 0x0:
    317286                                break
     
    440409
    441410        def print_formatted(self, marked, tid, name, state, address):
    442                 # print(marked, tid, name, state, address)
    443411                print('{:>1}  {:>4}  {:>20}  {:>10}  {:>20}'.format('*' if marked else ' ', tid, name, state, address))
    444412
    445413        def print_thread(self, thread, tid, marked):
    446                 # print("print", thread, tid, marked)
    447414                cfa_t = get_cfa_types()
    448415                ys = str(thread['preempted'].cast(cfa_t.yield_state))
     
    472439
    473440                self.print_formatted(False, '', 'Name', 'State', 'Address')
     441
    474442                for t in threads:
    475443                        if not t.is_system() or print_system:
Note: See TracChangeset for help on using the changeset viewer.