gdb-prettyprint.py 1.8 KB

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