Changeset d8b17e2
- Timestamp:
- Sep 24, 2020, 4:31:09 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- bb662027
- Parents:
- 58d64a4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/gdb/utils-gdb.py
r58d64a4 rd8b17e2 44 44 STACK = [] 45 45 46 # A global variable to keep all system task name47 SysTask_Name = ["uLocalDebuggerReader", "uLocalDebugger", "uProcessorTask", "uBootTask", "uSystemTask",48 "uProcessorTask", "uPthread", "uProfiler"]49 50 46 not_supported_error_msg = "Not a supported command for this language" 51 47 … … 101 97 return cluster_root 102 98 99 def get_sched_lock(): 100 """ 101 Return: gdb.Value of __scheduler_lock 102 """ 103 lock = gdb.parse_and_eval('_X16__scheduler_lockPS20__scheduler_RWLock_t_1') 104 if lock.address == 0x0: 105 print('No scheduler lock, program terminated') 106 return lock 107 108 def all_clusters(): 109 if not is_cforall(): 110 return None 111 112 cluster_root = get_cluster_root() 113 if cluster_root.address == 0x0: 114 return 115 116 curr = cluster_root 117 ret = [curr] 118 119 while True: 120 curr = curr['_X4nodeS26__cluster____dbg_node_cltr_1']['_X4nextPS7cluster_1'] 121 if curr == cluster_root: 122 break 123 124 ret.append(curr) 125 126 return ret 127 128 def all_processors(): 129 if not is_cforall(): 130 return None 131 132 cfa_t = get_cfa_types() 133 134 # get processors from registration to the RWlock 135 lock = get_sched_lock() 136 137 #get number of elements 138 count = lock['_X5readyVj_1'] 139 140 #find all the procs 141 raw_procs = [lock['_X4dataPS21__scheduler_lock_id_t_1'][i]['_X6handleVPS16__processor_id_t_1'] for i in range(count)] 142 143 # pre cast full procs 144 procs = [p.cast(cfa_t.processor_ptr) for p in raw_procs if p['_X9full_procb_1']] 145 146 # sort procs by clusters 147 return sorted(procs, key=lambda p: p['_X4cltrPS7cluster_1']) 148 149 def tls_for_pthread(pthrd): 150 prev = gdb.selected_thread() 151 inf = gdb.selected_inferior() 152 153 thrd = inf.thread_from_thread_handle( pthrd ) 154 thrd.switch() 155 tls = gdb.parse_and_eval('&_X9kernelTLSS16KernelThreadData_1') 156 157 prev.switch() 158 return tls 159 160 def tls_for_proc(proc): 161 return tls_for_pthread(proc['_X13kernel_threadm_1']) 162 163 def thread_for_pthread(pthrd): 164 return tls_for_pthread(pthrd)['_X11this_threadVPS7$thread_1'] 165 166 def thread_for_proc(proc): 167 return tls_for_proc(proc)['_X11this_threadVPS7$thread_1'] 168 169 170 103 171 def find_curr_thread(): 104 172 # btstr = gdb.execute('bt', to_string = True).splitlines() … … 108 176 # return btstr[0].split('this=',1)[1].split(',')[0].split(')')[0] 109 177 return None 110 111 def all_clusters():112 if not is_cforall():113 return None114 115 cluster_root = get_cluster_root()116 if cluster_root.address == 0x0:117 return118 119 curr = cluster_root120 ret = [curr]121 122 while True:123 curr = curr['_X4nodeS26__cluster____dbg_node_cltr_1']['_X4nextPS7cluster_1']124 if curr == cluster_root:125 break126 127 ret.append(curr)128 129 return ret130 131 178 132 179 def lookup_cluster(name = None): … … 239 286 """Cforall: Display currently known processors 240 287 Usage: 241 info processors : print out all the processors in the Main Cluster 242 info processors all : print out all processors in all clusters 288 info processors : print out all the processors 243 289 info processors <cluster_name> : print out all processors in a given cluster 244 290 """ … … 247 293 super(Processors, self).__init__('info processors', gdb.COMMAND_USER) 248 294 249 def print_processor(self, name, status, pending, address): 250 print('{:>20} {:>11} {:>13} {:>20}'.format(name, status, pending, address)) 251 252 def iterate_procs(self, root, active): 253 if root == 0x0: 254 return 255 256 cfa_t = get_cfa_types() 257 curr = root 258 259 while True: 260 processor = curr 261 should_stop = processor['_X12do_terminateVb_1'] 295 def print_processor(self, processor): 296 should_stop = processor['_X12do_terminateVb_1'] 297 if not should_stop: 298 midle = processor['_X6$linksS7$dlinks_S9processor__1']['_X4nextS9$mgd_link_Y13__tE_generic___1']['_X4elemPY13__tE_generic__1'] != 0x0 299 end = processor['_X6$linksS7$dlinks_S9processor__1']['_X4nextS9$mgd_link_Y13__tE_generic___1']['_X10terminatorPv_1'] != 0x0 300 301 status = 'Idle' if midle or end else 'Active' 302 else: 262 303 stop_count = processor['_X10terminatedS9semaphore_1']['_X5counti_1'] 263 if not should_stop: 264 status = 'Active' if active else 'Idle' 265 else: 266 status_str = 'Last Thread' if stop_count >= 0 else 'Terminating' 267 status = '{}({},{})'.format(status_str, should_stop, stop_count) 268 269 self.print_processor(processor['_X4namePKc_1'].string(), 270 status, str(processor['_X18pending_preemptionb_1']), str(processor) 271 ) 272 273 curr = curr['_X4nodeS28__processor____dbg_node_proc_1']['_X4nextPS9processor_1'] 274 275 if curr == root or curr == 0x0: 276 break 304 status_str = 'Last Thread' if stop_count >= 0 else 'Terminating' 305 status = '{}({},{})'.format(status_str, should_stop, stop_count) 306 307 print('{:>20} {:>11} {:<7} {:<}'.format( 308 processor['_X4namePKc_1'].string(), 309 status, 310 str(processor['_X18pending_preemptionb_1']), 311 str(processor) 312 )) 313 tls = tls_for_proc( processor ) 314 thrd = tls['_X11this_threadVPS7$thread_1'] 315 if thrd != 0x0: 316 tname = '{} {}'.format(thrd['self_cor']['name'].string(), str(thrd)) 317 else: 318 tname = None 319 320 print('{:>20} {}'.format('Thread', tname)) 321 print('{:>20} {}'.format('TLS', tls)) 277 322 278 323 #entry point from gdb … … 282 327 283 328 if not arg: 284 clusters = [lookup_cluster(None)]285 elif arg == "all":286 329 clusters = all_clusters() 287 330 else: … … 292 335 return 293 336 294 cfa_t = get_cfa_types() 295 for cluster in clusters: 296 print('Cluster: "{}"({})'.format(cluster['_X4namePKc_1'].string(), cluster.cast(cfa_t.cluster_ptr))) 297 298 active_root = cluster.cast(cfa_t.cluster_ptr) \ 299 ['_X5procsS8__dllist_S9processor__1'] \ 300 ['_X4headPY15__TYPE_generic__1'] \ 301 .cast(cfa_t.processor_ptr) 302 303 idle_root = cluster.cast(cfa_t.cluster_ptr) \ 304 ['_X5idlesS8__dllist_S9processor__1'] \ 305 ['_X4headPY15__TYPE_generic__1'] \ 306 .cast(cfa_t.processor_ptr) 307 308 if idle_root != 0x0 or active_root != 0x0: 309 self.print_processor('Name', 'Status', 'Pending Yield', 'Address') 310 self.iterate_procs(active_root, True) 311 self.iterate_procs(idle_root, False) 312 else: 313 print("No processors on cluster") 337 procs = all_processors() 338 339 print('{:>20} {:>11} {:<7} {}'.format('Processor', '', 'Pending', 'Object')) 340 print('{:>20} {:>11} {:<7} {}'.format('Name', 'Status', 'Yield', 'Address')) 341 cl = None 342 for p in procs: 343 # if this is a different cluster print it 344 if cl != p['_X4cltrPS7cluster_1']: 345 if cl: 346 print() 347 cl = p['_X4cltrPS7cluster_1'] 348 print('Cluster {}'.format(cl['_X4namePKc_1'].string())) 349 350 # print the processor information 351 self.print_processor(p) 314 352 315 353 print()
Note: See TracChangeset
for help on using the changeset viewer.