FreeRTOS.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # File: FreeRTOS.py
  2. # Author: Carl Allendorph
  3. # Date: 05NOV2014
  4. #
  5. # Description:
  6. # This file contains some python code that utilizes the GDB API
  7. # to inspect information about the FreeRTOS internal state. The
  8. # idea is to provide the user with the ability to inspect information
  9. # about the tasks, queues, mutexs, etc.
  10. #
  11. from os import path
  12. import sys
  13. directory, file = path.split(__file__)
  14. directory = path.expanduser(directory)
  15. directory = path.abspath(directory)
  16. sys.path.append(directory)
  17. import gdb
  18. import pprint
  19. from FreeRTOSgdb.Types import StdTypes
  20. from FreeRTOSgdb.List import ListInspector
  21. from FreeRTOSgdb.GDBCommands import ShowHandleName, ShowRegistry, ShowList
  22. from FreeRTOSgdb.GDBCommands import ShowQueueInfo
  23. class Scheduler:
  24. def __init__(self):
  25. self._blocked = ListInspector("xSuspendedTaskList")
  26. self._delayed1 = ListInspector("xDelayedTaskList1")
  27. self._delayed2 = ListInspector("xDelayedTaskList2")
  28. self._readyLists = []
  29. readyTasksListsStr = "pxReadyTasksLists"
  30. readyListsSym, methodType = gdb.lookup_symbol(readyTasksListsStr)
  31. if readyListsSym != None:
  32. readyLists = readyListsSym.value()
  33. minIndex, maxIndex = readyLists.type.range()
  34. for i in range(minIndex, maxIndex + 1):
  35. readyList = readyLists[i]
  36. FRReadyList = ListInspector(readyList)
  37. self._readyLists.append(FRReadyList)
  38. else:
  39. print("Failed to Find Symbol: %s" % readyTasksListsStr)
  40. raise ValueError("Invalid Symbol!")
  41. def ShowTaskList(self):
  42. self.PrintTableHeader()
  43. for i, rlist in enumerate(self._readyLists):
  44. if i == 0:
  45. items = rlist.GetElements("TCB_t", 0)
  46. else:
  47. items = rlist.GetElements("TCB_t", 1)
  48. if len(items) > 0:
  49. print("Ready List {%d}: Num Tasks: %d" % (i, len(items)))
  50. for tcb, val in items:
  51. self.PrintTaskFormatted(tcb)
  52. items = self._blocked.GetElements("TCB_t")
  53. print("Blocked List: Num Tasks: %d" % len(items))
  54. for tcb, val in items:
  55. self.PrintTaskFormatted(tcb)
  56. items = self._delayed1.GetElements("TCB_t")
  57. print("Delayed {1}: Num Tasks: %d" % len(items))
  58. for tcb, val in items:
  59. self.PrintTaskFormatted(tcb, val)
  60. items = self._delayed2.GetElements("TCB_t")
  61. print("Delayed {2}: Num Tasks: %d" % len(items))
  62. for tcb, val in items:
  63. self.PrintTaskFormatted(tcb, val)
  64. def PrintTableHeader(self):
  65. print("%16s %3s %4s" % ("Name", "PRI", "STCK"))
  66. def PrintTaskFormatted(self, task, itemVal=None):
  67. topStack = task["pxTopOfStack"]
  68. stackBase = task["pxStack"]
  69. highWater = topStack - stackBase
  70. taskName = task["pcTaskName"].string()
  71. taskPriority = task["uxPriority"]
  72. if itemVal != None:
  73. print("%16s %3s %4s %5s" % (taskName, taskPriority, highWater, itemVal))
  74. else:
  75. print("%16s %3s %4s" % (taskName, taskPriority, highWater))
  76. class ShowTaskList(gdb.Command):
  77. """Generate a print out of the current tasks and their states."""
  78. def __init__(self):
  79. super(ShowTaskList, self).__init__("show Task-List", gdb.COMMAND_SUPPORT)
  80. def invoke(self, arg, from_tty):
  81. sched = Scheduler()
  82. sched.ShowTaskList()
  83. ShowRegistry()
  84. ShowList()
  85. ShowTaskList()
  86. ShowHandleName()
  87. ShowQueueInfo()