Changeset ddbc530 in rtems-tools


Ignore:
Timestamp:
Aug 21, 2013, 12:42:36 PM (6 years ago)
Author:
Dhananjay Balan <mb.dhananjay@…>
Branches:
4.10, 4.11, master
Children:
8da0a37
Parents:
d4fc2d5
git-author:
Dhananjay Balan <mb.dhananjay@…> (08/21/13 12:42:36)
git-committer:
Chris Johns <chrisj@…> (08/24/14 23:52:41)
Message:

Refactor subcommands

  • index commands inherit from a parent class.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/gdb/python/rtems.py

    rd4fc2d5 rddbc530  
    6666        objects.information.invalidate()
    6767
    68 class rtems_semaphore(gdb.Command):
    69     '''Semaphore subcommand for rtems'''
     68class rtems_index(gdb.Command):
     69    '''Print object by index'''
    7070
    7171    api = 'classic'
    72     _class = 'semaphores'
     72    _class = ''
    7373
    74     def __init__(self):
    75         self.__doc__ = 'Display the RTEMS semaphores by index'
    76         super(rtems_semaphore, self).__init__( 'rtems semaphore',
    77                                            gdb.COMMAND_DATA, gdb.COMPLETE_NONE )
     74    def __init__(self,command):
     75        super(rtems_index, self).__init__( command,
     76                                           gdb.COMMAND_DATA,
     77                                           gdb.COMPLETE_NONE)
     78
     79    def instance(self,obj):
     80        '''Returns a n instance of corresponding object, the child should extend this'''
     81        return obj
    7882
    7983    def invoke(self, arg, from_tty):
     
    9296                return
    9397
    94             instance = classic.semaphore(obj)
     98            instance = self.instance(obj)
    9599            instance.show(from_tty)
    96100        objects.information.invalidate()
    97101
    98 class rtems_task(gdb.Command):
     102
     103class rtems_semaphore(rtems_index):
     104    '''semaphore subcommand'''
     105    _class = 'semaphores'
     106
     107    def __init__(self):
     108        self.__doc__ = 'Display RTEMS semaphore(s) by index(es)'
     109        super(rtems_semaphore, self).__init__('rtems semaphore')
     110
     111    def instance(self,obj):
     112        return classic.semaphore(obj)
     113
     114class rtems_task(rtems_index):
    99115    '''tasks subcommand for rtems'''
    100116
    101     api = 'classic'
    102117    _class = 'tasks'
    103118
    104119    def __init__(self):
    105         self.__doc__ = 'Display the RTEMS tasks by index(s)'
    106         super(rtems_task,self).__init__('rtems task',
    107                                         gdb.COMMAND_DATA, gdb.COMPLETE_NONE)
     120        self.__doc__ = 'Display RTEMS task(s) by index(es)'
     121        super(rtems_task,self).__init__('rtems task')
    108122
    109     def invoke(self, arg, from_tty):
    110         for val in arg.split():
    111             try:
    112                 index = int(val)
    113             except ValueError:
    114                 raise gdb.GdbError( "Value is not an integer")
     123    def instance(self,obj):
     124        return classic.task(obj)
    115125
    116             try:
    117                 obj = objects.information.object_return(self.api,
    118                                                         self._class,
    119                                                         index).dereference()
    120             except IndexError:
    121                 print "error: index %s is invalid" % (index)
    122                 return
    123126
    124             instance = classic.task(obj)
    125             instance.show(from_tty)
    126         objects.information.invalidate()
    127 
    128 class rtems_message_queue(gdb.Command):
     127class rtems_message_queue(rtems_index):
    129128    '''Message Queue subcommand'''
    130129
    131     api = 'classic'
    132130    _class = 'message_queues'
    133131
    134132    def __init__(self):
    135         self.__doc__ = 'Display the RTEMS message_queue by index(s)'
    136         super(rtems_message_queue,self).__init__('rtems mqueue',
    137                                                 gdb.COMMAND_DATA,
    138                                                 gdb.COMPLETE_NONE)
     133        self.__doc__ = 'Display RTEMS message_queue(s) by index(es)'
     134        super(rtems_message_queue,self).__init__('rtems mqueue')
    139135
    140     def invoke(self, arg, from_tty):
    141         for val in arg.split():
    142             try:
    143                 index = int(val)
    144             except ValueError:
    145                 print "error: %s is not an index" % (val)
    146                 return
     136    def instance(self,obj):
     137        return classic.message_queue(obj)
    147138
    148             try:
    149                 obj = objects.information.object_return(self.api,
    150                                                         self._class,
    151                                                         index).dereference()
    152             except IndexError:
    153                 print "error: index %s is invalid" % (index)
    154                 return
    155 
    156             instance = classic.message_queue(obj)
    157             instance.show(from_tty)
    158         objects.information.invalidate()
Note: See TracChangeset for help on using the changeset viewer.