Changeset 96df7c9c
- Timestamp:
- Mar 18, 2020, 3:39:29 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 45f4147
- Parents:
- bb75b4e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/gdb/utils-gdb.py
rbb75b4e r96df7c9c 25 25 CfaTypes = collections.namedtuple('CfaTypes', 'cluster_ptr processor_ptr thread_ptr int_ptr thread_state') 26 26 27 class Thread :27 class ThreadInfo: 28 28 tid = 0 29 29 cluster = None … … 100 100 print('No clusters, program terminated') 101 101 return cluster_root 102 103 def find_curr_thread(): 104 # btstr = gdb.execute('bt', to_string = True).splitlines() 105 # if len(btstr) == 0: 106 # print('error') 107 # return None 108 # return btstr[0].split('this=',1)[1].split(',')[0].split(')')[0] 109 return None 102 110 103 111 def lookup_cluster(name = None): … … 134 142 return cluster 135 143 144 def lookup_threads_by_cluster(cluster): 145 # Iterate through a circular linked list of threads and accumulate them in an array 146 threads = [] 147 148 cfa_t = get_cfa_types() 149 root = cluster['_X7threadsS8__dllist_S7$thread__1']['_X4headPY15__TYPE_generic__1'].cast(cfa_t.thread_ptr) 150 151 if root == 0x0 or root.address == 0x0: 152 print('There are no tasks for cluster: {}'.format(cluster)) 153 return threads 154 155 curr = root 156 tid = 0 157 sid = -1 158 159 while True: 160 t = ThreadInfo(cluster, curr) 161 if t.is_system(): 162 t.tid = sid 163 sid -= 1 164 else: 165 t.tid = tid 166 tid += 1 167 168 threads.append(t) 169 170 curr = curr['node']['next'] 171 if curr == root or curr == 0x0: 172 break 173 174 return threads 175 136 176 def system_thread(thread): 137 177 return False … … 257 297 ############ 258 298 class Threads(gdb.Command): 299 """Cforall: Display currently known threads 300 Usage: 301 cfathreads : print Main Cluster threads, application threads only 302 cfathreads all : print all clusters, all threads 303 cfathreads <clusterName> : print cluster threads, application threads only 304 """ 259 305 def __init__(self): 260 306 # The first parameter of the line below is the name of the command. You … … 262 308 super(Threads, self).__init__('info cfathreads', gdb.COMMAND_USER) 263 309 264 def print_usage(self): 265 print_usage(""" 266 cfathread : print userCluster tasks, application tasks only 267 cfathread all : print all clusters, all tasks 268 cfathread <clusterName> : print cluster tasks, application tasks only 269 """) 310 def print_formatted(self, marked, tid, name, state, address): 311 print('{:>1} {:>4} {:>20} {:>10} {:>20}'.format('*' if marked else ' ', tid, name, state, address)) 312 313 def print_thread(self, thread, tid, marked): 314 cfa_t = get_cfa_types() 315 self.print_formatted(marked, tid, thread['self_cor']['name'].string(), str(thread['state'].cast(cfa_t.thread_state)), str(thread)) 316 317 def print_formatted_cluster(self, str_format, cluster_name, cluster_addr): 318 print(str_format.format(cluster_name, cluster_addr)) 319 320 def print_threads_by_cluster(self, cluster, print_system = False): 321 # Iterate through a circular linked list of tasks and print out its 322 # name along with address associated to each cluster 323 threads = lookup_threads_by_cluster(cluster) 324 if not threads: 325 return 326 327 running_thread = find_curr_thread() 328 if running_thread is None: 329 print('Could not identify current thread') 330 331 self.print_formatted(False, '', 'Name', 'State', 'Address') 332 333 for t in threads: 334 if not t.is_system() or print_system: 335 self.print_thread(t.value, t.tid, t.value == running_thread if running_thread else False) 336 337 print() 338 339 def print_all_threads(self): 340 print("Not implemented") 270 341 271 342 def invoke(self, arg, from_tty): … … 277 348 return 278 349 279 argv = parse(arg) 280 print(argv) 281 if len(argv) == 0: 350 if not arg: 282 351 cluster = lookup_cluster() 283 352 if not cluster: … … 288 357 self.print_threads_by_cluster(cluster, False) 289 358 290 elif len(argv) == 1: 291 if argv[0] == 'help': 292 self.print_usage() 293 # print tasks 294 elif argv[0] == 'all': 295 self.print_all_threads() # all tasks, all clusters 296 else: 297 """ 298 Print out all the tasks available in the specified cluster 299 @cluster_name: str 300 """ 301 print("cfathread by name") 302 cluster = lookup_cluster(argv[0]) 303 if not cluster: 304 return 305 306 # all tasks, specified cluster 307 self.print_threads_by_cluster(cluster, True) 308 309 elif len(argv) == 2: 310 # push task 311 self.pushtask_by_id(argv[0], argv[1]) # by id, specified cluster 359 elif arg == 'all': 360 # all threads, all clusters 361 self.print_all_threads() 362 312 363 else: 313 print('Invalid arguments') 314 self.print_usage() 364 cluster = lookup_cluster(arg) 365 if not cluster: 366 print("Could not find cluster '{}'".format(arg)) 367 return 368 369 # all tasks, specified cluster 370 self.print_threads_by_cluster(cluster, True) 371 315 372 316 373 ############ … … 343 400 print(str_format.format(cluster_name, cluster_addr)) 344 401 345 def find_curr_thread(self):346 # btstr = gdb.execute('bt', to_string = True).splitlines()347 # if len(btstr) == 0:348 # print('error')349 # return None350 # return btstr[0].split('this=',1)[1].split(',')[0].split(')')[0]351 return None352 353 402 def print_tasks_by_cluster_all(self, cluster_address): 354 403 """ … … 404 453 return 405 454 406 def threads_by_cluster(self, cluster):407 # Iterate through a circular linked list of threads and accumulate them in an array408 threads = []409 410 cfa_t = get_cfa_types()411 root = cluster['_X7threadsS8__dllist_S7$thread__1']['_X4headPY15__TYPE_generic__1'].cast(cfa_t.thread_ptr)412 413 if root == 0x0 or root.address == 0x0:414 print('There are no tasks for cluster: {}'.format(cluster))415 return threads416 417 curr = root418 tid = 0419 sid = -1420 421 while True:422 t = Thread(cluster, curr)423 if t.is_system():424 t.tid = sid425 sid -= 1426 else:427 t.tid = tid428 tid += 1429 430 threads.append(t)431 432 curr = curr['node']['next']433 if curr == root or curr == 0x0:434 break435 436 return threads437 438 455 def print_threads_by_cluster(self, cluster, print_system = False): 439 456 """ … … 457 474 for t in threads: 458 475 if not t.is_system() or print_system: 459 self.print_thread(t.value, t.tid, t ivalue == running_thread if running_thread else False)476 self.print_thread(t.value, t.tid, t.value == running_thread if running_thread else False) 460 477 461 478 print()
Note: See TracChangeset
for help on using the changeset viewer.