1、什么是GDB
2、准备工作
3、GDB启动、退出、查看代码
输入:
gcc test.c -o test -g
gcc test.c -o test1
ll -h test test1
输出:
-rwxr-xr-x 1 petri petri 20K Apr 21 18:50 test*
-rwxr-xr-x 1 petri petri 17K Apr 21 18:50 test1*
可以看出加入-g文件变大了。
进入gdb调试:
gdb test
(gdb) set args 10 20
(gdb) show args
Argument list to give program being debugged when it is started is "10 20".
(gdb) help (查看帮助文档)
(gdb) q (退出)
关于list:
-g
选项的作用是在可执行文件中加入源代码信息,比如可执行文件中第几条机器指令对应源代码的第几行,并没有把源代码嵌入可执行文件中。所以源代码文件不可以没有。
1、显示
list 一次显示10行:
(gdb) list
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int test(int a);
5
6 int main(int argc, char* argv[]) {
7 int a, b;
8 printf("argc = %d\n", argc);
9
10 if