gdb ### 命令:: l,即 list,用于显示多行源代码。 b,即 break,用于设置断点。 r,即 run,用于开始运行程序。 n,即 next,用于执行下一条语句。如果该语句为函数调用,则不会进入函数内部执行。 p,即 print,用于打印内部变量值。 s,即 step,用于执行下一条语句。如果该语句为函数调用,则进入函数,执行其中的第一条语句。 c,即 continue,用于继续程序的运行,直到遇到下一个断点。 bt,即 backtrace,用于查看函数调用信息。 q,即 quit,用于退出 gdb 环境。 示例:: $ gdb ./a.out GNU gdb (Ubuntu 8.1-0ubuntu3.1) 8.1.0.20180409-git ...... Reading symbols from ./a.out...done. (gdb) l 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 8 int main () 9 { 10 char * words = "I am liuchao from user mode."; (gdb) b 10 Breakpoint 1 at 0x6e2: file syscall.c, line 10. (gdb) r Starting program: /root/syscall/a.out Breakpoint 1, main () at syscall.c:10 10 char * words = "I am liuchao from user mode."; (gdb) n 12 ret = syscall(333, words, strlen(words)+1); (gdb) p words $1 = 0x5555555547c4 "I am liuchao from user mode." (gdb) s __strlen_sse2 () at ../sysdeps/x86_64/multiarch/../strlen.S:79 (gdb) bt #0 __strlen_sse2 () at ../sysdeps/x86_64/multiarch/../strlen.S:79 #1 0x00005555555546f9 in main () at syscall.c:12 (gdb) c Continuing. return 63 from kernel mode. [Inferior 1 (process 1774) exited normally] (gdb) q 临时 ==== :: $ gdb --pid= -ex='handle SIGINT pass' -ex='c'