- 论坛徽章:
- 0
|
(gdb) b 36 - break at line number 36 of current source file
(gdb) b 36 if i==3 - break at line 36 of current source file if the
variable i is equal to 3
(A condition such as if "i==3" can be added after
any breakpoint definition )
(gdb) b fn.c:22 - break at line number 22 of source file fn.c which
is compiled into this executable
(gdb) b func - break at function "func" entry point (or in
source file fn.c: b fn.c:func)
(gdb) i b - info breakpoints. Lists all breakpoints now set up.
(gdb) d - delete all breakpoints (d 1 for just #1).
An executable file (a.out if the -o option is not used) can be compiled from a number of source files in C, and the will know about these source files and the lines they contain. To find source line numbers so you can set breakpoints, use the following commands:
(gdb) l 23 - list to terminal screen 10 lines of current source
centered at line 23
(gdb) l fn.c:22 - print 10 lines from source file in fn.c centered
at line 22
(gdb) l func - print 10 lines around function "func" entry point
(or l fn.c:func)
(gdb) l - print 10 or more lines after lines last printed
(gdb) l fn.c:1 - print all lines starting from line 1 in source
file fn.fc
Some other commands for examining memory and program information are:
(gdb) i sources - info on sources - print the names of all source files
(gdb) i lo - info locals: values of all local vars, current
function
(gdb) i var - info variables: values of global/static vars
(gdb) i s - info stack:calls made to get to this execution
point.
(gdb) bt - same as i s
(gdb) where same as i s
(gdb) up - go up one stack level (to caller)
(gdb) down - go down one stack level (to called function)
(gdb) x 0x20034 - examine memory address 0x20034
(gdb) x/s 0x20034 - examine memory, addr 0x20034, as a string (also x/f
(gdb) display x - prints x each time program stops
(gdb) whatis x - prints type information for x
bf NOTE: While running, CTRL-C brings you back to the (gdb) prompt to examine the program state. This is useful for programs that are in an infinite loop or hung and for debugging performance problems
To begin running a program again after a break (including the first break at main) type:
(gdb) c - continue running program from stopped point
(gdb) c 22 - continue, don't stop at this breakpoint again
until it is encountered 22 times
In setting a breakpoint we were allowed to give a condition (b 36 if i==3). In a counted continue (c 22), the condition is not checked until the breakpoint has been encountered 22 times. To find out what breakpoints exist and delete them:
(gdb) i b - info on breakpoints - returns list of breaknumbers
(gdb) d 3 - delete break number 3
(gdb) d - delete all breakpoints
You can create an array starting at any position to print out values all with the same type:
(gdb) p array[3]@12 - will print out values starting at array position
3 for 12 positions
You can also call your own function from within the debugger:
(gdb) p my_function () - calls a function
(gdb) call my_function () - same as p
(gdb) p my_function (10, ``Boston'') - call function with values
(gdb) p my_function (x, p->;name) - call using variable values |
|