如何在EMACS中使用GDB调试

时间:2024-10-25 10:37:04

1、一.EMACS中调试1、usingtheclipboardM-xmenu-bar-enable-clipboard(makecut,copy,pastymenuitems,usetheclipboard)2、using“wheel”miceM-xmouse-wheel-mode(激活中间的滚动键)3、退出出任何命令状态C-g4、进入编译模式M-xcompile或者从菜单-》TOOLS-》COMPILE5、用COMPILE模式C-x`(搜索出错的源代码行)<RET>(光标定位在compilebuffer的出错提示行上,按〈RET〉键,会跳到出错的源代码行)C-uC-x`在compilebuffer列出同样的错误。6、用GREP搜索 (一)、M-xgrep进入搜索参数为agrep-styleregexp(usinginsingle-quotestoquotetheshell'sspecialcharacters)followsbyefilenames; (二)、C-x`(搜索出错的源代码行--grep搜索出来的同种错误)<RET>(光标定位在grepbuffer的出错提示行上,按〈RET〉键,会跳到出错的源代码行)

2、二、GUD调试1、进入M-xgdb2、命令C-x<SPC>在指针所在源代码行上设置断点说明C-c在GUDBUFFER,而C-xC-a在gudbufferandsourcebuffer都行3、C-cC-lC-xC-aC-l到达最后一行4、C-cC-sC-xC-aC-sgud-step5、C-cC-nC-xC-aC-ngud-next6、C-cC-rC-xC-aC-rgud-cont执行到下一个断点7、C-cC-dC-xC-aC-dgud-remove删除当前断点

3、三、GDB命令1、调试命令stepnextcontinueuntile2、设置断点breakfile.c:foobreakfile.c:11break+12break-12如果执行到某一行,+表示往前,-表示向后断点信息infobreakpointenable<breakpointnumber>disable<breakpointnumber>断点条件break<args>if<cond>condition<breaknumber><cond>deletebreakpoints<breaknumber>clear3、显示源代码list使用同断点4、查看变量print/fmt<expr>5、查看内存x/<fmt><addr>6、切换目录cd7、添加源文件路径dir<path>8、显示如果有charmsg[25];int*arr=(int*)mollac(len*sizeof(int));则displaymsgdisplay*arr@len或者pmsgp*arr@len9、跳转执行jumplinespecjump<addr>

4、四、Makefile文件//mt.h#ifdef_cplusplusextern"c"{#endifintadd(inta,intb);intsubstract(intnum,intn,int*ret);#ifdef_cplusplus}#endif-----------------------------------------------//math.c#include"mt.h"intadd(inta,intb){return(a+b);}intsubtract(intnum,intn,int*ret){*ret=num-n;return*ret;}-----------------------------------------------//msg.h#ifdef_cplusplusextern"c"{#endifvoidprnmsg(char*msg);#ifdef_cplusplus}#endif-----------------------------------------------//msg.c#include<stdio.h>#include"www.gzlij.com msg.h"voidprnmsg(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"intmain(intargc,char*argv[]){inti,j,sum;int*p_iret;charmsg[256];printf("hellow,thisisatestprogram/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,"thishasmodify=%d",*p_iret);prnmsg(msg);return0;}//Makefilevlc:vlc.omath.omsg.o [email protected]:math.cmt.h [email protected]:msg.cmsg.h gcc-g-cmsg.cvlc.o:vlc.ccomm.h gcc-g-cvlc.cclean: rm-rvfmsg.omath.ovlc.ovlc

© 手抄报圈