gcc中的一些信息
todd@todd-virtual-machine:~/test/test03$ gcc -c hello.c只编译和激活生成.o的目标代码文件
todd@todd-virtual-machine:~/test/test03$ gcc -S hello.c 生成汇编代码文件
todd@todd-virtual-machine:~/test/test03$ gcc -E hello.c 直接预处理,并将预处理结果显示
todd@todd-virtual-machine:~/test/test03$ gcc -g hello.c 生成a.out的ddb调试信息
todd@todd-virtual-machine:~/test/test03$ ls
a. out hello.c hello.o hello.s
todd@todd-virtual-machine:~/test/test03$ gdb a.out 调试 //类似于windows在keil软件进行仿真测试,keil下可以查看寄存器的使用状况
以下是在查看状态下的命令信息
(gdb) break main 在main位置设置断点
Breakpoint 1 at 0x400531: file hello.c,line 4.
(gdb) r 程序运行到main位置
Starting program:/home/todd/test/test03/a.out
Breakpoint 1, main () at hello.c:4
4 printf("helloworld!\n");
(gdb) l 查询7行程序信息
1 #include<stdio.h>
2 intmain()
3 {
4 printf("helloworld!\n");
5 return0;
6 }
7
(gdb) l 5 则显示第5行附近的10行信息
1 #include<stdio.h>
2 intmain()
3 {
4 printf("helloworld!\n");
5 return0;
6 }
7
(gdb) b 3 在第三行设置断点
Note: breakpoint 1 also set at pc 0x400531.
Breakpoint 2 at 0x400531: file hello.c,line 3.
(gdb) info break 用info查看断点
Num Type Disp EnbAddress What
1 breakpoint keep y 0x0000000000400531 in main at hello.c:4
breakpointalready hit 1 time
2 breakpoint keep y 0x0000000000400531 in main at hello.c:3
(gdb) next 输入next或n单步调试程序。
helloworld!
5 return0;
(gdb) n 单击一次单步执行一次
6 }
(gdb) n 3 单击一次单步执行3次
9 }
(gdb) c c是continue的简写,退出循环可以是用c
P sum 时刻监视sum的值(p是print的缩写)
(gdb) q 按下q 退出调试
todd@todd-virtual-machine:~/test/test03$ ls
867

被折叠的 条评论
为什么被折叠?



