2013-08-28 05:01:20 +02:00
|
|
|
# Python hooks for gdb for debugging GCC
|
2016-01-04 15:30:50 +01:00
|
|
|
# Copyright (C) 2013-2016 Free Software Foundation, Inc.
|
2013-08-28 05:01:20 +02:00
|
|
|
|
|
|
|
# Contributed by David Malcolm <dmalcolm@redhat.com>
|
|
|
|
|
|
|
|
# This file is part of GCC.
|
|
|
|
|
|
|
|
# GCC is free software; you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU General Public License as published by the Free
|
|
|
|
# Software Foundation; either version 3, or (at your option) any later
|
|
|
|
# version.
|
|
|
|
|
|
|
|
# GCC is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
# for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with GCC; see the file COPYING3. If not see
|
|
|
|
# <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
"""
|
|
|
|
Enabling the debugging hooks
|
|
|
|
----------------------------
|
|
|
|
gcc/configure (from configure.ac) generates a .gdbinit within the "gcc"
|
|
|
|
subdirectory of the build directory, and when run by gdb, this imports
|
|
|
|
gcc/gdbhooks.py from the source directory, injecting useful Python code
|
|
|
|
into gdb.
|
|
|
|
|
|
|
|
You may see a message from gdb of the form:
|
|
|
|
"path-to-build/gcc/.gdbinit" auto-loading has been declined by your `auto-load safe-path'
|
|
|
|
as a protection against untrustworthy python scripts. See
|
|
|
|
http://sourceware.org/gdb/onlinedocs/gdb/Auto_002dloading-safe-path.html
|
|
|
|
|
|
|
|
The fix is to mark the paths of the build/gcc directory as trustworthy.
|
|
|
|
An easy way to do so is by adding the following to your ~/.gdbinit script:
|
|
|
|
add-auto-load-safe-path /absolute/path/to/build/gcc
|
|
|
|
for the build directories for your various checkouts of gcc.
|
|
|
|
|
|
|
|
If it's working, you should see the message:
|
|
|
|
Successfully loaded GDB hooks for GCC
|
|
|
|
as gdb starts up.
|
|
|
|
|
|
|
|
During development, I've been manually invoking the code in this way, as a
|
|
|
|
precanned way of printing a variety of different kinds of value:
|
|
|
|
|
|
|
|
gdb \
|
|
|
|
-ex "break expand_gimple_stmt" \
|
|
|
|
-ex "run" \
|
|
|
|
-ex "bt" \
|
|
|
|
--args \
|
|
|
|
./cc1 foo.c -O3
|
|
|
|
|
|
|
|
Examples of output using the pretty-printers
|
|
|
|
--------------------------------------------
|
|
|
|
Pointer values are generally shown in the form:
|
|
|
|
<type address extra_info>
|
|
|
|
|
|
|
|
For example, an opt_pass* might appear as:
|
|
|
|
(gdb) p pass
|
|
|
|
$2 = <opt_pass* 0x188b600 "expand"(170)>
|
|
|
|
|
|
|
|
The name of the pass is given ("expand"), together with the
|
|
|
|
static_pass_number.
|
|
|
|
|
|
|
|
Note that you can dereference the pointer in the normal way:
|
|
|
|
(gdb) p *pass
|
|
|
|
$4 = {type = RTL_PASS, name = 0x120a312 "expand",
|
|
|
|
[etc, ...snipped...]
|
|
|
|
|
|
|
|
and you can suppress pretty-printers using /r (for "raw"):
|
|
|
|
(gdb) p /r pass
|
|
|
|
$3 = (opt_pass *) 0x188b600
|
|
|
|
|
|
|
|
Basic blocks are shown with their index in parentheses, apart from the
|
|
|
|
CFG's entry and exit blocks, which are given as "ENTRY" and "EXIT":
|
|
|
|
(gdb) p bb
|
|
|
|
$9 = <basic_block 0x7ffff041f1a0 (2)>
|
|
|
|
(gdb) p cfun->cfg->x_entry_block_ptr
|
|
|
|
$10 = <basic_block 0x7ffff041f0d0 (ENTRY)>
|
|
|
|
(gdb) p cfun->cfg->x_exit_block_ptr
|
|
|
|
$11 = <basic_block 0x7ffff041f138 (EXIT)>
|
|
|
|
|
|
|
|
CFG edges are shown with the src and dest blocks given in parentheses:
|
|
|
|
(gdb) p e
|
|
|
|
$1 = <edge 0x7ffff043f118 (ENTRY -> 6)>
|
|
|
|
|
|
|
|
Tree nodes are printed using Python code that emulates print_node_brief,
|
|
|
|
running in gdb, rather than in the inferior:
|
|
|
|
(gdb) p cfun->decl
|
|
|
|
$1 = <function_decl 0x7ffff0420b00 foo>
|
|
|
|
For usability, the type is printed first (e.g. "function_decl"), rather
|
|
|
|
than just "tree".
|
|
|
|
|
|
|
|
RTL expressions use a kludge: they are pretty-printed by injecting
|
|
|
|
calls into print-rtl.c into the inferior:
|
|
|
|
Value returned is $1 = (note 9 8 10 [bb 3] NOTE_INSN_BASIC_BLOCK)
|
|
|
|
(gdb) p $1
|
|
|
|
$2 = (note 9 8 10 [bb 3] NOTE_INSN_BASIC_BLOCK)
|
|
|
|
(gdb) p /r $1
|
|
|
|
$3 = (rtx_def *) 0x7ffff043e140
|
|
|
|
This won't work for coredumps, and probably in other circumstances, but
|
|
|
|
it's a quick way of getting lots of debuggability quickly.
|
|
|
|
|
|
|
|
Callgraph nodes are printed with the name of the function decl, if
|
|
|
|
available:
|
|
|
|
(gdb) frame 5
|
|
|
|
#5 0x00000000006c288a in expand_function (node=<cgraph_node* 0x7ffff0312720 "foo">) at ../../src/gcc/cgraphunit.c:1594
|
|
|
|
1594 execute_pass_list (g->get_passes ()->all_passes);
|
|
|
|
(gdb) p node
|
|
|
|
$1 = <cgraph_node* 0x7ffff0312720 "foo">
|
2013-11-20 04:57:35 +01:00
|
|
|
|
|
|
|
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)>
|
2013-08-28 05:01:20 +02:00
|
|
|
"""
|
2014-08-05 23:01:47 +02:00
|
|
|
import os.path
|
2013-08-28 05:01:20 +02:00
|
|
|
import re
|
2015-06-08 15:35:51 +02:00
|
|
|
import sys
|
2013-08-28 05:01:20 +02:00
|
|
|
|
|
|
|
import gdb
|
|
|
|
import gdb.printing
|
|
|
|
import gdb.types
|
|
|
|
|
|
|
|
# Convert "enum tree_code" (tree.def and tree.h) to a dict:
|
|
|
|
tree_code_dict = gdb.types.make_enum_dict(gdb.lookup_type('enum tree_code'))
|
|
|
|
|
|
|
|
# ...and look up specific values for use later:
|
|
|
|
IDENTIFIER_NODE = tree_code_dict['IDENTIFIER_NODE']
|
|
|
|
TYPE_DECL = tree_code_dict['TYPE_DECL']
|
|
|
|
|
|
|
|
# Similarly for "enum tree_code_class" (tree.h):
|
|
|
|
tree_code_class_dict = gdb.types.make_enum_dict(gdb.lookup_type('enum tree_code_class'))
|
|
|
|
tcc_type = tree_code_class_dict['tcc_type']
|
|
|
|
tcc_declaration = tree_code_class_dict['tcc_declaration']
|
|
|
|
|
2015-06-08 15:35:51 +02:00
|
|
|
# Python3 has int() with arbitrary precision (bignum). Python2 int() is 32-bit
|
|
|
|
# on 32-bit hosts but remote targets may have 64-bit pointers there; Python2
|
|
|
|
# long() is always 64-bit but Python3 no longer has anything named long.
|
|
|
|
def intptr(gdbval):
|
|
|
|
return long(gdbval) if sys.version_info.major == 2 else int(gdbval)
|
|
|
|
|
2013-08-28 05:01:20 +02:00
|
|
|
class Tree:
|
|
|
|
"""
|
|
|
|
Wrapper around a gdb.Value for a tree, with various methods
|
|
|
|
corresponding to macros in gcc/tree.h
|
|
|
|
"""
|
|
|
|
def __init__(self, gdbval):
|
|
|
|
self.gdbval = gdbval
|
|
|
|
|
|
|
|
def is_nonnull(self):
|
2015-06-08 15:35:51 +02:00
|
|
|
return intptr(self.gdbval)
|
2013-08-28 05:01:20 +02:00
|
|
|
|
|
|
|
def TREE_CODE(self):
|
|
|
|
"""
|
|
|
|
Get gdb.Value corresponding to TREE_CODE (self)
|
|
|
|
as per:
|
|
|
|
#define TREE_CODE(NODE) ((enum tree_code) (NODE)->base.code)
|
|
|
|
"""
|
|
|
|
return self.gdbval['base']['code']
|
|
|
|
|
|
|
|
def DECL_NAME(self):
|
|
|
|
"""
|
|
|
|
Get Tree instance corresponding to DECL_NAME (self)
|
|
|
|
"""
|
|
|
|
return Tree(self.gdbval['decl_minimal']['name'])
|
|
|
|
|
|
|
|
def TYPE_NAME(self):
|
|
|
|
"""
|
|
|
|
Get Tree instance corresponding to result of TYPE_NAME (self)
|
|
|
|
"""
|
|
|
|
return Tree(self.gdbval['type_common']['name'])
|
|
|
|
|
|
|
|
def IDENTIFIER_POINTER(self):
|
|
|
|
"""
|
|
|
|
Get str correspoinding to result of IDENTIFIER_NODE (self)
|
|
|
|
"""
|
|
|
|
return self.gdbval['identifier']['id']['str'].string()
|
|
|
|
|
|
|
|
class TreePrinter:
|
|
|
|
"Prints a tree"
|
|
|
|
|
|
|
|
def __init__ (self, gdbval):
|
|
|
|
self.gdbval = gdbval
|
|
|
|
self.node = Tree(gdbval)
|
|
|
|
|
|
|
|
def to_string (self):
|
|
|
|
# like gcc/print-tree.c:print_node_brief
|
|
|
|
# #define TREE_CODE(NODE) ((enum tree_code) (NODE)->base.code)
|
|
|
|
# tree_code_name[(int) TREE_CODE (node)])
|
2015-06-08 15:35:51 +02:00
|
|
|
if intptr(self.gdbval) == 0:
|
2013-08-28 05:01:20 +02:00
|
|
|
return '<tree 0x0>'
|
|
|
|
|
|
|
|
val_TREE_CODE = self.node.TREE_CODE()
|
|
|
|
|
|
|
|
# extern const enum tree_code_class tree_code_type[];
|
|
|
|
# #define TREE_CODE_CLASS(CODE) tree_code_type[(int) (CODE)]
|
|
|
|
|
|
|
|
val_tree_code_type = gdb.parse_and_eval('tree_code_type')
|
|
|
|
val_tclass = val_tree_code_type[val_TREE_CODE]
|
|
|
|
|
|
|
|
val_tree_code_name = gdb.parse_and_eval('tree_code_name')
|
2015-06-08 15:35:51 +02:00
|
|
|
val_code_name = val_tree_code_name[intptr(val_TREE_CODE)]
|
2015-06-02 09:37:22 +02:00
|
|
|
#print(val_code_name.string())
|
2013-08-28 05:01:20 +02:00
|
|
|
|
2015-06-08 15:35:51 +02:00
|
|
|
result = '<%s 0x%x' % (val_code_name.string(), intptr(self.gdbval))
|
|
|
|
if intptr(val_tclass) == tcc_declaration:
|
2013-08-28 05:01:20 +02:00
|
|
|
tree_DECL_NAME = self.node.DECL_NAME()
|
|
|
|
if tree_DECL_NAME.is_nonnull():
|
|
|
|
result += ' %s' % tree_DECL_NAME.IDENTIFIER_POINTER()
|
|
|
|
else:
|
|
|
|
pass # TODO: labels etc
|
2015-06-08 15:35:51 +02:00
|
|
|
elif intptr(val_tclass) == tcc_type:
|
2013-08-28 05:01:20 +02:00
|
|
|
tree_TYPE_NAME = Tree(self.gdbval['type_common']['name'])
|
|
|
|
if tree_TYPE_NAME.is_nonnull():
|
|
|
|
if tree_TYPE_NAME.TREE_CODE() == IDENTIFIER_NODE:
|
|
|
|
result += ' %s' % tree_TYPE_NAME.IDENTIFIER_POINTER()
|
|
|
|
elif tree_TYPE_NAME.TREE_CODE() == TYPE_DECL:
|
|
|
|
if tree_TYPE_NAME.DECL_NAME().is_nonnull():
|
|
|
|
result += ' %s' % tree_TYPE_NAME.DECL_NAME().IDENTIFIER_POINTER()
|
|
|
|
if self.node.TREE_CODE() == IDENTIFIER_NODE:
|
|
|
|
result += ' %s' % self.node.IDENTIFIER_POINTER()
|
|
|
|
# etc
|
|
|
|
result += '>'
|
|
|
|
return result
|
|
|
|
|
|
|
|
######################################################################
|
|
|
|
# Callgraph pretty-printers
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
class CGraphNodePrinter:
|
|
|
|
def __init__(self, gdbval):
|
|
|
|
self.gdbval = gdbval
|
|
|
|
|
|
|
|
def to_string (self):
|
2015-06-08 15:35:51 +02:00
|
|
|
result = '<cgraph_node* 0x%x' % intptr(self.gdbval)
|
|
|
|
if intptr(self.gdbval):
|
2013-11-18 13:18:12 +01:00
|
|
|
# symtab_node::name calls lang_hooks.decl_printable_name
|
2013-08-28 05:01:20 +02:00
|
|
|
# default implementation (lhd_decl_printable_name) is:
|
|
|
|
# return IDENTIFIER_POINTER (DECL_NAME (decl));
|
2013-10-29 19:58:42 +01:00
|
|
|
tree_decl = Tree(self.gdbval['decl'])
|
2013-08-28 05:01:20 +02:00
|
|
|
result += ' "%s"' % tree_decl.DECL_NAME().IDENTIFIER_POINTER()
|
|
|
|
result += '>'
|
|
|
|
return result
|
|
|
|
|
2014-12-11 00:16:42 +01:00
|
|
|
######################################################################
|
|
|
|
# Dwarf DIE pretty-printers
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
class DWDieRefPrinter:
|
|
|
|
def __init__(self, gdbval):
|
|
|
|
self.gdbval = gdbval
|
|
|
|
|
|
|
|
def to_string (self):
|
2015-06-08 15:35:51 +02:00
|
|
|
if intptr(self.gdbval) == 0:
|
2014-12-11 00:16:42 +01:00
|
|
|
return '<dw_die_ref 0x0>'
|
2015-06-08 15:35:51 +02:00
|
|
|
result = '<dw_die_ref 0x%x' % intptr(self.gdbval)
|
2014-12-11 00:16:42 +01:00
|
|
|
result += ' %s' % self.gdbval['die_tag']
|
2015-06-08 15:35:51 +02:00
|
|
|
if intptr(self.gdbval['die_parent']) != 0:
|
|
|
|
result += ' <parent=0x%x %s>' % (intptr(self.gdbval['die_parent']),
|
2014-12-11 00:16:42 +01:00
|
|
|
self.gdbval['die_parent']['die_tag'])
|
|
|
|
|
|
|
|
result += '>'
|
|
|
|
return result
|
|
|
|
|
2013-08-28 05:01:20 +02:00
|
|
|
######################################################################
|
|
|
|
|
|
|
|
class GimplePrinter:
|
|
|
|
def __init__(self, gdbval):
|
|
|
|
self.gdbval = gdbval
|
|
|
|
|
|
|
|
def to_string (self):
|
2015-06-08 15:35:51 +02:00
|
|
|
if intptr(self.gdbval) == 0:
|
2013-08-28 05:01:20 +02:00
|
|
|
return '<gimple 0x0>'
|
Convert gimple types from a union to C++ inheritance
Patch partially autogenerated by refactor_gimple.py from
https://github.com/davidmalcolm/gcc-refactoring-scripts
revision 05fc808c61bd8ddd2372f29b79ceb2491360d298
* Makefile.in (GIMPLE_H): Add dep on is-a.h.
* coretypes.h (union gimple_statement_d): Remove declaration.
(gimple): Convert from being a "union gimple_statement_d *"
to a "struct gimple_statement_base *".
(const_gimple): Likewise (with "const").
* ggc.h (ggc_alloc_cleared_gimple_statement_d_stat): Replace
with...
(ggc_alloc_cleared_gimple_statement_stat): ...this.
* gimple-pretty-print.c (debug): Change parameter from a
"gimple_statement_d &" to a "gimple_statement_base &".
(debug): Change parameter from a "gimple_statement_d *" to
a "gimple_statement_base *".
* gimple-pretty-print.h (debug): Update declarations as above.
* gimple.c (gimple_alloc_stat): Update for renaming of
ggc_alloc_cleared_gimple_statement_d_stat to
ggc_alloc_cleared_gimple_statement_stat.
* gimple.h: Include "is-a.h" for use by is_a_helper
specializations in followup autogenerated patch.
(struct gimple statement_base): Make this type usable as a base
class by adding "desc", "tag" and "variable_size" to GTY, thus
using opting-in to gengtype's support for simple inheritance.
(gimple_statement_with_ops_base): Convert to a subclass of
gimple_statement_base, dropping initial "gsbase" field. Note
that this type is abstract, with no GSS_ value, and thus no GTY
tag value.
(gimple_statement_with_ops): Convert to a subclass of
gimple_statement_with_ops_base, dropping initial "opbase" field.
Add tag value to GTY marking. Update marking of op field to
reflect how num_ops field is accessed via inheritance.
(gimple_statement_with_memory_ops_base): Convert to a subclass of
gimple_statement_with_ops_base, dropping initial "opbase" field.
Add tag value to GTY marking.
(gimple_statement_with_memory_ops): Convert to a subclass of
public gimple_statement_with_memory_ops_base, dropping initial
"membase" field. Add tag value to GTY marking. Update marking
of op field to reflect how num_ops field is accessed via
inheritance.
(gimple_statement_call): Analogous changes that also update the
marking of the "u" union.
(gimple_statement_omp): Convert to a subclass of
gimple_statement_base, dropping initial "gsbase" field, adding
tag value to GTY marking.
(gimple_statement_bind): Likewise.
(gimple_statement_catch): Likewise.
(gimple_statement_eh_filter): Likewise.
(gimple_statement_eh_else): Likewise.
(gimple_statement_eh_mnt): Likewise.
(gimple_statement_phi): Likewise.
(gimple_statement_eh_ctrl): Likewise.
(gimple_statement_try): Likewise.
(gimple_statement_wce): Likewise.
(gimple_statement_asm): Convert to a subclass of
gimple_statement_with_memory_ops_base, dropping initial
"membase" field, adding tag value to GTY marking, and updating
marking of op field.
(gimple_statement_omp_critical): Convert to a subclass of
gimple_statement_omp, dropping initial "omp" field, adding tag
value to GTY marking.
(gimple_statement_omp_for): Likewise.
(gimple_statement_omp_parallel): Likewise.
(gimple_statement_omp_task): Convert to a subclass of
gimple_statement_omp_parallel, dropping initial "par" field,
adding tag value to GTY marking.
(gimple_statement_omp_sections): Convert to a subclass of
gimple_statement_omp, dropping initial "omp" field, adding
tag value to GTY marking.
(gimple_statement_omp_continue): Convert to a subclass of
gimple_statement_base, dropping initial "gsbase" field, adding
tag value to GTY marking.
(gimple_statement_omp_single): Convert to a subclass of
gimple_statement_omp, dropping initial "omp" field, adding
tag value to GTY marking.
(gimple_statement_omp_atomic_load): Convert to a subclass of
gimple_statement_base, dropping initial "gsbase" field, adding
tag value to GTY marking.
(gimple_statement_omp_atomic_store): Convert to a subclass of
gimple_statement_base, dropping initial "gsbase" field, adding
tag value to GTY marking.
(gimple_statement_transaction): Convert to a subclass of
gimple_statement_with_memory_ops_base, dropping initial "gsbase"
field, adding tag value to GTY marking.
(union gimple_statement_d): Remove.
* system.h (CONST_CAST_GIMPLE): Update to use
"struct gimple_statement_base *" rather than
"union gimple_statement_d *".
* tree-ssa-ccp.c (gimple_htab): Convert underlying type from
gimple_statement_d to gimple_statement_base.
* gimple.h (gimple_use_ops): Port from union to usage of
dyn_cast.
(gimple_set_use_ops): Port from union to usage of as_a.
(gimple_set_vuse): Likewise.
(gimple_set_vdef): Likewise.
(gimple_call_internal_fn): Port from union to a static_cast,
given that the type has already been asserted.
(gimple_omp_body_ptr): Port from unchecked union usage to
a static_cast.
(gimple_omp_set_body): Likewise.
* gimple-iterator.c (update_bb_for_stmts): Update for conversion of
gimple types to a true class hierarchy.
(update_call_edge_frequencies): Likewise.
(gsi_insert_seq_nodes_before): Likewise.
(gsi_insert_seq_nodes_after): Likewise.
(gsi_split_seq_after): Likewise.
(gsi_set_stmt): Likewise.
(gsi_split_seq_before): Likewise.
(gsi_remove): Likewise.
* gimple-iterator.h (gsi_one_before_end_p): Likewise.
(gsi_next): Likewise.
(gsi_prev): Likewise.
* gimple-pretty-print.c (dump_gimple_debug): Likewise.
* gimple-ssa.h (gimple_vuse_op): Likewise.
(gimple_vdef_op): Likewise.
* gimple-streamer-in.c (input_gimple_stmt): Likewise.
* gimple-streamer-out.c (output_gimple_stmt): Likewise.
* gimple.c (gimple_set_code): Likewise.
(gimple_alloc_stat): Likewise.
(gimple_set_subcode): Likewise.
(gimple_build_call_internal_1): Likewise.
(gimple_check_failed): Likewise.
(gimple_call_flags): Likewise.
(gimple_set_bb): Likewise.
* gimple.h (is_a_helper <gimple_statement_asm> (gimple)): New.
(is_a_helper <gimple_statement_bind> (gimple)): Likewise.
(is_a_helper <gimple_statement_call> (gimple)): Likewise.
(is_a_helper <gimple_statement_catch> (gimple)): Likewise.
(is_a_helper <gimple_statement_eh_ctrl> (gimple)): Likewise.
(is_a_helper <gimple_statement_eh_else> (gimple)): Likewise.
(is_a_helper <gimple_statement_eh_filter> (gimple)): Likewise.
(is_a_helper <gimple_statement_eh_mnt> (gimple)): Likewise.
(is_a_helper <gimple_statement_omp_atomic_load> (gimple)): Likewise.
(is_a_helper <gimple_statement_omp_atomic_store> (gimple)): Likewise.
(is_a_helper <gimple_statement_omp_continue> (gimple)): Likewise.
(is_a_helper <gimple_statement_omp_critical> (gimple)): Likewise.
(is_a_helper <gimple_statement_omp_for> (gimple)): Likewise.
(is_a_helper <gimple_statement_omp_parallel> (gimple)): Likewise.
(is_a_helper <gimple_statement_omp_sections> (gimple)): Likewise.
(is_a_helper <gimple_statement_omp_single> (gimple)): Likewise.
(is_a_helper <gimple_statement_omp_task> (gimple)): Likewise.
(is_a_helper <gimple_statement_phi> (gimple)): Likewise.
(is_a_helper <gimple_statement_transaction> (gimple)): Likewise.
(is_a_helper <gimple_statement_try> (gimple)): Likewise.
(is_a_helper <gimple_statement_wce> (gimple)): Likewise.
(is_a_helper <const gimple_statement_asm> (const_gimple)): Likewise.
(is_a_helper <const gimple_statement_bind> (const_gimple)): Likewise.
(is_a_helper <const gimple_statement_call> (const_gimple)): Likewise.
(is_a_helper <const gimple_statement_catch> (const_gimple)): Likewise.
(is_a_helper <const gimple_statement_eh_ctrl> (const_gimple)):
Likewise.
(is_a_helper <const gimple_statement_eh_filter> (const_gimple)):
Likewise.
(is_a_helper <const gimple_statement_omp_atomic_load> (const_gimple)):
Likewise.
(is_a_helper <const gimple_statement_omp_atomic_store>
(const_gimple)): Likewise.
(is_a_helper <const gimple_statement_omp_continue> (const_gimple)):
Likewise.
(is_a_helper <const gimple_statement_omp_critical> (const_gimple)):
Likewise.
(is_a_helper <const gimple_statement_omp_for> (const_gimple)):
Likewise.
(is_a_helper <const gimple_statement_omp_parallel> (const_gimple)):
Likewise.
(is_a_helper <const gimple_statement_omp_sections> (const_gimple)):
Likewise.
(is_a_helper <const gimple_statement_omp_single> (const_gimple)):
Likewise.
(is_a_helper <const gimple_statement_omp_task> (const_gimple)):
Likewise.
(is_a_helper <const gimple_statement_phi> (const_gimple)): Likewise.
(is_a_helper <const gimple_statement_transaction> (const_gimple)):
Likewise.
(gimple_seq_last): Update for conversion of gimple types to a true
class hierarchy.
(gimple_seq_set_last): Likewise.
(gimple_code): Likewise.
(gimple_bb): Likewise.
(gimple_block): Likewise.
(gimple_set_block): Likewise.
(gimple_location): Likewise.
(gimple_location_ptr): Likewise.
(gimple_set_location): Likewise.
(gimple_no_warning_p): Likewise.
(gimple_set_no_warning): Likewise.
(gimple_set_visited): Likewise.
(gimple_visited_p): Likewise.
(gimple_set_plf): Likewise.
(gimple_plf): Likewise.
(gimple_set_uid): Likewise.
(gimple_uid): Likewise.
(gimple_init_singleton): Likewise.
(gimple_modified_p): Likewise.
(gimple_set_modified): Likewise.
(gimple_expr_code): Likewise.
(gimple_has_volatile_ops): Likewise.
(gimple_set_has_volatile_ops): Likewise.
(gimple_omp_subcode): Likewise.
(gimple_omp_set_subcode): Likewise.
(gimple_omp_return_set_nowait): Likewise.
(gimple_omp_section_set_last): Likewise.
(gimple_omp_parallel_set_combined_p): Likewise.
(gimple_omp_atomic_set_need_value): Likewise.
(gimple_omp_atomic_set_seq_cst): Likewise.
(gimple_num_ops): Likewise.
(gimple_set_num_ops): Likewise.
(gimple_assign_nontemporal_move_p): Likewise.
(gimple_assign_set_nontemporal_move): Likewise.
(gimple_assign_rhs_code): Likewise.
(gimple_assign_set_rhs_code): Likewise.
(gimple_call_internal_p): Likewise.
(gimple_call_with_bounds_p): Likewise.
(gimple_call_set_with_bounds): Likewise.
(gimple_call_set_tail): Likewise.
(gimple_call_tail_p): Likewise.
(gimple_call_set_return_slot_opt): Likewise.
(gimple_call_return_slot_opt_p): Likewise.
(gimple_call_set_from_thunk): Likewise.
(gimple_call_from_thunk_p): Likewise.
(gimple_call_set_va_arg_pack): Likewise.
(gimple_call_va_arg_pack_p): Likewise.
(gimple_call_set_nothrow): Likewise.
(gimple_call_set_alloca_for_var): Likewise.
(gimple_call_alloca_for_var_p): Likewise.
(gimple_call_copy_flags): Likewise.
(gimple_cond_code): Likewise.
(gimple_cond_set_code): Likewise.
(gimple_cond_make_false): Likewise.
(gimple_cond_make_true): Likewise.
(gimple_asm_volatile_p): Likewise.
(gimple_asm_set_volatile): Likewise.
(gimple_asm_set_input): Likewise.
(gimple_asm_input_p): Likewise.
(gimple_try_kind): Likewise.
(gimple_try_set_kind): Likewise.
(gimple_try_catch_is_cleanup): Likewise.
(gimple_try_set_catch_is_cleanup): Likewise.
(gimple_wce_cleanup_eh_only): Likewise.
(gimple_wce_set_cleanup_eh_only): Likewise.
(gimple_debug_bind_p): Likewise.
(gimple_debug_source_bind_p): Likewise.
(gimple_omp_for_set_kind): Likewise.
(gimple_omp_for_set_combined_p): Likewise.
(gimple_omp_for_set_combined_into_p): Likewise.
(gimple_omp_target_set_kind): Likewise.
(gimple_transaction_subcode): Likewise.
(gimple_transaction_set_subcode): Likewise.
(gimple_predict_predictor): Likewise.
(gimple_predict_set_predictor): Likewise.
(gimple_predict_outcome): Likewise.
(gimple_predict_set_outcome): Likewise.
(gimple_transaction_set_label): Likewise.
(gimple_transaction_set_body): Likewise.
(gimple_transaction_label_ptr): Likewise.
(gimple_transaction_label): Likewise.
(gimple_transaction_body_ptr): Likewise.
(gimple_omp_continue_set_control_use): Likewise.
(gimple_omp_continue_control_use_ptr): Likewise.
(gimple_omp_continue_control_use): Likewise.
(gimple_omp_continue_set_control_def): Likewise.
(gimple_omp_continue_control_def_ptr): Likewise.
(gimple_omp_continue_control_def): Likewise.
(gimple_omp_atomic_load_rhs_ptr): Likewise.
(gimple_omp_atomic_load_rhs): Likewise.
(gimple_omp_atomic_load_set_rhs): Likewise.
(gimple_omp_atomic_load_lhs_ptr): Likewise.
(gimple_omp_atomic_load_lhs): Likewise.
(gimple_omp_atomic_load_set_lhs): Likewise.
(gimple_omp_atomic_store_val_ptr): Likewise.
(gimple_omp_atomic_store_val): Likewise.
(gimple_omp_atomic_store_set_val): Likewise.
(gimple_omp_for_cond): Likewise.
(gimple_omp_for_set_cond): Likewise.
(gimple_omp_sections_set_control): Likewise.
(gimple_omp_sections_control_ptr): Likewise.
(gimple_omp_sections_control): Likewise.
(gimple_omp_sections_set_clauses): Likewise.
(gimple_omp_sections_clauses_ptr): Likewise.
(gimple_omp_sections_clauses): Likewise.
(gimple_omp_teams_set_clauses): Likewise.
(gimple_omp_teams_clauses_ptr): Likewise.
(gimple_omp_teams_clauses): Likewise.
(gimple_omp_target_set_data_arg): Likewise.
(gimple_omp_target_data_arg_ptr): Likewise.
(gimple_omp_target_data_arg): Likewise.
(gimple_omp_target_set_child_fn): Likewise.
(gimple_omp_target_child_fn_ptr): Likewise.
(gimple_omp_target_child_fn): Likewise.
(gimple_omp_target_set_clauses): Likewise.
(gimple_omp_target_clauses_ptr): Likewise.
(gimple_omp_target_clauses): Likewise.
(gimple_omp_single_set_clauses): Likewise.
(gimple_omp_single_clauses_ptr): Likewise.
(gimple_omp_single_clauses): Likewise.
(gimple_omp_task_set_arg_align): Likewise.
(gimple_omp_task_arg_align_ptr): Likewise.
(gimple_omp_task_arg_align): Likewise.
(gimple_omp_task_set_arg_size): Likewise.
(gimple_omp_task_arg_size_ptr): Likewise.
(gimple_omp_task_arg_size): Likewise.
(gimple_omp_task_set_copy_fn): Likewise.
(gimple_omp_task_copy_fn_ptr): Likewise.
(gimple_omp_task_copy_fn): Likewise.
(gimple_omp_task_set_data_arg): Likewise.
(gimple_omp_task_data_arg_ptr): Likewise.
(gimple_omp_task_data_arg): Likewise.
(gimple_omp_task_set_child_fn): Likewise.
(gimple_omp_task_child_fn_ptr): Likewise.
(gimple_omp_task_child_fn): Likewise.
(gimple_omp_task_set_clauses): Likewise.
(gimple_omp_task_clauses_ptr): Likewise.
(gimple_omp_task_clauses): Likewise.
(gimple_omp_parallel_set_data_arg): Likewise.
(gimple_omp_parallel_data_arg_ptr): Likewise.
(gimple_omp_parallel_data_arg): Likewise.
(gimple_omp_parallel_set_child_fn): Likewise.
(gimple_omp_parallel_child_fn_ptr): Likewise.
(gimple_omp_parallel_child_fn): Likewise.
(gimple_omp_parallel_set_clauses): Likewise.
(gimple_omp_parallel_clauses_ptr): Likewise.
(gimple_omp_parallel_clauses): Likewise.
(gimple_omp_for_set_pre_body): Likewise.
(gimple_omp_for_pre_body_ptr): Likewise.
(gimple_omp_for_set_incr): Likewise.
(gimple_omp_for_incr_ptr): Likewise.
(gimple_omp_for_incr): Likewise.
(gimple_omp_for_set_final): Likewise.
(gimple_omp_for_final_ptr): Likewise.
(gimple_omp_for_final): Likewise.
(gimple_omp_for_set_initial): Likewise.
(gimple_omp_for_initial_ptr): Likewise.
(gimple_omp_for_initial): Likewise.
(gimple_omp_for_set_index): Likewise.
(gimple_omp_for_index_ptr): Likewise.
(gimple_omp_for_index): Likewise.
(gimple_omp_for_collapse): Likewise.
(gimple_omp_for_set_clauses): Likewise.
(gimple_omp_for_clauses_ptr): Likewise.
(gimple_omp_for_clauses): Likewise.
(gimple_omp_critical_set_name): Likewise.
(gimple_omp_critical_name_ptr): Likewise.
(gimple_omp_critical_name): Likewise.
(gimple_eh_dispatch_set_region): Likewise.
(gimple_eh_dispatch_region): Likewise.
(gimple_resx_set_region): Likewise.
(gimple_resx_region): Likewise.
(gimple_phi_set_arg): Likewise.
(gimple_phi_arg): Likewise.
(gimple_phi_set_result): Likewise.
(gimple_phi_result_ptr): Likewise.
(gimple_phi_result): Likewise.
(gimple_phi_num_args): Likewise.
(gimple_phi_capacity): Likewise.
(gimple_wce_set_cleanup): Likewise.
(gimple_wce_cleanup_ptr): Likewise.
(gimple_try_set_cleanup): Likewise.
(gimple_try_set_eval): Likewise.
(gimple_try_cleanup_ptr): Likewise.
(gimple_try_eval_ptr): Likewise.
(gimple_eh_else_set_e_body): Likewise.
(gimple_eh_else_set_n_body): Likewise.
(gimple_eh_else_e_body_ptr): Likewise.
(gimple_eh_else_n_body_ptr): Likewise.
(gimple_eh_must_not_throw_set_fndecl): Likewise.
(gimple_eh_must_not_throw_fndecl): Likewise.
(gimple_eh_filter_set_failure): Likewise.
(gimple_eh_filter_set_types): Likewise.
(gimple_eh_filter_failure_ptr): Likewise.
(gimple_eh_filter_types_ptr): Likewise.
(gimple_eh_filter_types): Likewise.
(gimple_catch_set_handler): Likewise.
(gimple_catch_set_types): Likewise.
(gimple_catch_handler_ptr): Likewise.
(gimple_catch_types_ptr): Likewise.
(gimple_catch_types): Likewise.
(gimple_asm_string): Likewise.
(gimple_asm_set_label_op): Likewise.
(gimple_asm_label_op): Likewise.
(gimple_asm_set_clobber_op): Likewise.
(gimple_asm_clobber_op): Likewise.
(gimple_asm_set_output_op): Likewise.
(gimple_asm_output_op_ptr): Likewise.
(gimple_asm_output_op): Likewise.
(gimple_asm_set_input_op): Likewise.
(gimple_asm_input_op_ptr): Likewise.
(gimple_asm_input_op): Likewise.
(gimple_asm_nlabels): Likewise.
(gimple_asm_nclobbers): Likewise.
(gimple_asm_noutputs): Likewise.
(gimple_asm_ninputs): Likewise.
(gimple_bind_set_block): Likewise.
(gimple_bind_block): Likewise.
(gimple_bind_add_seq): Likewise.
(gimple_bind_add_stmt): Likewise.
(gimple_bind_set_body): Likewise.
(gimple_bind_body_ptr): Likewise.
(gimple_bind_append_vars): Likewise.
(gimple_bind_set_vars): Likewise.
(gimple_bind_vars): Likewise.
(gimple_call_clobber_set): Likewise.
(gimple_call_use_set): Likewise.
(gimple_call_set_internal_fn): Likewise.
(gimple_call_set_fntype): Likewise.
(gimple_call_fntype): Likewise.
(gimple_omp_return_lhs_ptr): Likewise.
(gimple_omp_return_lhs): Likewise.
(gimple_omp_return_set_lhs): Likewise.
(gimple_omp_taskreg_set_data_arg): Likewise.
(gimple_omp_taskreg_data_arg_ptr): Likewise.
(gimple_omp_taskreg_data_arg): Likewise.
(gimple_omp_taskreg_set_child_fn): Likewise.
(gimple_omp_taskreg_child_fn_ptr): Likewise.
(gimple_omp_taskreg_child_fn): Likewise.
(gimple_omp_taskreg_set_clauses): Likewise.
(gimple_omp_taskreg_clauses_ptr): Likewise.
(gimple_omp_taskreg_clauses): Likewise.
(gimple_vuse): Likewise.
(gimple_vdef): Likewise.
(gimple_vuse_ptr): Likewise.
(gimple_vdef_ptr): Likewise.
* tree-inline.c (copy_debug_stmt): Likewise.
* tree-phinodes.c (make_phi_node): Likewise.
* gimple.h (is_a_helper <const gimple_statement_with_ops>::test): New.
(is_a_helper <gimple_statement_with_ops>::test): New.
(is_a_helper <const gimple_statement_with_memory_ops>::test): New.
(is_a_helper <gimple_statement_with_memory_ops>::test): New.
* gimple-streamer-in.c (input_gimple_stmt): Port from union
access to use of as_a.
* gimple.c (gimple_build_asm_1): Likewise.
(gimple_build_try): Likewise. Also, return a specific subclass
rather than just gimple.
(gimple_build_resx): Port from union access to use of as_a.
(gimple_build_eh_dispatch): Likewise.
(gimple_build_omp_for): Likewise. Also, convert allocation of iter
now that gengtype no longer provides a typed allocator function.
(gimple_copy): Likewise.
* gimple.h (gimple_build_try): Return a specific subclass rather
than just gimple.
* gimplify.c (gimplify_cleanup_point_expr): Replace union access
with subclass access by making use of new return type of
gimple_build_try.
* tree-phinodes.c: (allocate_phi_node): Return a
"gimple_statement_phi *" rather than just a gimple.
(resize_phi_node): Likewise.
(make_phi_node): Replace union access with subclass access by
making use of new return type of allocate_phi_node.
(reserve_phi_args_for_new_edge): Replace union access with as_a.
(remove_phi_arg_num): Accept a "gimple_statement_phi *" rather
than just a gimple.
(remove_phi_args): Update for change to remove_phi_arg_num.
* gdbhooks.py (GimplePrinter.to_string): Update lookup of
code field to reflect inheritance, rather than embedding of
the base gimple type.
From-SVN: r205034
2013-11-19 16:50:46 +01:00
|
|
|
val_gimple_code = self.gdbval['code']
|
2013-08-28 05:01:20 +02:00
|
|
|
val_gimple_code_name = gdb.parse_and_eval('gimple_code_name')
|
2015-06-08 15:35:51 +02:00
|
|
|
val_code_name = val_gimple_code_name[intptr(val_gimple_code)]
|
2013-08-28 05:01:20 +02:00
|
|
|
result = '<%s 0x%x' % (val_code_name.string(),
|
2015-06-08 15:35:51 +02:00
|
|
|
intptr(self.gdbval))
|
2013-08-28 05:01:20 +02:00
|
|
|
result += '>'
|
|
|
|
return result
|
|
|
|
|
|
|
|
######################################################################
|
|
|
|
# CFG pretty-printers
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
def bb_index_to_str(index):
|
|
|
|
if index == 0:
|
|
|
|
return 'ENTRY'
|
|
|
|
elif index == 1:
|
|
|
|
return 'EXIT'
|
|
|
|
else:
|
|
|
|
return '%i' % index
|
|
|
|
|
|
|
|
class BasicBlockPrinter:
|
|
|
|
def __init__(self, gdbval):
|
|
|
|
self.gdbval = gdbval
|
|
|
|
|
|
|
|
def to_string (self):
|
2015-06-08 15:35:51 +02:00
|
|
|
result = '<basic_block 0x%x' % intptr(self.gdbval)
|
|
|
|
if intptr(self.gdbval):
|
|
|
|
result += ' (%s)' % bb_index_to_str(intptr(self.gdbval['index']))
|
2013-08-28 05:01:20 +02:00
|
|
|
result += '>'
|
|
|
|
return result
|
|
|
|
|
|
|
|
class CfgEdgePrinter:
|
|
|
|
def __init__(self, gdbval):
|
|
|
|
self.gdbval = gdbval
|
|
|
|
|
|
|
|
def to_string (self):
|
2015-06-08 15:35:51 +02:00
|
|
|
result = '<edge 0x%x' % intptr(self.gdbval)
|
|
|
|
if intptr(self.gdbval):
|
|
|
|
src = bb_index_to_str(intptr(self.gdbval['src']['index']))
|
|
|
|
dest = bb_index_to_str(intptr(self.gdbval['dest']['index']))
|
2013-08-28 05:01:20 +02:00
|
|
|
result += ' (%s -> %s)' % (src, dest)
|
|
|
|
result += '>'
|
|
|
|
return result
|
|
|
|
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
class Rtx:
|
|
|
|
def __init__(self, gdbval):
|
|
|
|
self.gdbval = gdbval
|
|
|
|
|
|
|
|
def GET_CODE(self):
|
|
|
|
return self.gdbval['code']
|
|
|
|
|
|
|
|
def GET_RTX_LENGTH(code):
|
|
|
|
val_rtx_length = gdb.parse_and_eval('rtx_length')
|
2015-06-08 15:35:51 +02:00
|
|
|
return intptr(val_rtx_length[code])
|
2013-08-28 05:01:20 +02:00
|
|
|
|
|
|
|
def GET_RTX_NAME(code):
|
|
|
|
val_rtx_name = gdb.parse_and_eval('rtx_name')
|
|
|
|
return val_rtx_name[code].string()
|
|
|
|
|
|
|
|
def GET_RTX_FORMAT(code):
|
|
|
|
val_rtx_format = gdb.parse_and_eval('rtx_format')
|
|
|
|
return val_rtx_format[code].string()
|
|
|
|
|
|
|
|
class RtxPrinter:
|
|
|
|
def __init__(self, gdbval):
|
|
|
|
self.gdbval = gdbval
|
|
|
|
self.rtx = Rtx(gdbval)
|
|
|
|
|
|
|
|
def to_string (self):
|
|
|
|
"""
|
|
|
|
For now, a cheap kludge: invoke the inferior's print
|
|
|
|
function to get a string to use the user, and return an empty
|
|
|
|
string for gdb
|
|
|
|
"""
|
|
|
|
# We use print_inline_rtx to avoid a trailing newline
|
|
|
|
gdb.execute('call print_inline_rtx (stderr, (const_rtx) %s, 0)'
|
2015-06-08 15:35:51 +02:00
|
|
|
% intptr(self.gdbval))
|
2013-08-28 05:01:20 +02:00
|
|
|
return ''
|
|
|
|
|
|
|
|
# or by hand; based on gcc/print-rtl.c:print_rtx
|
|
|
|
result = ('<rtx_def 0x%x'
|
2015-06-08 15:35:51 +02:00
|
|
|
% (intptr(self.gdbval)))
|
2013-08-28 05:01:20 +02:00
|
|
|
code = self.rtx.GET_CODE()
|
|
|
|
result += ' (%s' % GET_RTX_NAME(code)
|
|
|
|
format_ = GET_RTX_FORMAT(code)
|
|
|
|
for i in range(GET_RTX_LENGTH(code)):
|
2015-06-02 09:37:22 +02:00
|
|
|
print(format_[i])
|
2013-08-28 05:01:20 +02:00
|
|
|
result += ')>'
|
|
|
|
return result
|
|
|
|
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
class PassPrinter:
|
|
|
|
def __init__(self, gdbval):
|
|
|
|
self.gdbval = gdbval
|
|
|
|
|
|
|
|
def to_string (self):
|
2015-06-08 15:35:51 +02:00
|
|
|
result = '<opt_pass* 0x%x' % intptr(self.gdbval)
|
|
|
|
if intptr(self.gdbval):
|
2013-08-28 05:01:20 +02:00
|
|
|
result += (' "%s"(%i)'
|
|
|
|
% (self.gdbval['name'].string(),
|
2015-06-08 15:35:51 +02:00
|
|
|
intptr(self.gdbval['static_pass_number'])))
|
2013-08-28 05:01:20 +02:00
|
|
|
result += '>'
|
|
|
|
return result
|
|
|
|
|
|
|
|
######################################################################
|
|
|
|
|
2013-11-20 04:57:35 +01:00
|
|
|
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.
|
2015-06-08 15:35:51 +02:00
|
|
|
return '0x%x' % intptr(self.gdbval)
|
2013-11-20 04:57:35 +01:00
|
|
|
|
|
|
|
def children (self):
|
2015-06-08 15:35:51 +02:00
|
|
|
if intptr(self.gdbval) == 0:
|
2013-11-20 21:00:33 +01:00
|
|
|
return
|
2013-11-20 04:57:35 +01:00
|
|
|
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])
|
|
|
|
|
|
|
|
######################################################################
|
|
|
|
|
2013-08-28 05:01:20 +02:00
|
|
|
# TODO:
|
|
|
|
# * hashtab
|
|
|
|
# * location_t
|
|
|
|
|
|
|
|
class GdbSubprinter(gdb.printing.SubPrettyPrinter):
|
2013-11-20 04:33:33 +01:00
|
|
|
def __init__(self, name, class_):
|
2013-08-28 05:01:20 +02:00
|
|
|
super(GdbSubprinter, self).__init__(name)
|
|
|
|
self.class_ = class_
|
|
|
|
|
2013-11-20 04:33:33 +01:00
|
|
|
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)
|
|
|
|
|
2013-08-28 05:01:20 +02:00
|
|
|
class GdbPrettyPrinters(gdb.printing.PrettyPrinter):
|
|
|
|
def __init__(self, name):
|
|
|
|
super(GdbPrettyPrinters, self).__init__(name, [])
|
|
|
|
|
2013-11-20 04:33:33 +01:00
|
|
|
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))
|
2013-08-28 05:01:20 +02:00
|
|
|
|
|
|
|
def __call__(self, gdbval):
|
|
|
|
type_ = gdbval.type.unqualified()
|
2013-11-20 04:33:33 +01:00
|
|
|
str_type = str(type_)
|
2013-08-28 05:01:20 +02:00
|
|
|
for printer in self.subprinters:
|
2013-11-20 04:33:33 +01:00
|
|
|
if printer.enabled and printer.handles_type(str_type):
|
2013-08-28 05:01:20 +02:00
|
|
|
return printer.class_(gdbval)
|
|
|
|
|
|
|
|
# Couldn't find a pretty printer (or it was disabled):
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def build_pretty_printer():
|
|
|
|
pp = GdbPrettyPrinters('gcc')
|
2013-11-20 04:33:33 +01:00
|
|
|
pp.add_printer_for_types(['tree'],
|
|
|
|
'tree', TreePrinter)
|
|
|
|
pp.add_printer_for_types(['cgraph_node *'],
|
|
|
|
'cgraph_node', CGraphNodePrinter)
|
2014-12-11 00:16:42 +01:00
|
|
|
pp.add_printer_for_types(['dw_die_ref'],
|
|
|
|
'dw_die_ref', DWDieRefPrinter)
|
2015-09-28 08:26:21 +02:00
|
|
|
pp.add_printer_for_types(['gimple', 'gimple *',
|
2014-11-19 18:00:54 +01:00
|
|
|
|
|
|
|
# Keep this in the same order as gimple.def:
|
|
|
|
'gimple_cond', 'const_gimple_cond',
|
|
|
|
'gimple_statement_cond *',
|
|
|
|
'gimple_debug', 'const_gimple_debug',
|
|
|
|
'gimple_statement_debug *',
|
|
|
|
'gimple_label', 'const_gimple_label',
|
|
|
|
'gimple_statement_label *',
|
|
|
|
'gimple_switch', 'const_gimple_switch',
|
|
|
|
'gimple_statement_switch *',
|
|
|
|
'gimple_assign', 'const_gimple_assign',
|
|
|
|
'gimple_statement_assign *',
|
|
|
|
'gimple_bind', 'const_gimple_bind',
|
|
|
|
'gimple_statement_bind *',
|
|
|
|
'gimple_phi', 'const_gimple_phi',
|
|
|
|
'gimple_statement_phi *'],
|
|
|
|
|
2013-11-20 04:33:33 +01:00
|
|
|
'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)
|
|
|
|
|
2013-11-20 04:57:35 +01:00
|
|
|
pp.add_printer_for_regex(r'vec<(\S+), (\S+), (\S+)> \*',
|
|
|
|
'vec',
|
|
|
|
VecPrinter)
|
|
|
|
|
2013-08-28 05:01:20 +02:00
|
|
|
return pp
|
|
|
|
|
|
|
|
gdb.printing.register_pretty_printer(
|
|
|
|
gdb.current_objfile(),
|
|
|
|
build_pretty_printer())
|
|
|
|
|
2014-08-05 23:01:47 +02:00
|
|
|
def find_gcc_source_dir():
|
|
|
|
# Use location of global "g" to locate the source tree
|
|
|
|
sym_g = gdb.lookup_global_symbol('g')
|
|
|
|
path = sym_g.symtab.filename # e.g. '../../src/gcc/context.h'
|
|
|
|
srcdir = os.path.split(path)[0] # e.g. '../../src/gcc'
|
|
|
|
return srcdir
|
|
|
|
|
|
|
|
class PassNames:
|
|
|
|
"""Parse passes.def, gathering a list of pass class names"""
|
|
|
|
def __init__(self):
|
|
|
|
srcdir = find_gcc_source_dir()
|
|
|
|
self.names = []
|
|
|
|
with open(os.path.join(srcdir, 'passes.def')) as f:
|
|
|
|
for line in f:
|
2015-11-16 13:40:05 +01:00
|
|
|
m = re.match('\s*NEXT_PASS \(([^,]+).*\);', line)
|
2014-08-05 23:01:47 +02:00
|
|
|
if m:
|
|
|
|
self.names.append(m.group(1))
|
|
|
|
|
|
|
|
class BreakOnPass(gdb.Command):
|
|
|
|
"""
|
|
|
|
A custom command for putting breakpoints on the execute hook of passes.
|
|
|
|
This is largely a workaround for issues with tab-completion in gdb when
|
|
|
|
setting breakpoints on methods on classes within anonymous namespaces.
|
|
|
|
|
|
|
|
Example of use: putting a breakpoint on "final"
|
|
|
|
(gdb) break-on-pass
|
|
|
|
Press <TAB>; it autocompletes to "pass_":
|
|
|
|
(gdb) break-on-pass pass_
|
|
|
|
Press <TAB>:
|
|
|
|
Display all 219 possibilities? (y or n)
|
|
|
|
Press "n"; then type "f":
|
|
|
|
(gdb) break-on-pass pass_f
|
|
|
|
Press <TAB> to autocomplete to pass classnames beginning with "pass_f":
|
|
|
|
pass_fast_rtl_dce pass_fold_builtins
|
|
|
|
pass_feedback_split_functions pass_forwprop
|
|
|
|
pass_final pass_fre
|
|
|
|
pass_fixup_cfg pass_free_cfg
|
|
|
|
Type "in<TAB>" to complete to "pass_final":
|
|
|
|
(gdb) break-on-pass pass_final
|
|
|
|
...and hit <RETURN>:
|
|
|
|
Breakpoint 6 at 0x8396ba: file ../../src/gcc/final.c, line 4526.
|
|
|
|
...and we have a breakpoint set; continue execution:
|
|
|
|
(gdb) cont
|
|
|
|
Continuing.
|
|
|
|
Breakpoint 6, (anonymous namespace)::pass_final::execute (this=0x17fb990) at ../../src/gcc/final.c:4526
|
|
|
|
4526 virtual unsigned int execute (function *) { return rest_of_handle_final (); }
|
|
|
|
"""
|
|
|
|
def __init__(self):
|
|
|
|
gdb.Command.__init__(self, 'break-on-pass', gdb.COMMAND_BREAKPOINTS)
|
|
|
|
self.pass_names = None
|
|
|
|
|
|
|
|
def complete(self, text, word):
|
|
|
|
# Lazily load pass names:
|
|
|
|
if not self.pass_names:
|
|
|
|
self.pass_names = PassNames()
|
|
|
|
|
|
|
|
return [name
|
|
|
|
for name in sorted(self.pass_names.names)
|
|
|
|
if name.startswith(text)]
|
|
|
|
|
|
|
|
def invoke(self, arg, from_tty):
|
|
|
|
sym = '(anonymous namespace)::%s::execute' % arg
|
|
|
|
breakpoint = gdb.Breakpoint(sym)
|
|
|
|
|
|
|
|
BreakOnPass()
|
|
|
|
|
2013-08-28 05:01:20 +02:00
|
|
|
print('Successfully loaded GDB hooks for GCC')
|