Skip to content

Latest commit

 

History

History
50 lines (31 loc) · 1.35 KB

README.md

File metadata and controls

50 lines (31 loc) · 1.35 KB

GCC internals - GDB scripts

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.

Install

Basically you need two things:

  1. Make the gcc package available to the Python that is embedded in GDB.
  2. Import this package and call gcc.setup().

Depending on your system, there are multiple ways of doing this.

  1. Either install the gcc package in the relevant Python, or add the containing directory to sys.path at runtime. For instance, in your .gdbinit:

    python import sys; sys.path.append("$DIR")
    
  2. Add the following to your .gdbinit file:

    python import gcc; gcc.setup()