HandleRegistry.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # File: HandleRegistry.py
  2. # Author: Carl Allendorph
  3. # Date: 06NOV2014
  4. #
  5. # Description:
  6. # THis file contains the implementation of a class for accessing the
  7. # handle registry. This contains a mapping of queue handles to
  8. # strings for labeling purposes.
  9. import gdb
  10. from .Types import StdTypes
  11. from .QueueTools import *
  12. class HandleRegistry:
  13. """The FreeRTOS system can be configured with a table that
  14. associates a name with a QueueHandle_t.
  15. This class can be used to access this table and
  16. label queue/mutex/semaphore/event groups
  17. """
  18. def __init__(self, regSymbol="xQueueRegistry"):
  19. symbol, methodObj = gdb.lookup_symbol(regSymbol)
  20. self._registry = symbol.value()
  21. self._minIndex = 0
  22. self._maxIndex = 0
  23. self._minIndex, self._maxIndex = self._registry.type.range()
  24. def GetName(self, handle):
  25. """Find the string name associated with a queue
  26. handle if it exists in the registry
  27. """
  28. for i in range(self._minIndex, self._maxIndex):
  29. elem = self._registry[i]
  30. h = elem["xHandle"]
  31. val = h.cast(StdTypes.uint32_t)
  32. if handle == val:
  33. print("Found Entry for: %x" % handle)
  34. name = elem["pcQueueName"].string()
  35. return name
  36. def PrintRegistry(self):
  37. for i in range(self._minIndex, self._maxIndex):
  38. elem = self._registry[i]
  39. h = elem["xHandle"]
  40. if h != 0:
  41. name = elem["pcQueueName"].string()
  42. print("%d: %3s %16s" % (i, h, name))
  43. def FilterBy(self, qMode):
  44. """Retrieve a List of Mutex Queue Handles"""
  45. resp = []
  46. for i in range(self._minIndex, self._maxIndex):
  47. elem = self._registry[i]
  48. h = elem["xHandle"]
  49. if h != 0:
  50. name = elem["pcQueueName"].string()
  51. q = QueueInspector(h)
  52. q.SetName(name)
  53. if qMode != None:
  54. qType = q.GetQueueType()
  55. if qType != None:
  56. if qType == qMode:
  57. resp.append(q)
  58. else:
  59. print("qType == None")
  60. else:
  61. resp.append(q)
  62. return resp
  63. def GetMutexes(self):
  64. """Retrieve all the Mutex Objects in the Handle Registry"""
  65. return self.FilterBy(QueueMode.MUTEX)
  66. def GetSemaphores(self):
  67. """Retrieve all the Semaphore Objects in the Handle Registry"""
  68. return self.FilterBy(QueueMode.BINARY)
  69. def GetQueues(self):
  70. """Retrieve all the Queue Objects in the Handle Registry"""
  71. return self.FilterBy(QueueMode.QUEUE)