comparison gcc/gdbhooks.py @ 132:d34655255c78

update gcc-8.2
author mir3636
date Thu, 25 Oct 2018 10:21:07 +0900
parents 84e7813d76e9
children 1830386684a0
comparison
equal deleted inserted replaced
130:e108057fa461 132:d34655255c78
1 # Python hooks for gdb for debugging GCC 1 # Python hooks for gdb for debugging GCC
2 # Copyright (C) 2013-2017 Free Software Foundation, Inc. 2 # Copyright (C) 2013-2018 Free Software Foundation, Inc.
3 3
4 # Contributed by David Malcolm <dmalcolm@redhat.com> 4 # Contributed by David Malcolm <dmalcolm@redhat.com>
5 5
6 # This file is part of GCC. 6 # This file is part of GCC.
7 7
103 it's a quick way of getting lots of debuggability quickly. 103 it's a quick way of getting lots of debuggability quickly.
104 104
105 Callgraph nodes are printed with the name of the function decl, if 105 Callgraph nodes are printed with the name of the function decl, if
106 available: 106 available:
107 (gdb) frame 5 107 (gdb) frame 5
108 #5 0x00000000006c288a in expand_function (node=<cgraph_node* 0x7ffff0312720 "foo">) at ../../src/gcc/cgraphunit.c:1594 108 #5 0x00000000006c288a in expand_function (node=<cgraph_node* 0x7ffff0312720 "foo"/12345>) at ../../src/gcc/cgraphunit.c:1594
109 1594 execute_pass_list (g->get_passes ()->all_passes); 109 1594 execute_pass_list (g->get_passes ()->all_passes);
110 (gdb) p node 110 (gdb) p node
111 $1 = <cgraph_node* 0x7ffff0312720 "foo"> 111 $1 = <cgraph_node* 0x7ffff0312720 "foo"/12345>
112
113 Similarly for symtab_node and varpool_node classes.
114
115 Cgraph edges are printed with the name of caller and callee:
116 (gdb) p this->callees
117 $4 = <cgraph_edge* 0x7fffe25aa000 (<cgraph_node * 0x7fffe62b22e0 "_GLOBAL__sub_I__ZN5Pooma5pinfoE"/19660> -> <cgraph_node * 0x7fffe620f730 "__static_initialization_and_destruction_1"/19575>)>
118
119 IPA reference follow very similar format:
120 (gdb) Value returned is $5 = <ipa_ref* 0x7fffefcb80c8 (<symtab_node * 0x7ffff562f000 "__dt_base "/875> -> <symtab_node * 0x7fffe795f000 "_ZTVN6Smarts8RunnableE"/16056>:IPA_REF_ADDR)>
112 121
113 vec<> pointers are printed as the address followed by the elements in 122 vec<> pointers are printed as the address followed by the elements in
114 braces. Here's a length 2 vec: 123 braces. Here's a length 2 vec:
115 (gdb) p bb->preds 124 (gdb) p bb->preds
116 $18 = 0x7ffff0428b68 = {<edge 0x7ffff044d380 (3 -> 5)>, <edge 0x7ffff044d3b8 (4 -> 5)>} 125 $18 = 0x7ffff0428b68 = {<edge 0x7ffff044d380 (3 -> 5)>, <edge 0x7ffff044d3b8 (4 -> 5)>}
243 252
244 ###################################################################### 253 ######################################################################
245 # Callgraph pretty-printers 254 # Callgraph pretty-printers
246 ###################################################################### 255 ######################################################################
247 256
248 class CGraphNodePrinter: 257 class SymtabNodePrinter:
249 def __init__(self, gdbval): 258 def __init__(self, gdbval):
250 self.gdbval = gdbval 259 self.gdbval = gdbval
251 260
252 def to_string (self): 261 def to_string (self):
253 result = '<cgraph_node* 0x%x' % intptr(self.gdbval) 262 t = str(self.gdbval.type)
263 result = '<%s 0x%x' % (t, intptr(self.gdbval))
254 if intptr(self.gdbval): 264 if intptr(self.gdbval):
255 # symtab_node::name calls lang_hooks.decl_printable_name 265 # symtab_node::name calls lang_hooks.decl_printable_name
256 # default implementation (lhd_decl_printable_name) is: 266 # default implementation (lhd_decl_printable_name) is:
257 # return IDENTIFIER_POINTER (DECL_NAME (decl)); 267 # return IDENTIFIER_POINTER (DECL_NAME (decl));
258 tree_decl = Tree(self.gdbval['decl']) 268 tree_decl = Tree(self.gdbval['decl'])
259 result += ' "%s"' % tree_decl.DECL_NAME().IDENTIFIER_POINTER() 269 result += ' "%s"/%d' % (tree_decl.DECL_NAME().IDENTIFIER_POINTER(), self.gdbval['order'])
270 result += '>'
271 return result
272
273 class CgraphEdgePrinter:
274 def __init__(self, gdbval):
275 self.gdbval = gdbval
276
277 def to_string (self):
278 result = '<cgraph_edge* 0x%x' % intptr(self.gdbval)
279 if intptr(self.gdbval):
280 src = SymtabNodePrinter(self.gdbval['caller']).to_string()
281 dest = SymtabNodePrinter(self.gdbval['callee']).to_string()
282 result += ' (%s -> %s)' % (src, dest)
283 result += '>'
284 return result
285
286 class IpaReferencePrinter:
287 def __init__(self, gdbval):
288 self.gdbval = gdbval
289
290 def to_string (self):
291 result = '<ipa_ref* 0x%x' % intptr(self.gdbval)
292 if intptr(self.gdbval):
293 src = SymtabNodePrinter(self.gdbval['referring']).to_string()
294 dest = SymtabNodePrinter(self.gdbval['referred']).to_string()
295 result += ' (%s -> %s:%s)' % (src, dest, str(self.gdbval['use']))
260 result += '>' 296 result += '>'
261 return result 297 return result
262 298
263 ###################################################################### 299 ######################################################################
264 # Dwarf DIE pretty-printers 300 # Dwarf DIE pretty-printers
501 537
502 def build_pretty_printer(): 538 def build_pretty_printer():
503 pp = GdbPrettyPrinters('gcc') 539 pp = GdbPrettyPrinters('gcc')
504 pp.add_printer_for_types(['tree'], 540 pp.add_printer_for_types(['tree'],
505 'tree', TreePrinter) 541 'tree', TreePrinter)
506 pp.add_printer_for_types(['cgraph_node *'], 542 pp.add_printer_for_types(['cgraph_node *', 'varpool_node *', 'symtab_node *'],
507 'cgraph_node', CGraphNodePrinter) 543 'symtab_node', SymtabNodePrinter)
544 pp.add_printer_for_types(['cgraph_edge *'],
545 'cgraph_edge', CgraphEdgePrinter)
546 pp.add_printer_for_types(['ipa_ref *'],
547 'ipa_ref', IpaReferencePrinter)
508 pp.add_printer_for_types(['dw_die_ref'], 548 pp.add_printer_for_types(['dw_die_ref'],
509 'dw_die_ref', DWDieRefPrinter) 549 'dw_die_ref', DWDieRefPrinter)
510 pp.add_printer_for_types(['gimple', 'gimple *', 550 pp.add_printer_for_types(['gimple', 'gimple *',
511 551
512 # Keep this in the same order as gimple.def: 552 # Keep this in the same order as gimple.def: