Task.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # File: Task.py
  2. # Author: Carl Allendorph
  3. # Date: 05NOV2014
  4. #
  5. # Description:
  6. # This file contains the implementation of a class to use for
  7. # inspecting the state of a FreeRTOS Task in GDB
  8. #
  9. import gdb
  10. class TaskInspector:
  11. TCBType = gdb.lookup_type("TCB_t")
  12. def __init__(self, handle):
  13. self._tcb = None
  14. # print("Task: Pass Handle: %s" % str(handle))
  15. try:
  16. if handle.type == TaskInspector.TCBType:
  17. self._tcb = handle
  18. return
  19. else:
  20. print("Handle Type: %s" % str(handle.type))
  21. except AttributeError as aexc:
  22. print("Attribute Error: %s" % str(aexc))
  23. pass
  24. except Exception as exc:
  25. print("Error Initializing Task Inspector: %s" % str(exc))
  26. raise
  27. try:
  28. tcbPtr = gdb.Value(handle).cast(TaskInspector.TCBType.pointer())
  29. self._tcb = tcbPtr.dereference()
  30. return
  31. except Exception as exc:
  32. print("Failed to convert Handle Pointer: %s" % str(handle))
  33. self._tcb = handle
  34. def GetName(self):
  35. if self._tcb != None:
  36. return self._tcb["pcTaskName"].string()
  37. else:
  38. raise ValueError("Invalid TCB")
  39. def GetPriority(self):
  40. if self._tcb != None:
  41. return self._tcb["uxPriority"]
  42. else:
  43. raise ValueError("Invalid TCB")
  44. def GetStackMargin(self):
  45. if self._tcb != None:
  46. topStack = self._tcb["pxTopOfStack"]
  47. stackBase = self._tcb["pxStack"]
  48. highWater = topStack - stackBase
  49. return highWater
  50. else:
  51. raise ValueError("Invalid TCB")