Changeset 96df7c9c


Ignore:
Timestamp:
Mar 18, 2020, 3:39:29 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
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
Message:

Pushing intermediate to other machines

File:
1 edited

Legend:

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

    rbb75b4e r96df7c9c  
    2525CfaTypes = collections.namedtuple('CfaTypes', 'cluster_ptr processor_ptr thread_ptr int_ptr thread_state')
    2626
    27 class Thread:
     27class ThreadInfo:
    2828    tid = 0
    2929    cluster = None
     
    100100        print('No clusters, program terminated')
    101101    return cluster_root
     102
     103def 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
    102110
    103111def lookup_cluster(name = None):
     
    134142    return cluster
    135143
     144def 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
    136176def system_thread(thread):
    137177    return False
     
    257297############
    258298class Threads(gdb.Command):
     299    """Cforall: Display currently known threads
     300Usage:
     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    """
    259305    def __init__(self):
    260306        # The first parameter of the line below is the name of the command. You
     
    262308        super(Threads, self).__init__('info cfathreads', gdb.COMMAND_USER)
    263309
    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")
    270341
    271342    def invoke(self, arg, from_tty):
     
    277348            return
    278349
    279         argv = parse(arg)
    280         print(argv)
    281         if len(argv) == 0:
     350        if not arg:
    282351            cluster = lookup_cluster()
    283352            if not cluster:
     
    288357            self.print_threads_by_cluster(cluster, False)
    289358
    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
    312363        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
    315372
    316373############
     
    343400        print(str_format.format(cluster_name, cluster_addr))
    344401
    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 None
    350         # return btstr[0].split('this=',1)[1].split(',')[0].split(')')[0]
    351         return None
    352 
    353402    def print_tasks_by_cluster_all(self, cluster_address):
    354403        """
     
    404453            return
    405454
    406     def threads_by_cluster(self, cluster):
    407         # Iterate through a circular linked list of threads and accumulate them in an array
    408         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 threads
    416 
    417         curr = root
    418         tid = 0
    419         sid = -1
    420 
    421         while True:
    422             t = Thread(cluster, curr)
    423             if t.is_system():
    424                 t.tid = sid
    425                 sid -= 1
    426             else:
    427                 t.tid = tid
    428                 tid += 1
    429 
    430             threads.append(t)
    431 
    432             curr = curr['node']['next']
    433             if curr == root or curr == 0x0:
    434                 break
    435 
    436         return threads
    437 
    438455    def print_threads_by_cluster(self, cluster, print_system = False):
    439456        """
     
    457474        for t in threads:
    458475            if not t.is_system() or print_system:
    459                 self.print_thread(t.value, t.tid, tivalue == running_thread if running_thread else False)
     476                self.print_thread(t.value, t.tid, t.value == running_thread if running_thread else False)
    460477
    461478        print()
Note: See TracChangeset for help on using the changeset viewer.