如何在EMACS中使用GDB调试?
1、一 .EMACS 中调试 1、using the clipboard M-x menu-bar-enable-clipboard (make cut,copy,pasty menu items,use the clipboard) 2、using “wheel”mice M-x mouse-wheel-mode (激活中间的滚动键) 3、退出出任何命令状态 C-g 4、进入编译模式 M-x compile 或者从菜单-》TOOLS-》COMPILE 5、用COMPILE 模式 C-x ` (搜索出错的源代码行) <RET> (光标定位在compile buffer 的出错提示行上,按〈RET〉键,会跳到出错的源代码行) C-u C-x ` 在compile buffer 列出同样的错误。 6、用GREP 搜索 (一)、M-x grep 进入搜索 参数为 a grep-style regexp(using in single-quotes to quote the shell's special characters)follows bye file names; (二)、 C-x ` (搜索出错的源代码行 --grep 搜索出来的同种错误) <RET> (光标定位在grep buffer 的出错提示行上,按〈RET〉键,会跳到出错的源代码行)
2、二、GUD 调试 1、进入 M-x gdb 2、命令 C-x <SPC> 在指针所在源代码行上设置断点 说明 C-c 在GUD BUFFER,而C-x C-a 在gud buffer and source buffer 都行 3、 C-c C-l C-x C-a C-l 到达最后一行 4、C-c C-s C-x C-a C-s gud-step 5、C-c C-n C-x C-a C-n gud-next 6、C-c C-r C-x C-a C-r gud-cont 执行到下一个断点 7、C-c C-d C-x C-a C-d gud-remove 删除当前断点
3、三、GDB 命令 1、调试命令 step next continue untile 2、设置断点 break file.c:foo break file.c:11 break +12 break -12 如果执行到某一行,+表示往前,-表示向后 断点信息 info breakpoint enable <breakpoint number> disable <breakpoint number> 断点条件 break <args> if <cond> condition <break number> <cond> delete breakpoints <break number> clear 3、显示源代码 list 使用同断点 4、查看变量 print /fmt <expr> 5、查看内存 x /<fmt> <addr> 6、切换目录 cd 7、添加源文件路径 dir <path> 8、显示 如果有 char msg[25]; int *arr=(int *)mollac(len*sizeof(int)); 则 display msg display *arr@len 或者 p msg p *arr@len 9、跳转执行 jump linespec jump <addr>
4、四、Makefile 文件//mt.h#ifdef _cplusplusextern "c" {#endifint add(int a,int b);int substract(int num,int n,int *ret);#ifdef _cplusplus}#endif-----------------------------------------------//math.c#include"mt.h"int add(int a,int b) { return (a+b);}int subtract(int num,int n,int *ret){*ret=num-n;return *ret;}-----------------------------------------------//msg.h#ifdef _cplusplusextern "c" {#endifvoid prnmsg(char *msg);#ifdef _cplusplus}#endif-----------------------------------------------//msg.c#include<stdio.h>#include"www.gzlij.com msg.h"void prnmsg(char * msg){ printf("%s/n",msg);}-----------------------------------------------//comm.h#include"mt.h"#include"msg.h"-----------------------------------------------//vlc.c#include<stdlib.h>#include<stdio.h>#include"comm.h"int main(int argc,char *argv[]){ int i,j,sum; int *p_iret; char msg[256]; printf("hellow,this is a test program/n"); i=15; j=10; sum=add(i,j); sprintf(msg,"number=%d",sum); prnmsg(msg); subtract(i,j,p_iret); sprintf(msg,"substract=%d",*p_iret); prnmsg(msg); sprintf(msg,"this has modify=%d",*p_iret); prnmsg(msg); return 0;}//Makefilevlc:vlc.o math.o msg.o gcc -g -o $@ vlc.o math.o msg.omath.o:math.c mt.h gcc -g -c -o $@ math.cmsg.o:msg.c msg.h gcc -g -c msg.cvlc.o:vlc.c comm.h gcc -g -c vlc.cclean: rm -rvf msg.o math.o vlc.o vlc