summaryrefslogtreecommitdiff
path: root/gcc/gdbhooks.py
diff options
context:
space:
mode:
authorbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-22 14:58:36 +0000
committerbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-22 14:58:36 +0000
commitcfea6514a4b6ced0930593ebb48d0037e9716d87 (patch)
treeeeccf866e18463f7dc7ea882ea944247d4ed1010 /gcc/gdbhooks.py
parent9456798d72d0e81a2a553287f436dcb05cff175a (diff)
downloadgcc-cfea6514a4b6ced0930593ebb48d0037e9716d87.tar.gz
[./]
2013-11-22 Basile Starynkevitch <basile@starynkevitch.net> {{merge with trunk GCC 4.9 svn rev 205247 now in stage 3}} [gcc/] 2013-11-22 Basile Starynkevitch <basile@starynkevitch.net> {{merge with trunk GCC 4.9 svn rev 205247 now in stage 3}} * Makefile.in (MELT_GCC_VERSION_NUM): New make variable. (melt-run-md5.h, melt-run.h): Use it. * melt-runtime.cc: With GCC 4.9 include print-tree.h, gimple-iterator.h, gimple-walk.h. (meltgc_start_all_new_modules, meltgc_start_flavored_module) (meltgc_do_initial_mode, meltgc_set_user_options) (meltgc_load_modules_and_do_mode): Improve debugprintf... (melt_gt_ggc_mx_gimple_seq_d): Handle GCC 4.9 specifically. * melt-runtime.h (gt_ggc_mx_gimple_statement_d): Temporarily define this macro. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@205264 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/gdbhooks.py')
-rw-r--r--gcc/gdbhooks.py115
1 files changed, 99 insertions, 16 deletions
diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
index 53abf329113..f0a925c2b9c 100644
--- a/gcc/gdbhooks.py
+++ b/gcc/gdbhooks.py
@@ -109,6 +109,26 @@ available:
1594 execute_pass_list (g->get_passes ()->all_passes);
(gdb) p node
$1 = <cgraph_node* 0x7ffff0312720 "foo">
+
+vec<> pointers are printed as the address followed by the elements in
+braces. Here's a length 2 vec:
+ (gdb) p bb->preds
+ $18 = 0x7ffff0428b68 = {<edge 0x7ffff044d380 (3 -> 5)>, <edge 0x7ffff044d3b8 (4 -> 5)>}
+
+and here's a length 1 vec:
+ (gdb) p bb->succs
+ $19 = 0x7ffff0428bb8 = {<edge 0x7ffff044d3f0 (5 -> EXIT)>}
+
+You cannot yet use array notation [] to access the elements within the
+vector: attempting to do so instead gives you the vec itself (for vec[0]),
+or a (probably) invalid cast to vec<> for the memory after the vec (for
+vec[1] onwards).
+
+Instead (for now) you must access m_vecdata:
+ (gdb) p bb->preds->m_vecdata[0]
+ $20 = <edge 0x7ffff044d380 (3 -> 5)>
+ (gdb) p bb->preds->m_vecdata[1]
+ $21 = <edge 0x7ffff044d3b8 (4 -> 5)>
"""
import re
@@ -223,7 +243,7 @@ class CGraphNodePrinter:
def to_string (self):
result = '<cgraph_node* 0x%x' % long(self.gdbval)
if long(self.gdbval):
- # symtab_node_name calls lang_hooks.decl_printable_name
+ # symtab_node::name calls lang_hooks.decl_printable_name
# default implementation (lhd_decl_printable_name) is:
# return IDENTIFIER_POINTER (DECL_NAME (decl));
tree_decl = Tree(self.gdbval['decl'])
@@ -240,7 +260,7 @@ class GimplePrinter:
def to_string (self):
if long(self.gdbval) == 0:
return '<gimple 0x0>'
- val_gimple_code = self.gdbval['gsbase']['code']
+ val_gimple_code = self.gdbval['code']
val_gimple_code_name = gdb.parse_and_eval('gimple_code_name')
val_code_name = val_gimple_code_name[long(val_gimple_code)]
result = '<%s 0x%x' % (val_code_name.string(),
@@ -349,29 +369,79 @@ class PassPrinter:
######################################################################
+class VecPrinter:
+ # -ex "up" -ex "p bb->preds"
+ def __init__(self, gdbval):
+ self.gdbval = gdbval
+
+ def display_hint (self):
+ return 'array'
+
+ def to_string (self):
+ # A trivial implementation; prettyprinting the contents is done
+ # by gdb calling the "children" method below.
+ return '0x%x' % long(self.gdbval)
+
+ def children (self):
+ if long(self.gdbval) == 0:
+ return
+ m_vecpfx = self.gdbval['m_vecpfx']
+ m_num = m_vecpfx['m_num']
+ m_vecdata = self.gdbval['m_vecdata']
+ for i in range(m_num):
+ yield ('[%d]' % i, m_vecdata[i])
+
+######################################################################
+
# TODO:
-# * vec
# * hashtab
# * location_t
class GdbSubprinter(gdb.printing.SubPrettyPrinter):
- def __init__(self, name, str_type_, class_):
+ def __init__(self, name, class_):
super(GdbSubprinter, self).__init__(name)
- self.str_type_ = str_type_
self.class_ = class_
+ def handles_type(self, str_type):
+ raise NotImplementedError
+
+class GdbSubprinterTypeList(GdbSubprinter):
+ """
+ A GdbSubprinter that handles a specific set of types
+ """
+ def __init__(self, str_types, name, class_):
+ super(GdbSubprinterTypeList, self).__init__(name, class_)
+ self.str_types = frozenset(str_types)
+
+ def handles_type(self, str_type):
+ return str_type in self.str_types
+
+class GdbSubprinterRegex(GdbSubprinter):
+ """
+ A GdbSubprinter that handles types that match a regex
+ """
+ def __init__(self, regex, name, class_):
+ super(GdbSubprinterRegex, self).__init__(name, class_)
+ self.regex = re.compile(regex)
+
+ def handles_type(self, str_type):
+ return self.regex.match(str_type)
+
class GdbPrettyPrinters(gdb.printing.PrettyPrinter):
def __init__(self, name):
super(GdbPrettyPrinters, self).__init__(name, [])
- def add_printer(self, name, exp, class_):
- self.subprinters.append(GdbSubprinter(name, exp, class_))
+ def add_printer_for_types(self, name, class_, types):
+ self.subprinters.append(GdbSubprinterTypeList(name, class_, types))
+
+ def add_printer_for_regex(self, name, class_, regex):
+ self.subprinters.append(GdbSubprinterRegex(name, class_, regex))
def __call__(self, gdbval):
type_ = gdbval.type.unqualified()
- str_type_ = str(type_)
+ str_type = str(type_)
for printer in self.subprinters:
- if printer.enabled and str_type_ == printer.str_type_:
+ if printer.enabled and printer.handles_type(str_type):
return printer.class_(gdbval)
# Couldn't find a pretty printer (or it was disabled):
@@ -380,13 +450,26 @@ class GdbPrettyPrinters(gdb.printing.PrettyPrinter):
def build_pretty_printer():
pp = GdbPrettyPrinters('gcc')
- pp.add_printer('tree', 'tree', TreePrinter)
- pp.add_printer('cgraph_node', 'cgraph_node *', CGraphNodePrinter)
- pp.add_printer('gimple', 'gimple', GimplePrinter)
- pp.add_printer('basic_block', 'basic_block', BasicBlockPrinter)
- pp.add_printer('edge', 'edge', CfgEdgePrinter)
- pp.add_printer('rtx_def', 'rtx_def *', RtxPrinter)
- pp.add_printer('opt_pass', 'opt_pass *', PassPrinter)
+ pp.add_printer_for_types(['tree'],
+ 'tree', TreePrinter)
+ pp.add_printer_for_types(['cgraph_node *'],
+ 'cgraph_node', CGraphNodePrinter)
+ pp.add_printer_for_types(['gimple', 'gimple_statement_base *'],
+ 'gimple',
+ GimplePrinter)
+ pp.add_printer_for_types(['basic_block', 'basic_block_def *'],
+ 'basic_block',
+ BasicBlockPrinter)
+ pp.add_printer_for_types(['edge', 'edge_def *'],
+ 'edge',
+ CfgEdgePrinter)
+ pp.add_printer_for_types(['rtx_def *'], 'rtx_def', RtxPrinter)
+ pp.add_printer_for_types(['opt_pass *'], 'opt_pass', PassPrinter)
+
+ pp.add_printer_for_regex(r'vec<(\S+), (\S+), (\S+)> \*',
+ 'vec',
+ VecPrinter)
+
return pp
gdb.printing.register_pretty_printer(