4 # GDB Pretty Printers for most isl objects
5 class IslObjectPrinter
:
6 """Print an isl object"""
8 def __init__(self
, val
, type):
13 # Cast val to a void pointer to stop gdb using this pretty
14 # printer for the pointer which would lead to an infinite loop.
15 void_ptr
= gdb
.lookup_type("void").pointer()
16 value
= str(self
.val
.cast(void_ptr
))
17 printer
= gdb
.parse_and_eval(
18 "isl_printer_to_str(isl_" + str(self
.type) + "_get_ctx(" + value
+ "))"
20 printer
= gdb
.parse_and_eval(
29 string
= gdb
.parse_and_eval("(char*)isl_printer_get_str(" + str(printer
) + ")")
30 gdb
.parse_and_eval("isl_printer_free(" + str(printer
) + ")")
33 def display_hint(self
):
38 """Print an isl_int"""
40 def __init__(self
, val
):
44 # Cast val to a void pointer to stop gdb using this pretty
45 # printer for the pointer which would lead to an infinite loop.
46 void_ptr
= gdb
.lookup_type("void").pointer()
47 value
= str(self
.val
.cast(void_ptr
))
49 context
= gdb
.parse_and_eval("isl_ctx_alloc()")
50 printer
= gdb
.parse_and_eval("isl_printer_to_str(" + str(context
) + ")")
51 printer
= gdb
.parse_and_eval(
52 "isl_printer_print_isl_int(" + str(printer
) + ", " + value
+ ")"
54 string
= gdb
.parse_and_eval("(char*)isl_printer_get_str(" + str(printer
) + ")")
55 gdb
.parse_and_eval("isl_printer_free(" + str(printer
) + ")")
56 gdb
.parse_and_eval("isl_ctx_free(" + str(context
) + ")")
59 def display_hint(self
):
63 class IslPrintCommand(gdb
.Command
):
64 """Print an isl value."""
67 super(IslPrintCommand
, self
).__init
__("islprint", gdb
.COMMAND_OBSCURE
)
69 def invoke(self
, arg
, from_tty
):
70 arg
= gdb
.parse_and_eval(arg
)
71 printer
= str_lookup_function(arg
)
74 print("No isl printer for this type")
77 print(printer
.to_string())
83 def str_lookup_function(val
):
84 if val
.type.code
!= gdb
.TYPE_CODE_PTR
:
85 if str(val
.type) == "isl_int":
86 return IslIntPrinter(val
)
90 lookup_tag
= val
.type.target()
91 regex
= re
.compile("^isl_(.*)$")
93 if lookup_tag
== None:
96 m
= regex
.match(str(lookup_tag
))
99 # Those types of printers defined in isl.
109 "pw_qpolynomial_fold",
110 "union_pw_qpolynomial",
111 "union_pw_qpolynomial_fold",
113 return IslObjectPrinter(val
, m
.group(1))
117 # Do not register the pretty printer.
118 # gdb.current_objfile().pretty_printers.append(str_lookup_function)