mirror of
https://git.rtems.org/rtems-tools/
synced 2025-10-17 18:39:47 +08:00
Refactor subcommands
- index commands inherit from a parent class.
This commit is contained in:

committed by
Chris Johns

parent
d4fc2d5e54
commit
ddbc5306fa
@@ -65,16 +65,20 @@ class rtems_object(gdb.Command):
|
|||||||
object.show(from_tty)
|
object.show(from_tty)
|
||||||
objects.information.invalidate()
|
objects.information.invalidate()
|
||||||
|
|
||||||
class rtems_semaphore(gdb.Command):
|
class rtems_index(gdb.Command):
|
||||||
'''Semaphore subcommand for rtems'''
|
'''Print object by index'''
|
||||||
|
|
||||||
api = 'classic'
|
api = 'classic'
|
||||||
_class = 'semaphores'
|
_class = ''
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self,command):
|
||||||
self.__doc__ = 'Display the RTEMS semaphores by index'
|
super(rtems_index, self).__init__( command,
|
||||||
super(rtems_semaphore, self).__init__( 'rtems semaphore',
|
gdb.COMMAND_DATA,
|
||||||
gdb.COMMAND_DATA, gdb.COMPLETE_NONE )
|
gdb.COMPLETE_NONE)
|
||||||
|
|
||||||
|
def instance(self,obj):
|
||||||
|
'''Returns a n instance of corresponding object, the child should extend this'''
|
||||||
|
return obj
|
||||||
|
|
||||||
def invoke(self, arg, from_tty):
|
def invoke(self, arg, from_tty):
|
||||||
for val in arg.split():
|
for val in arg.split():
|
||||||
@@ -91,68 +95,44 @@ class rtems_semaphore(gdb.Command):
|
|||||||
print "error: index %s is invalid" % (index)
|
print "error: index %s is invalid" % (index)
|
||||||
return
|
return
|
||||||
|
|
||||||
instance = classic.semaphore(obj)
|
instance = self.instance(obj)
|
||||||
instance.show(from_tty)
|
instance.show(from_tty)
|
||||||
objects.information.invalidate()
|
objects.information.invalidate()
|
||||||
|
|
||||||
class rtems_task(gdb.Command):
|
|
||||||
|
class rtems_semaphore(rtems_index):
|
||||||
|
'''semaphore subcommand'''
|
||||||
|
_class = 'semaphores'
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.__doc__ = 'Display RTEMS semaphore(s) by index(es)'
|
||||||
|
super(rtems_semaphore, self).__init__('rtems semaphore')
|
||||||
|
|
||||||
|
def instance(self,obj):
|
||||||
|
return classic.semaphore(obj)
|
||||||
|
|
||||||
|
class rtems_task(rtems_index):
|
||||||
'''tasks subcommand for rtems'''
|
'''tasks subcommand for rtems'''
|
||||||
|
|
||||||
api = 'classic'
|
|
||||||
_class = 'tasks'
|
_class = 'tasks'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.__doc__ = 'Display the RTEMS tasks by index(s)'
|
self.__doc__ = 'Display RTEMS task(s) by index(es)'
|
||||||
super(rtems_task,self).__init__('rtems task',
|
super(rtems_task,self).__init__('rtems task')
|
||||||
gdb.COMMAND_DATA, gdb.COMPLETE_NONE)
|
|
||||||
|
|
||||||
def invoke(self, arg, from_tty):
|
def instance(self,obj):
|
||||||
for val in arg.split():
|
return classic.task(obj)
|
||||||
try:
|
|
||||||
index = int(val)
|
|
||||||
except ValueError:
|
|
||||||
raise gdb.GdbError( "Value is not an integer")
|
|
||||||
|
|
||||||
try:
|
|
||||||
obj = objects.information.object_return(self.api,
|
|
||||||
self._class,
|
|
||||||
index).dereference()
|
|
||||||
except IndexError:
|
|
||||||
print "error: index %s is invalid" % (index)
|
|
||||||
return
|
|
||||||
|
|
||||||
instance = classic.task(obj)
|
class rtems_message_queue(rtems_index):
|
||||||
instance.show(from_tty)
|
|
||||||
objects.information.invalidate()
|
|
||||||
|
|
||||||
class rtems_message_queue(gdb.Command):
|
|
||||||
'''Message Queue subcommand'''
|
'''Message Queue subcommand'''
|
||||||
|
|
||||||
api = 'classic'
|
|
||||||
_class = 'message_queues'
|
_class = 'message_queues'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.__doc__ = 'Display the RTEMS message_queue by index(s)'
|
self.__doc__ = 'Display RTEMS message_queue(s) by index(es)'
|
||||||
super(rtems_message_queue,self).__init__('rtems mqueue',
|
super(rtems_message_queue,self).__init__('rtems mqueue')
|
||||||
gdb.COMMAND_DATA,
|
|
||||||
gdb.COMPLETE_NONE)
|
|
||||||
|
|
||||||
def invoke(self, arg, from_tty):
|
def instance(self,obj):
|
||||||
for val in arg.split():
|
return classic.message_queue(obj)
|
||||||
try:
|
|
||||||
index = int(val)
|
|
||||||
except ValueError:
|
|
||||||
print "error: %s is not an index" % (val)
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
obj = objects.information.object_return(self.api,
|
|
||||||
self._class,
|
|
||||||
index).dereference()
|
|
||||||
except IndexError:
|
|
||||||
print "error: index %s is invalid" % (index)
|
|
||||||
return
|
|
||||||
|
|
||||||
instance = classic.message_queue(obj)
|
|
||||||
instance.show(from_tty)
|
|
||||||
objects.information.invalidate()
|
|
Reference in New Issue
Block a user