libisl.dll.a-gdb.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import gdb
  2. import re
  3. # GDB Pretty Printers for most isl objects
  4. class IslObjectPrinter:
  5. """Print an isl object"""
  6. def __init__ (self, val, type):
  7. self.val = val
  8. self.type = type
  9. def to_string (self):
  10. # Cast val to a void pointer to stop gdb using this pretty
  11. # printer for the pointer which would lead to an infinite loop.
  12. void_ptr = gdb.lookup_type('void').pointer()
  13. value = str(self.val.cast(void_ptr))
  14. printer = gdb.parse_and_eval("isl_printer_to_str(isl_"
  15. + str(self.type)
  16. + "_get_ctx(" + value + "))")
  17. printer = gdb.parse_and_eval("isl_printer_print_"
  18. + str(self.type) + "("
  19. + str(printer) + ", "
  20. + value + ")")
  21. string = gdb.parse_and_eval("(char*)isl_printer_get_str("
  22. + str(printer) + ")")
  23. gdb.parse_and_eval("isl_printer_free(" + str(printer) + ")")
  24. return string
  25. def display_hint (self):
  26. return 'string'
  27. class IslIntPrinter:
  28. """Print an isl_int """
  29. def __init__ (self, val):
  30. self.val = val
  31. def to_string (self):
  32. # Cast val to a void pointer to stop gdb using this pretty
  33. # printer for the pointer which would lead to an infinite loop.
  34. void_ptr = gdb.lookup_type('void').pointer()
  35. value = str(self.val.cast(void_ptr))
  36. context = gdb.parse_and_eval("isl_ctx_alloc()")
  37. printer = gdb.parse_and_eval("isl_printer_to_str("
  38. + str(context) + ")")
  39. printer = gdb.parse_and_eval("isl_printer_print_isl_int("
  40. + str(printer) + ", "
  41. + value + ")")
  42. string = gdb.parse_and_eval("(char*)isl_printer_get_str("
  43. + str(printer) + ")")
  44. gdb.parse_and_eval("isl_printer_free(" + str(printer) + ")")
  45. gdb.parse_and_eval("isl_ctx_free(" + str(context) + ")")
  46. return string
  47. def display_hint (self):
  48. return 'string'
  49. class IslPrintCommand (gdb.Command):
  50. """Print an isl value."""
  51. def __init__ (self):
  52. super (IslPrintCommand, self).__init__ ("islprint",
  53. gdb.COMMAND_OBSCURE)
  54. def invoke (self, arg, from_tty):
  55. arg = gdb.parse_and_eval(arg);
  56. printer = str_lookup_function(arg)
  57. if printer == None:
  58. print("No isl printer for this type")
  59. return
  60. print(printer.to_string())
  61. IslPrintCommand()
  62. def str_lookup_function (val):
  63. if val.type.code != gdb.TYPE_CODE_PTR:
  64. if str(val.type) == "isl_int":
  65. return IslIntPrinter(val)
  66. else:
  67. return None
  68. lookup_tag = val.type.target()
  69. regex = re.compile ("^isl_(.*)$")
  70. if lookup_tag == None:
  71. return None
  72. m = regex.match (str(lookup_tag))
  73. if m:
  74. # Those types of printers defined in isl.
  75. if m.group(1) in ["basic_set", "set", "union_set", "basic_map",
  76. "map", "union_map", "qpolynomial",
  77. "pw_qpolynomial", "pw_qpolynomial_fold",
  78. "union_pw_qpolynomial",
  79. "union_pw_qpolynomial_fold"]:
  80. return IslObjectPrinter(val, m.group(1))
  81. return None
  82. # Do not register the pretty printer.
  83. # gdb.current_objfile().pretty_printers.append(str_lookup_function)