This hosts GDB helpers Python scripts to make it easier to debug GCC. For instance, this should make it easy to:
-
print locations:
(gdb) p input_location $1 = f.adb:5:5
-
print trees:
(gdb) p current_function_decl $1 = <function_decl 0x7ffff6594500 f>
-
use Python expressions to process trees:
(gdb) pi [(str(v.code), v.name) for v in Tree('current_function_decl').decl_initial.block_vars] [('CONST_DECL', 'a'), ('VAR_DECL', 'a'), ('LABEL_DECL', None)]
-
easily match trees with specific codes/names:
(gdb) break gen_variable_die if $matchtree(decl, VAR_DECL, "a")
There are other helpers to deal with DIE nodes (in the DWARF back-end), CFG ones or IRA data structures.
Basically you need two things:
- Make the
gcc
package available to the Python that is embedded in GDB. - Import this package and call
gcc.setup()
.
Depending on your system, there are multiple ways of doing this.
-
Either install the
gcc
package in the relevant Python, or add the containing directory tosys.path
at runtime. For instance, in your.gdbinit
:python import sys; sys.path.append("$DIR")
-
Add the following to your
.gdbinit
file:python import gcc; gcc.setup()