This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GDB hooks for debugging GCC


>>>>> "David" == David Malcolm <dmalcolm@redhat.com> writes:

David> GDB 7.0 onwards supports hooks written in Python to improve the
David> quality-of-life within the debugger.  The best known are the
David> pretty-printing hooks [1], which we already use within libstdc++ for
David> printing better representations of STL containers.

Nice!

A few suggestions.

David>   (note how the rtx_def* is printed inline.  This last one is actually a
David> kludge; all the other pretty-printers work inside gdb, whereas this one
David> injects a call into print-rtl.c into the inferior).

Naughty.

David>   * it hardcoded values in a few places rather than correctly looking up
David> enums

If you have a new-enough gdb (I don't recall the exact version -- I can
look if you want, but recall that gcc changes mean that gcc developers
generally have to use a very recent gdb) you can use
gdb.types.make_enum_dict to get this very easily.

David> You may see a message from gdb of the form:
David>   cc1-gdb.py auto-loading has been declined by your `auto-load safe-path'
David> as a protection against untrustworthy python scripts.  See
David>   http://sourceware.org/gdb/onlinedocs/gdb/Auto_002dloading-safe-path.html

I think you could set up the safe-path in the gcc .gdbinit.

David> Note that you can suppress pretty-printers using /r (for "raw"):
David>   (gdb) p /r pass
David>   $3 = (opt_pass *) 0x188b600
David> and dereference the pointer in the normal way:
David>   (gdb) p *pass
David>   $4 = {type = RTL_PASS, name = 0x120a312 "expand",
David>   [etc, ...snipped...]

I just wanted to clarify here that you can "p *pass" *without* first
using "p/r".  Pretty-printing applies just to printing -- it does not
affect what is in the value history.  The values there still have the
correct type and such.

David> def pretty_printer_lookup(gdbval):
[...]

David> def register (obj):
David>     if obj is None:
David>         obj = gdb

David>     # Wire up the pretty-printer
David>     obj.pretty_printers.append(pretty_printer_lookup)

It's better to use the gdb.printing facilities now.  These let user
disable pretty-printers if they prefer.  The libstdc++ printers go out
of their way to use gdb.printing only if available; but you can probably
just assume it exists.

David> print('Successfully loaded GDB hooks for GCC')

I wonder whether gdb ought to do this.

Tom


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]