|
Quick Navigation Bar make and makefiles :: debugging techniques :: creating libraries [ toc | forums ] |
Note: If the document URL does not begin with http://randu.org/tutorials/c/ then you are viewing a copy. Please direct your browser to the correct location for the most recent version. |
#ifdef DEBUG and
corresponding #endif statements around debug code. For
example:
#ifdef DEBUG
PRINTF(("Variables Currently Contain: %d, %f, %s\n", *pi, *pf[1], str));
#endif
You can specify a DEBUG define at compile time by issuing gcc with
the -DDEBUG command option.DPRINTF, so you don't even have to
write the #ifdef #endif directives! How? Look at the
Programming Tips and Tricks section
(Quick Debugging Statements).-g option
and without any optimization (i.e. no -O2 flag).break 376 would instruct gdb to stop
at line 376.run command.
If your program requires command-line options or parameters, you can
specify them with the run command. For example: run 4 -s
Doc! where 4, -s, Doc! are the parameters.step command.
NOTE: Do not step into system library calls (e.g.
printf). You can use the command next over these types
of calls or over local function calls you don't wish to step into.
You can repeat the last command by simply pressing enter.continue command to tell gdb to
continue executing until the next breakpoint or it finishes the
program.print command on the variable. For example: print
mystruct->data.set command.
For example: set mystruct->data = 42.ptype command can tell you what type a particular
variable is.commands instruction tells gdb to set a particular
number of commands and to report them to you. For example,
commands 1 will allow you to enter in a variable number
of other commands (one per line, end it with "end"), and will report
those commands to you once breakpoint 1 is hit.clear command tells gdb to clear a specified
breakpoint.list command can tell you where you are
at in the particular code block.help command inside gdb.runargs.check -memuse command.
This will check for memory use. If you want to also check for
access violations, you can use the check -all command.run command. If you get any
access violations or memory leaks, dbx will report them to you.
