Changeset bb75b4e


Ignore:
Timestamp:
Mar 12, 2020, 5:55:30 PM (5 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:
96df7c9c
Parents:
5c08a1a
Message:

Changed processors and clusters command to fit more closely info threads

File:
1 edited

Legend:

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

    r5c08a1a rbb75b4e  
    7474    return str_addr[:ending_addr_index].strip()
    7575
    76 def print_usage(msg):
    77     """
    78     Print out usage message
    79     @msg: str
    80     """
    81     print('Usage: ' + msg)
     76def print_usage(obj):
     77    print(obj.__doc__)
    8278
    8379def parse(args):
     
    150146
    151147class Clusters(gdb.Command):
    152     """Print out the list of available clusters"""
    153     usage_msg = 'clusters'
    154     str_format = ''
     148    """Cforall: Display currently known clusters
     149Usage:
     150    info clusters                 : print out all the clusters
     151"""
    155152
    156153    def __init__(self):
    157         super(Clusters, self).__init__('clusters', gdb.COMMAND_USER)
     154        super(Clusters, self).__init__('info clusters', gdb.COMMAND_USER)
    158155
    159156    def print_cluster(self, cluster_name, cluster_address):
    160157        print('{:>20}  {:>20}'.format(cluster_name, cluster_address))
    161158
     159    #entry point from gdb
    162160    def invoke(self, arg, from_tty):
    163         """
    164         Iterate through a circular linked list of clusters and print out its
    165         name along with address associated to each cluster
    166         @arg: str
    167         @from_tty: bool
    168         """
    169161        if not is_cforall():
    170162            return
    171163
    172         argv = parse(arg)
    173         if len(argv) != 0:
    174             print_usage('clusters')
     164        if arg:
     165            print("info clusters does not take arguments")
     166            print_usage(self)
    175167            return
    176168
     
    192184############
    193185class Processors(gdb.Command):
    194     """Display a list of all info about all available processors on a particular cluster"""
    195     usage_msg = """
    196     processors                 : print out all the processors in the Main Cluster
    197     processors <cluster_name>  : print out all processors in a given cluster"""
     186    """Cforall: Display currently known processors
     187Usage:
     188    info processors                 : print out all the processors in the Main Cluster
     189    info processors <cluster_name>  : print out all processors in a given cluster
     190"""
    198191
    199192    def __init__(self):
    200         super(Processors, self).__init__('processors', gdb.COMMAND_USER)
     193        super(Processors, self).__init__('info processors', gdb.COMMAND_USER)
    201194
    202195    def print_processor(self, name, status, pending, address):
    203         print('{:>20}  {:>20}  {:>13}  {:>20}'.format(name, status, pending, address))
    204 
    205     def iterate_procs(self, root):
     196        print('{:>20}  {:>11}  {:>13}  {:>20}'.format(name, status, pending, address))
     197
     198    def iterate_procs(self, root, active):
    206199        if root == 0x0:
    207             print('{:>20}'.format("None"))
    208200            return
    209201
    210202        cfa_t = get_cfa_types()
    211 
    212         self.print_processor('Name', 'Termination Status', 'Yield Pending', 'Address')
    213203        curr = root
    214204
     
    217207            should_stop = processor['_X12do_terminateVb_1']
    218208            stop_count  = processor['_X10terminatedS9semaphore_1']['_X5counti_1']
    219             status_str  = 'Running' if not should_stop else 'Last Thread' if stop_count >= 0 else 'Terminating'
    220             status      = '{}({},{})'.format(status_str, should_stop, stop_count)
     209            if not should_stop:
     210                status = 'Active' if active else 'Idle'
     211            else:
     212                status_str  = 'Last Thread' if stop_count >= 0 else 'Terminating'
     213                status      = '{}({},{})'.format(status_str, should_stop, stop_count)
    221214
    222215            self.print_processor(processor['_X4namePKc_1'].string(),
     
    229222                break
    230223
    231         print()
    232 
     224    #entry point from gdb
    233225    def invoke(self, arg, from_tty):
    234         """
    235         Iterate through a circular linked list of tasks and print out all
    236         info about each processor in that cluster
    237         @arg: str
    238         @from_tty: bool
    239         """
    240226        if not is_cforall():
    241227            return
    242228
     229        cluster = lookup_cluster(arg if arg else None)
     230
     231        if not cluster:
     232            print("No Cluster matching arguments found")
     233            return
     234
    243235        cfa_t = get_cfa_types()
    244 
    245         argv = parse(arg)
    246         if len(argv) > 1:
    247             print_usage(self.usage_msg)
    248             return
    249 
    250         cluster = lookup_cluster(argv[0] if len(argv) > 0 else None)
    251 
    252         if cluster == 0x0 or cluster == None:
    253             print("No Cluster matching arguments found")
    254             return
    255 
    256         print('Cluster {}({})'.format(cluster['_X4namePKc_1'].string(), cluster.cast(cfa_t.cluster_ptr)))
     236        print('Cluster: "{}"({})'.format(cluster['_X4namePKc_1'].string(), cluster.cast(cfa_t.cluster_ptr)))
    257237
    258238        active_root = cluster.cast(cfa_t.cluster_ptr) \
     
    266246                .cast(cfa_t.processor_ptr)
    267247
    268         print("Active Processors")
    269         self.iterate_procs(active_root)
    270 
    271         print("\nIdle Processors")
    272         self.iterate_procs(idle_root)
     248        if idle_root != 0x0 or active_root != 0x0:
     249            self.print_processor('Name', 'Status', 'Pending Yield', 'Address')
     250            self.iterate_procs(active_root, True)
     251            self.iterate_procs(idle_root, False)
     252        else:
     253            print("No processors on cluster")
     254
     255        print()
    273256
    274257############
    275258class Threads(gdb.Command):
     259    def __init__(self):
     260        # The first parameter of the line below is the name of the command. You
     261        # can call it 'uc++ task'
     262        super(Threads, self).__init__('info cfathreads', gdb.COMMAND_USER)
     263
     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    """)
     270
     271    def invoke(self, arg, from_tty):
     272        """
     273        @arg: str
     274        @from_tty: bool
     275        """
     276        if not is_cforall():
     277            return
     278
     279        argv = parse(arg)
     280        print(argv)
     281        if len(argv) == 0:
     282            cluster = lookup_cluster()
     283            if not cluster:
     284                print("Could not find Main Cluster")
     285                return
     286
     287            # only tasks and main
     288            self.print_threads_by_cluster(cluster, False)
     289
     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
     312        else:
     313            print('Invalid arguments')
     314            self.print_usage()
     315
     316############
     317class Thread(gdb.Command):
    276318    def __init__(self):
    277319        # The first parameter of the line below is the name of the command. You
Note: See TracChangeset for help on using the changeset viewer.