gdb调试:
进入调试
gcc -o xxx.o xxx.c -g
gdb xxx.o
显示源代码
(gdb) l
在第六行打上断点
(gdb) b 6
查看断点号
(gdb) info b
删除断点号为3的断点
(gdb) d 3
Breakpoint 1 at 0x80483e7: file a.c, line 6.
运行代码
(gdb) r
Starting program: /home/xyw/study/3th/a.o
Breakpoint 1, main () at a.c:6
6 printf("dasdajhmdfh");
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.80.el6.i686
继续往下执行
(gdb) c
Continuing.
进入函数,分布执行每条代码。
(gdb) s
打印变量fd的值
(gdb) p fd
Breakpoint 3, main () at a.c:9
不进入函数,执行代码
(gdb) n
Breakpoint 4, main () at a.c:10
帮助命令
(gdb) h
List of classes of commands:
aliases -- Aliases of other commands
breakpoints -- Making program stop at certain points
data -- Examining data
files -- Specifying and examining files
internals -- Maintenance commands
obscure -- Obscure features
running -- Running the program
stack -- Examining the stack
status -- Status inquiries
support -- Support facilities
tracepoints -- Tracing of program execution without stopping the program
user-defined -- User-defined commands
退出调试
(gdb) q
A debugging session is active.
Inferior 1 [process 5171] will be killed.
Quit anyway? (y or n) y