Emacs中使用gdb
时间:2009-07-31 来源:cmdblock
Emacs中使用gdb
myprog.c
1.启动,打入下面命令
emacs myprog.c
M-x gdb
M-x gdb-many-windows
file myprog
start
myprog.c
1 typedef struct {myproc.c
2 float a;
3 float b;
4 } substruct;
5
6 struct {
7 int i;
8 substruct r;
9 } c;
10
11 main() {
12 int n = 4;
13 int m[10] = {0,1,4,9,16,25,36,49,64,81};
14 n = 5;
15 myproc(n);
16 c.i = 1;
17 c.r.a = 0.5;
18 c.r.b = 0.25;
19 }
1 myproc(n)
2 {
3 int p;
4 p = 2*n;
5 printf("Two times %d is %d\n", n, p);
6 }
cc -g -c myproc.c
cc -g -o myprog myprog.c myproc.o
如果要用gdb调试器,必须使用g选项。GCC 的g选项 (prof 命令)建立剖析(profile)信息并且把调试信息加入到可执行的文件里.
gdb基本命令
backtrace(或bt) | 查看各级函数调用及参数 |
finish | 执行到当前函数返回,然后停下来等待命令 |
frame(或f) 帧编号 | 选择栈帧 |
info(或i) locals | 查看当前栈帧局部变量的值 |
list(或l) | 列出源代码,接着上次的位置往下列,每次列10行 |
list 行号 | 列出从第几行开始的源代码 |
list 函数名 | 列出某个函数的源代码 |
next(或n) | 执行下一行语句 |
print(或p) | 打印表达式的值,通过表达式可以修改变量的值或者调用函数 |
set var | 修改变量的值 |
start | 开始执行程序,停在main函数第一行语句前面等待命令 |
step(或s) | 执行下一行语句,如果有函数调用则进入到函数 |
break(或b) 行号 | 在某一行设置断点 |
break 函数名 | 在某个函数开头设置断点 |
break...if... | 设置条件断点 |
continue(或c) | 从当前位置开始连续执行程序直到遇到断点 |
delete breakpoints | 删除断点 |
display 变量名 | 跟踪查看一个变量,每次停下来都显示它的值 |
disable breakpoints | 禁用断点 |
enable breakpoints | 启用断点 |
info(或i) breakpoints | 查看当前设置了哪些断点 |
run(或r) | 从头开始连续而非单步执行程序 |
undisplay | 取消对先前设置的那些变量的跟踪 |
jump |
在断点之间跳转 |
1.启动,打入下面命令
emacs myprog.c
M-x gdb
M-x gdb-many-windows
file myprog
start