List.py 3.3 KB

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