(gdb) l warning: Source file is more recent than executable. 1 #include<stdio.h> 2 3 int fun(int a, int b) { 4 int val = 0; 5 if (a > b) { 6 val = a + b; 7 } else { 8 val = a - b; 9 } 10 return val; (gdb) l 11 } 12 13 int main() { 14 printf("hello gdb!\n"); 15 int i; 16 for (i=0; i<10; i++) { 17 printf("what is gdb? %d\n", i); 18 } 19 return 0; 20 } (gdb) l - 1 #include<stdio.h> 2 3 int fun(int a, int b) { 4 int val = 0; 5 if (a > b) { 6 val = a + b; 7 } else { 8 val = a - b; 9 } 10 return val;
start
说明: 开始执行程序,并在main函数的第一条语句前面停下来
示例:
1 2 3 4 5 6
(gdb) start Temporary breakpoint 1 at 0x617: file hello1.c, line 14. Starting program: /home/dounine/gdb/hello1
Temporary breakpoint 1, main () at hello1.c:14 14 printf("hello gdb!\n");
(gdb) start Temporary breakpoint 1 at 0x617: file hello1.c, line 14. Starting program: /home/dounine/gdb/hello1
Temporary breakpoint 1, main () at hello1.c:14 warning: Source file is more recent than executable. 14 printf("hello gdb!\n"); (gdb) l 9 } 10 return val; 11 } 12 13 int main() { 14 printf("hello gdb!\n"); 15 16 int i; 17 for (i=0; i<10; i++) { 18 printf("what is gdb? %d\n", i); (gdb) break 17 Breakpoint 2 at 0x400629: file hello1.c, line 17. (gdb) break fun Breakpoint 3 at 0x4005d0: file hello1.c, line 4. (gdb) break *0x400630 Breakpoint 4 at 0x400630: file hello1.c, line 17. (gdb) break +2 Note: breakpoint 2 also set at pc 0x400629. Breakpoint 5 at 0x400629: file hello1.c, line 16.
(gdb) break 22 Breakpoint 2 at 0x40065f: file hello1.c, line 22. (gdb) c Continuing. hello gdb! what is gdb? 0 what is gdb? 1 what is gdb? 2 what is gdb? 3 what is gdb? 4 what is gdb? 5 what is gdb? 6 what is gdb? 7 what is gdb? 8 what is gdb? 9
Breakpoint 2, main () at hello1.c:22 22 printf("%d\n", fun(a, b)); (gdb) n -2 24 return 0; (gdb) n 25 }
(gdb) start Temporary breakpoint 1 at 0x617: file hello1.c, line 14. Starting program: /home/dounine/gdb/hello1
Temporary breakpoint 1, main () at hello1.c:14 warning: Source file is more recent than executable. 14 printf("hello gdb!\n"); (gdb) b 22 Breakpoint 2 at 0x40065f: file hello1.c, line 22. (gdb) c Continuing. hello gdb! what is gdb? 0 what is gdb? 1 what is gdb? 2 what is gdb? 3 what is gdb? 4 what is gdb? 5 what is gdb? 6 what is gdb? 7 what is gdb? 8 what is gdb? 9
Breakpoint 2, main () at hello1.c:22 22 printf("%d\n", fun(a, b)); (gdb) s fun (a=1, b=3) at hello1.c:4 4 int val = 0; (gdb) n 5 if (a > b) {
(gdb) info "info" must be followed by the name of an info command. List of info subcommands:
info address -- Describe where symbol SYM is stored info all-registers -- List of all registers and their contents info args -- Argument variables of current stack frame info auto-load -- Print current status of auto-loaded files info auxv -- Display the inferior's auxiliary vector info bookmarks -- Status of user-settable bookmarks info breakpoints -- Status of specified breakpoints (all user-settable breakpoints if no argument) info checkpoints -- IDs of currently known checkpoints info classes -- All Objective-C classes info common -- Print out the values contained in a Fortran COMMON block info copying -- Conditions for redistributing copies of GDB info dcache -- Print information on the dcache performance info display -- Expressions to display when program stops info exceptions -- List all Ada exception names info extensions -- All filename extensions associated with a source language info files -- Names of targets and files being debugged info float -- Print the status of the floating point unit info frame -- All about selected stack frame info frame-filter -- List all registered Python frame-filters info functions -- All function names info guile -- Prefix command for Guile info displays info handle -- What debugger does when program gets various signals info inferiors -- IDs of specified inferiors (all inferiors if no argument) info line -- Core addresses of the code for a source line info locals -- Local variables of current stack frame info macro -- Show the definition of MACRO info macros -- Show the definitions of all macros at LINESPEC info mem -- Memory region attributes info os -- Show OS data ARG info pretty-printer -- GDB command to list all registered pretty-printers info probes -- Show available static probes info proc -- Show /proc process information about any running process info program -- Execution status of the program info record -- Info record options info registers -- List of integer registers and their contents info scope -- List the variables local to a scope info selectors -- All Objective-C selectors info set -- Show all GDB settings info sharedlibrary -- Status of loaded shared object libraries info signals -- What debugger does when program gets various signals info skip -- Display the status of skips info source -- Information about the current source file info sources -- Source files in the program info stack -- Backtrace of the stack info static-tracepoint-markers -- List target static tracepoints markers info symbol -- Describe what symbol is at location ADDR info target -- Names of targets and files being debugged info tasks -- Provide information about all known Ada tasks info terminal -- Print inferior's saved terminal status info threads -- Display currently known threads info tracepoints -- Status of specified tracepoints (all tracepoints if no argument) info tvariables -- Status of trace state variables and their values info type-printers -- GDB command to list all registered type-printers info types -- All type names info unwinder -- GDB command to list unwinders info variables -- All global and static variable names info vector -- Print the status of the vector unit info vtbl -- Show the virtual function table for a C++ object info warranty -- Various kinds of warranty you do not have info watchpoints -- Status of specified watchpoints (all watchpoints if no argument) info win -- List of all displayed windows info xmethod -- GDB command to list registered xmethod matchers
(gdb) br 17 Breakpoint 2 at 0x400629: file hello1.c, line 17. (gdb) info breakpoints Num Type Disp Enb Address What 2 breakpoint keep y 0x00400629 in main at hello1.c:17 (gdb) delete 2 (gdb) info breakpoints No breakpoints or watchpoints. (gdb) br 16 Breakpoint 3 at 0x400629: file hello1.c, line 16. (gdb) br 17 Note: breakpoint 3 also set at pc 0x400629. Breakpoint 4 at 0x400629: file hello1.c, line 17. (gdb) br 18 Breakpoint 5 at 0x400632: file hello1.c, line 18. (gdb) info breakpoints Num Type Disp Enb Address What 3 breakpoint keep y 0x00400629 in main at hello1.c:16 4 breakpoint keep y 0x00400629 in main at hello1.c:17 5 breakpoint keep y 0x00400632 in main at hello1.c:18 (gdb) delete Delete all breakpoints? (y or n) y (gdb) info breakpoints No breakpoints or watchpoints.