4 # GDB Pretty Printers for most isl objects
5 class IslObjectPrinter
:
6 """Print an isl object"""
7 def __init__ (self
, val
, type):
12 # Cast val to a void pointer to stop gdb using this pretty
13 # printer for the pointer which would lead to an infinite loop.
14 void_ptr
= gdb
.lookup_type('void').pointer()
15 value
= str(self
.val
.cast(void_ptr
))
16 printer
= gdb
.parse_and_eval("isl_printer_to_str(isl_"
18 + "_get_ctx(" + value
+ "))")
19 printer
= gdb
.parse_and_eval("isl_printer_print_"
20 + str(self
.type) + "("
23 string
= gdb
.parse_and_eval("(char*)isl_printer_get_str("
25 gdb
.parse_and_eval("isl_printer_free(" + str(printer
) + ")")
28 def display_hint (self
):
32 """Print an isl_int """
33 def __init__ (self
, val
):
37 # Cast val to a void pointer to stop gdb using this pretty
38 # printer for the pointer which would lead to an infinite loop.
39 void_ptr
= gdb
.lookup_type('void').pointer()
40 value
= str(self
.val
.cast(void_ptr
))
42 context
= gdb
.parse_and_eval("isl_ctx_alloc()")
43 printer
= gdb
.parse_and_eval("isl_printer_to_str("
45 printer
= gdb
.parse_and_eval("isl_printer_print_isl_int("
48 string
= gdb
.parse_and_eval("(char*)isl_printer_get_str("
50 gdb
.parse_and_eval("isl_printer_free(" + str(printer
) + ")")
51 gdb
.parse_and_eval("isl_ctx_free(" + str(context
) + ")")
54 def display_hint (self
):
57 class IslPrintCommand (gdb
.Command
):
58 """Print an isl value."""
60 super (IslPrintCommand
, self
).__init
__ ("islprint",
62 def invoke (self
, arg
, from_tty
):
63 arg
= gdb
.parse_and_eval(arg
);
64 printer
= str_lookup_function(arg
)
67 print "No isl printer for this type"
70 print printer
.to_string()
74 def str_lookup_function (val
):
75 if val
.type.code
!= gdb
.TYPE_CODE_PTR
:
76 if str(val
.type) == "isl_int":
77 return IslIntPrinter(val
)
81 lookup_tag
= val
.type.target()
82 regex
= re
.compile ("^isl_(.*)$")
84 if lookup_tag
== None:
87 m
= regex
.match (str(lookup_tag
))
90 # Those types of printers defined in isl.
91 if m
.group(1) in ["basic_set", "set", "union_set", "basic_map",
92 "map", "union_map", "qpolynomial",
93 "pw_qpolynomial", "pw_qpolynomial_fold",
94 "union_pw_qpolynomial",
95 "union_pw_qpolynomial_fold"]:
96 return IslObjectPrinter(val
, m
.group(1))
99 # Do not register the pretty printer.
100 # gdb.current_objfile().pretty_printers.append(str_lookup_function)