Changeset 9dad5b3 for tools


Ignore:
Timestamp:
Jun 22, 2022, 8:06:19 PM (21 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
d28524a
Parents:
1158180
Message:

Fixed gdb printing of processors which was broken for a while now.

File:
1 edited

Legend:

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

    r1158180 r9dad5b3  
    8989        return argv
    9090
    91 def get_cluster_root():
    92         """
    93         Return: gdb.Value of globalClusters.root (is an address)
    94         """
     91class ClusterIter:
     92        def __init__(self, root):
     93                self.curr = None
     94                self.root = root
     95
     96        def __iter__(self):
     97                return self
     98
     99        def __next__(self):
     100                # Clusters form a cycle
     101                # If we haven't seen the root yet, then the root is the first
     102                if not self.curr:
     103                        self.curr = self.root
     104                        return self.curr
     105
     106                # if we already saw the root, then go forward
     107                self.curr = self.curr['_X4nodeS26__cluster____dbg_node_cltr_1']['_X4nextPS7cluster_1']
     108
     109                # if we reached the root again, then we are done
     110                if self.curr == self.root:
     111                        raise StopIteration
     112
     113                # otherwise return the next
     114                return self.curr
     115
     116def all_clusters():
     117        """
     118        Return: a list of all the clusters as an iterator.
     119        obtained from gdb.Value of globalClusters.root (is an address)
     120        """
     121        if not is_cforall():
     122                return []
     123
    95124        cluster_root = gdb.parse_and_eval('_X11mainClusterPS7cluster_1')
    96125        if cluster_root.address == 0x0:
    97126                print('No clusters, program terminated')
    98         return cluster_root
    99 
    100 def get_sched_lock():
    101         """
    102         Return: gdb.Value of __scheduler_lock
    103         """
    104         lock = gdb.parse_and_eval('_X16__scheduler_lockPS20__scheduler_RWLock_t_1')
    105         if lock.address == 0x0:
    106                 print('No scheduler lock, program terminated')
    107         return lock
    108 
    109 def all_clusters():
    110         if not is_cforall():
    111                 return None
    112 
    113         cluster_root = get_cluster_root()
    114         if cluster_root.address == 0x0:
    115                 return
    116 
    117         curr = cluster_root
    118         ret = [curr]
    119 
    120         while True:
    121                 curr = curr['_X4nodeS26__cluster____dbg_node_cltr_1']['_X4nextPS7cluster_1']
    122                 if curr == cluster_root:
    123                         break
    124 
    125                 ret.append(curr)
    126 
    127         return ret
     127                return []
     128
     129        return ClusterIter(cluster_root)
     130
     131class ProcIter:
     132        def __init__(self, root):
     133                self.curr = None
     134                self.root = root
     135
     136        def __iter__(self):
     137                return self
     138
     139        def check(self):
     140                # 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):
     144                        raise StopIteration
     145
     146        def __next__(self):
     147                cfa_t = get_cfa_types()
     148
     149                # Processors form a cycle
     150                # If we haven't seen the root yet, then the root is the first
     151                if not self.curr:
     152                        my_next = self.root
     153                        self.curr = my_next.cast(cfa_t.processor_ptr)
     154
     155                        #check if this is an empty list
     156                        self.check()
     157
     158                        return self.curr
     159
     160                # if we already saw the root, then go forward
     161                my_next = self.curr['__anonymous_object2225']['_X4nextPY13__tE_generic__1']
     162                self.curr = my_next.cast(cfa_t.processor_ptr)
     163
     164                #check if we reached the end
     165                self.check()
     166
     167                # otherwise return the next
     168                return self.curr
     169
     170def proc_list(cluster):
     171        """
     172        Return: for a given processor, return the active and idle processors, as 2 iterators
     173        """
     174        cfa_t = get_cfa_types()
     175        proclist = cluster['_X5procsS19__cluster_proc_list_1']
     176        idle = proclist['_X5idlesS5dlist_S9processorS5dlink_S9processor___1']['__anonymous_object2167']['_X4nextPY13__tE_generic__1']
     177        active = proclist['_X7activesS5dlist_S9processorS5dlink_S9processor___1']['__anonymous_object2167']['_X4nextPY13__tE_generic__1']
     178        return ProcIter(active.cast(cfa_t.processor_ptr)), ProcIter(idle.cast(cfa_t.processor_ptr))
    128179
    129180def all_processors():
    130         if not is_cforall():
    131                 return None
    132 
    133         cfa_t = get_cfa_types()
    134 
    135         # get processors from registration to the RWlock
    136         lock = get_sched_lock()
    137 
    138         #get number of elements
    139         count = lock['_X5readyVj_1']
    140 
    141         #find all the procs
    142         raw_procs = [lock['_X4dataPS21__scheduler_lock_id_t_1'][i]['_X6handleVPS16__processor_id_t_1'] for i in range(count)]
    143 
    144         # pre cast full procs
    145         procs = [p.cast(cfa_t.processor_ptr) for p in raw_procs if p['_X9full_procb_1']]
    146 
    147         # sort procs by clusters
    148         return sorted(procs, key=lambda p: p['_X4cltrPS7cluster_1'])
     181        procs = []
     182        for c in all_clusters():
     183                active, idle = proc_list(c)
     184                for p in active:
     185                        procs.append(p)
     186
     187                for p in idle:
     188                        procs.append(p)
     189
     190        print(procs)
     191        return procs
    149192
    150193def tls_for_pthread(pthrd):
     
    160203
    161204def tls_for_proc(proc):
    162         return tls_for_pthread(proc['_X13kernel_threadm_1'])
     205        return proc['_X10local_dataPS16KernelThreadData_1']
    163206
    164207def thread_for_pthread(pthrd):
     
    180223def lookup_cluster(name = None):
    181224        """
    182         Look up a cluster given its ID
     225        Look up one or more cluster given a name
    183226        @name: str
    184227        Return: gdb.Value
     
    187230                return None
    188231
    189         root = get_cluster_root()
    190         if root.address == 0x0:
     232        clusters = all_clusters()
     233        if not clusters:
    191234                return None
    192235
    193236        if not name:
    194                 return root
     237                return clusters.root
    195238
    196239        # lookup for the task associated with the id
    197         cluster = None
    198         curr = root
    199         while True:
    200                 if curr['_X4namePKc_1'].string() == name:
    201                         cluster = curr.address
    202                         break
    203                 curr = curr['_X4nodeS26__cluster____dbg_node_cltr_1']['_X4nextPS7cluster_1']
    204                 if curr == root or curr == 0x0:
    205                         break
    206 
    207         if not cluster:
     240        found = [c for c in clusters if c['_X4namePKc_1'].string() == name]
     241
     242        if not found:
    208243                print("Cannot find a cluster with the name: {}.".format(name))
    209244                return None
    210245
    211         return cluster
     246        return found
     247
    212248
    213249def lookup_threads_by_cluster(cluster):
     
    294330                super(Processors, self).__init__('info processors', gdb.COMMAND_USER)
    295331
    296         def print_processor(self, processor):
     332        def print_processor(self, processor, in_stats):
    297333                should_stop = processor['_X12do_terminateVb_1']
    298334                if not should_stop:
    299                         midle = processor['_X6$linksS7$dlinks_S9processor__1']['_X4nextS9$mgd_link_Y13__tE_generic___1']['_X4elemPY13__tE_generic__1'] != 0x0
    300                         end   = processor['_X6$linksS7$dlinks_S9processor__1']['_X4nextS9$mgd_link_Y13__tE_generic___1']['_X10terminatorPv_1'] != 0x0
    301 
    302                         status = 'Idle' if midle or end else 'Active'
     335                        status = in_stats
    303336                else:
    304337                        stop_count  = processor['_X10terminatedS9semaphore_1']['_X5counti_1']
     
    336369                        return
    337370
    338                 procs = all_processors()
    339 
    340371                print('{:>20}  {:>11}  {:<7}  {}'.format('Processor', '', 'Pending', 'Object'))
    341372                print('{:>20}  {:>11}  {:<7}  {}'.format('Name', 'Status', 'Yield', 'Address'))
    342                 cl = None
    343                 for p in procs:
    344                         # if this is a different cluster print it
    345                         if cl != p['_X4cltrPS7cluster_1']:
    346                                 if cl:
    347                                         print()
    348                                 cl = p['_X4cltrPS7cluster_1']
    349                                 print('Cluster {}'.format(cl['_X4namePKc_1'].string()))
    350 
     373                for c in clusters:
     374                        print('Cluster {}'.format(c['_X4namePKc_1'].string()))
     375
     376                        active, idle = proc_list(c)
    351377                        # print the processor information
    352                         self.print_processor(p)
     378                        for p in active:
     379                                self.print_processor(p, 'Active')
     380
     381                        for p in idle:
     382                                self.print_processor(p, 'Idle')
     383
     384                        print()
    353385
    354386                print()
     
    433465                        cluster = lookup_cluster(arg)
    434466                        if not cluster:
    435                                 print("Could not find cluster '{}'".format(arg))
     467                                print("No matching cluster")
    436468                                return
    437469
Note: See TracChangeset for help on using the changeset viewer.