著作權資訊:
本文來自internet,轉載這裡供流媒體愛好者學習和研究使用,請尊重作者的勞動成果。未經授權而在商業上使用原作者的文章屬侵權行為,後果由使用者自負,本人不承擔任何法律責任。
EMACS 中調試 1、using the clipboard M-x menu-bar-enable-clipboard (make cut,copy,pasty menu items,use the clipboard) 2、using wheelmice M-x mouse-wheel-mode (啟用中間的滾動鍵)
一 .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〉鍵,會跳到出錯的原始碼行)
二、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 刪除當前斷點
三、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>
四、Makefile 檔案
//mt.h
#ifdef _cplusplus
extern "c" {
#endif
int 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 _cplusplus
extern "c" {
#endif
void prnmsg(char *msg);
#ifdef _cplusplus
}
#endif
-----------------------------------------------
//msg.c
#include<stdio.h>
#include"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;
}
-----------------------------------------------
//Makefile
vlc:vlc.o math.o msg.o
gcc -g -o $@ vlc.o math.o msg.o
math.o:math.c mt.h
gcc -g -c -o $@ math.c
msg.o:msg.c msg.h
gcc -g -c msg.c
vlc.o:vlc.c comm.h
gcc -g -c vlc.c
clean:
rm -rvf msg.o math.o vlc.o vlc