gdb-prettyprint.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # WARNING: This is till work in progress
  2. #
  3. # Load into gdb with 'source ../tools/gdb-prettyprint.py'
  4. # Make sure to also apply 'set print pretty on' to get nice structure printouts
  5. class String:
  6. def __init__(self, val):
  7. self.val = val
  8. def to_string (self):
  9. length = int(self.val['length'])
  10. data = self.val['data']
  11. if int(data) == 0:
  12. return "UA_STRING_NULL"
  13. inferior = gdb.selected_inferior()
  14. text = inferior.read_memory(data, length).tobytes().decode(errors='replace')
  15. return "\"%s\"" % text
  16. class LocalizedText:
  17. def __init__(self, val):
  18. self.val = val
  19. def to_string (self):
  20. return "UA_LocalizedText(%s, %s)" % (self.val['locale'], self.val['text'])
  21. class QualifiedName:
  22. def __init__(self, val):
  23. self.val = val
  24. def to_string (self):
  25. return "UA_QualifiedName(%s, %s)" % (int(self.val['namespaceIndex']), self.val['name'])
  26. class Guid:
  27. def __init__(self, val):
  28. self.val = val
  29. def to_string (self):
  30. return "UA_Guid()"
  31. class NodeId:
  32. def __init__(self, val):
  33. self.val = val
  34. def to_string (self):
  35. return "UA_NodeId()"
  36. class Variant:
  37. def __init__(self, val):
  38. self.val = val
  39. def to_string (self):
  40. return "UA_Variant()"
  41. def lookup_type (val):
  42. if str(val.type) == 'UA_String':
  43. return String(val)
  44. if str(val.type) == 'UA_LocalizedText':
  45. return LocalizedText(val)
  46. if str(val.type) == 'UA_QualifiedName':
  47. return QualifiedName(val)
  48. if str(val.type) == 'UA_Guid':
  49. return Guid(val)
  50. if str(val.type) == 'UA_NodeId':
  51. return NodeId(val)
  52. if str(val.type) == 'UA_Variant':
  53. return Variant(val)
  54. return None
  55. gdb.pretty_printers.append (lookup_type)