Changeset 262d4d51


Ignore:
Timestamp:
Dec 5, 2022, 4:25:55 PM (2 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master
Children:
258aaab8
Parents:
d4c8b59
Message:

Updating gdb tools to latest invoke.h changes

File:
1 edited

Legend:

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

    rd4c8b59 r262d4d51  
    2323gdb.execute('handle SIGUSR1 nostop noprint pass')
    2424
    25 CfaTypes = collections.namedtuple('CfaTypes', 'cluster_ptr processor_ptr thread_ptr int_ptr thread_state yield_state')
     25CfaTypes = collections.namedtuple('CfaTypes', 'cluster_ptr processor_ptr thread_ptr int_ptr uintptr 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'),
    5758                thread_state = gdb.lookup_type('enum __Coroutine_State'),
    5859                yield_state = gdb.lookup_type('enum __Preemption_Reason'))
     
    8990        return argv
    9091
     92def 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
     104def 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
     112def 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
    91131class ClusterIter:
    92132        def __init__(self, root):
     
    139179        def check(self):
    140180                # 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):
    144182                        raise StopIteration
    145183
     
    168206                return self.curr
    169207
    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 
    178208def proc_list(cluster):
    179209        """
     
    183213        proclist = cluster['_X5procsS19__cluster_proc_list_1']
    184214
    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']
    187217        return ProcIter(active.cast(cfa_t.processor_ptr)), ProcIter(idle.cast(cfa_t.processor_ptr))
    188218
     
    261291
    262292                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)
    264295
    265296                if root == 0x0 or root.address == 0x0:
     
    282313                        threads.append(t)
    283314
    284                         curr = curr['node']['next']
     315                        curr = fix_dlink(single_field(curr['cltr_link'])['_X4nextPY13__tE_generic__1']).cast(cfa_t.thread_ptr)
    285316                        if curr == root or curr == 0x0:
    286317                                break
     
    409440
    410441        def print_formatted(self, marked, tid, name, state, address):
     442                # print(marked, tid, name, state, address)
    411443                print('{:>1}  {:>4}  {:>20}  {:>10}  {:>20}'.format('*' if marked else ' ', tid, name, state, address))
    412444
    413445        def print_thread(self, thread, tid, marked):
     446                # print("print", thread, tid, marked)
    414447                cfa_t = get_cfa_types()
    415448                ys = str(thread['preempted'].cast(cfa_t.yield_state))
     
    439472
    440473                self.print_formatted(False, '', 'Name', 'State', 'Address')
    441 
    442474                for t in threads:
    443475                        if not t.is_system() or print_system:
Note: See TracChangeset for help on using the changeset viewer.