List.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # File: List.py
  2. # Author: Carl Allendorph
  3. # Date: 05NOV2014
  4. #
  5. # Description:
  6. # This file contains the class for inspecting
  7. # a FreeRTOS List Object
  8. #
  9. import gdb
  10. from .Types import StdTypes
  11. class ListInspector:
  12. """FreeRTOS List Inspector Object"""
  13. ListType = gdb.lookup_type("List_t")
  14. def __init__(self, handle):
  15. """"""
  16. self._list = None
  17. # print("List: Handle: %s" % handle)
  18. self.Assign(handle)
  19. def Assign(self, listObj):
  20. try:
  21. if listObj.type == ListInspector.ListType:
  22. self._list = listObj
  23. return
  24. else:
  25. raise TypeError("Invalid List Object Type!")
  26. except Exception as exc:
  27. # print(" Failed to assign from List object: %s" % str(exc))
  28. pass
  29. symbol, methodObj = gdb.lookup_symbol(listObj)
  30. if symbol != None:
  31. self._list = symbol.value()
  32. else:
  33. addrInt = int(listObj, 0)
  34. listObjPtr = gdb.Value(addrInt).cast(ListInspector.ListType.pointer())
  35. self._list = listObjPtr.dereference()
  36. def GetElements(self, CastTypeStr=None, startElem=1):
  37. """Get the Elements of the list as an array of
  38. gdb.Value type objects.
  39. @param CastTypeStr string name of the type of object that
  40. we will cast the void *pvOwner elements of the list to.
  41. User can also pass a L{gdb.Type} object as the type
  42. If None, we will simply cast to uint32_t and print these
  43. as hex values.
  44. @param startElem This is a flag to indicate whether
  45. we will start getting elements starting at 0 or 1. Note
  46. that this is to deal with some non-consistent behavior
  47. of some of the TCB Task lists.
  48. """
  49. if self._list != None:
  50. CastType = None
  51. if CastTypeStr != None:
  52. if type(CastTypeStr) == str:
  53. try:
  54. CastType = gdb.lookup_type(CastTypeStr).pointer()
  55. except:
  56. print("Failed to find type: %s" % CastTypeStr)
  57. elif type(CastTypeStr) == gdb.Type:
  58. CastType = CastTypeStr.pointer()
  59. resp = []
  60. numElems = self._list["uxNumberOfItems"]
  61. # print("List Elements: %d" % numElems)
  62. index = self._list["pxIndex"]
  63. if numElems > 0 and numElems < 200:
  64. if startElem == 0:
  65. curr = index
  66. else:
  67. curr = index["pxPrevious"]
  68. for i in range(0, numElems):
  69. owner = curr["pvOwner"]
  70. ownerObj = None
  71. if CastType != None:
  72. castObjPtr = owner.cast(CastType)
  73. castObj = castObjPtr.dereference()
  74. ownerObj = castObj
  75. else:
  76. ownerUInt = owner.cast(StdTypes.uint32_t)
  77. ownerObj = ownerUInt
  78. itemVal = curr["xItemValue"]
  79. resp.append((ownerObj, itemVal.cast(StdTypes.uint32_t)))
  80. curr = curr["pxPrevious"]
  81. return resp
  82. else:
  83. raise ValueError("Invalid List Object - Possibly Failed to Initialize!")