GDBCommands.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # File: GDBCommands.py
  2. # Author: Carl Allendorph
  3. # Date: 05NOV2014
  4. #
  5. # Description:
  6. # This file contains the implementation of some custom
  7. # GDB commands for Inspecting the FreeRTOS state
  8. import gdb
  9. from .List import ListInspector
  10. from .Task import TaskInspector
  11. from .HandleRegistry import HandleRegistry
  12. from .QueueTools import *
  13. class ShowQueueInfo(gdb.Command):
  14. """Generate a print out of info about a particular
  15. set of queues.
  16. """
  17. def __init__(self):
  18. super(ShowQueueInfo, self).__init__("show Queue-Info", gdb.COMMAND_SUPPORT)
  19. def invoke(self, arg, from_tty):
  20. argv = gdb.string_to_argv(arg)
  21. qTypes = []
  22. if len(argv) > 0:
  23. for a in argv:
  24. try:
  25. qType = QueueMode.Map[a]
  26. qTypes.append(qType)
  27. except KeyError:
  28. print("Arg %s does not map to a Queue Type!" % a)
  29. reg = HandleRegistry()
  30. qToShow = []
  31. if len(qTypes) > 0:
  32. # We will only print info about queues
  33. for qType in qTypes:
  34. qObjs = reg.FilterBy(qType)
  35. qToShow.extend(qObjs)
  36. else:
  37. qToShow = reg.FilterBy(None)
  38. print("Num Queues: %d" % len(qToShow))
  39. print("%20s %4s %16s %16s" % ("NAME", "CNT", "SEND", "RECEIVE"))
  40. for q in qToShow:
  41. self.PrintQueueInfo(q)
  42. def PrintQueueInfo(self, q):
  43. """Print Info about the Queue"""
  44. sendList = q.GetTasksWaitingToSend()
  45. rxList = q.GetTasksWaitingToReceive()
  46. # print("TxLen: %d, RxLen: %d" % (len(sendList), len(rxList)))
  47. maxCount = max(len(sendList), len(rxList))
  48. outputFmt = "%20s %4s %16s %16s"
  49. if maxCount == 0:
  50. print(outputFmt % (q.GetName(), q.GetQueueMessagesWaiting(), "", ""))
  51. else:
  52. for i in range(0, maxCount):
  53. txName = ""
  54. if i < len(sendList):
  55. tcbRef, val = sendList[i]
  56. tcb = TaskInspector(tcbRef)
  57. txName = tcb.GetName()
  58. rxName = ""
  59. if i < len(rxList):
  60. tcbRef, val = rxList[i]
  61. tcb = TaskInspector(tcbRef)
  62. rxName = tcb.GetName()
  63. if i == 0:
  64. print(
  65. outputFmt
  66. % (q.GetName(), q.GetQueueMessagesWaiting(), txName, rxName)
  67. )
  68. else:
  69. print(outputFmt % ("", "", txName, rxName))
  70. class ShowHandleName(gdb.Command):
  71. """Generate a print out of the handle by name"""
  72. def __init__(self):
  73. super(ShowHandleName, self).__init__("show Handle-Name", gdb.COMMAND_SUPPORT)
  74. def invoke(self, arg, from_tty):
  75. argv = gdb.string_to_argv(arg)
  76. if len(argv) != 1:
  77. print("Invalid Argument: Requires one handle arg")
  78. handle = int(argv[0], 0)
  79. reg = HandleRegistry()
  80. name = reg.GetName(handle)
  81. print("Handle 0x%08x: %s" % (handle, name))
  82. class ShowRegistry(gdb.Command):
  83. """Generate a print out of the queue handle registry"""
  84. def __init__(self):
  85. super(ShowRegistry, self).__init__("show Handle-Registry", gdb.COMMAND_SUPPORT)
  86. def invoke(self, arg, from_tty):
  87. reg = HandleRegistry()
  88. reg.PrintRegistry()
  89. class ShowList(gdb.Command):
  90. """Generate a print out of the elements in a list
  91. passed to this command. User must pass a symbol that
  92. will be looked up.
  93. """
  94. def __init__(self):
  95. super(ShowList, self).__init__(
  96. "show List-Handle", gdb.COMMAND_SUPPORT, gdb.COMPLETE_SYMBOL
  97. )
  98. def invoke(self, arg, from_tty):
  99. argv = gdb.string_to_argv(arg)
  100. CastTypeStr = None
  101. if len(argv) > 0:
  102. symbolArg = argv[0]
  103. if len(argv) > 1:
  104. CastTypeStr = argv[1]
  105. listVal = ListInspector(symbolArg)
  106. elems = listVal.GetElements(CastTypeStr)
  107. for elem in elems:
  108. print("Elem: %s" % str(elem))