Differences between revisions 3 and 5 (spanning 2 versions)
Revision 3 as of 2020-03-16 20:56:32
Size: 350
Editor: SamatJain
Comment:
Revision 5 as of 2020-06-06 03:33:53
Size: 981
Editor: SamatJain
Comment: gdb usage patterns
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
== Usage patterns ==

Run a program w/ arguments:

{{{#!highlight sh numbers=off
gdb --args ${PROGRAM_NAME} ${ARGUMENTS}
}}}

to automatically start debugging, put commands into a file, including breakpoints if you want them. E.g.:

{{{
breakpoint main.cpp:1
run
}}}

and then execute gdb with `-x`:

{{{#!highlight sh numbers=off
gdb -x ${COMMANDS_FILE} --args ${PROGRAM_NAME} ${ARGUMENTS}
}}}

Line 9: Line 31:
 * `generate-core-file` to generate a coredump. Be aware of [[https://bugzilla.redhat.com/show_bug.cgi?id=1099405|this bug on RHEL 7.x]], for which the workaround is `info threads` before creating the coredump.

Stuff about GNU Debugger (AKA gdb).

Usage patterns

Run a program w/ arguments:

gdb --args ${PROGRAM_NAME} ${ARGUMENTS}

to automatically start debugging, put commands into a file, including breakpoints if you want them. E.g.:

breakpoint main.cpp:1
run

and then execute gdb with -x:

gdb -x ${COMMANDS_FILE} --args ${PROGRAM_NAME} ${ARGUMENTS}

Quick reference

  • List all variables in current context: info locals if at a breakpoint, or bt full if at a breakpoint

  • generate-core-file to generate a coredump. Be aware of this bug on RHEL 7.x, for which the workaround is info threads before creating the coredump.

SamatsWiki: GnuDebugger (last edited 2020-06-06 03:33:53 by SamatJain)