Linux Format

PRETTIER PRINTING

-

GDB version 7 was a landmark release because it added support for new commands and functions coded in Python. One of the big areas this opened up was extending GDB’S printing capabiliti­es. A great example of this is gdb-tools at https://github.com/vuvova/gdbtools, which can be downloaded and installed using Python’s pip (or

pip3) package manager: sudo pip3 install gdb-tools

gdb-tools includes DUEL.PY, a Python version of Michael Golan’s DUEL language for printing C data structures. DUEL is imported into

GDB by including the line python import duel at the start of your .gdbinit configurat­ion file.

DUEL supports an incredibly versatile expression­s notation, which is used to print an array and a linked list of pointers in this article. For more details and examples, see the manual at https://github. com/vuvova/gdb-tools/blob/arpeggio/duel/help.md.

Hooks

commands to a file, e.g.:

Standard GDB commands (e.g. quit and next) can be extended via hook functions. For example: define hook-quit set confirm off end hook-quit disables the irritating habit of GDB asking you if you’re really sure that you want to quit.

Infinitely running programs

The negfact.c example calculates the factorial of a positive number correctly but goes into an infinite loop when supplied with a negative value. There are two ways of debugging such code: cause it to crash and look at the core dump, or attach GDB to the running program and examine it while it’s still running. negfact.c reads its integer argument from the command line; it’s replicated inside GDB by calling run with a value (-5 in this case): (gdb) run -5

Newspapers in English

Newspapers from Australia