已觸發了乙個斷點 vs GDB不同檔案斷點除錯

2021-10-11 14:14:16 字數 3196 閱讀 1635

gdb不同檔案斷點除錯

作為乙個linux下c/c++開發人員,除錯工具是必不可少的一項技能,在windows平台,會有很多任務具給我們用,比如vs,自帶很強大的除錯工具。當然,linux平台夜市毫不遜色,gdb工具是乙個非常強大的**除錯工具。今天主要介紹的是gdb在多檔案中的除錯方法,不會一一介紹基礎命令的。

一、同乙個目錄中的檔案

現在,有三個檔案,分別為main.cpp、test1.cpp、test2.cpp檔案,這個是很簡單的程式,只是為了說明除錯過程。

**如下:

head.h

#include using namespace std;

void test1();

void test2();

test2.cpp

#include "head.h"

void test2()

這部分**都在同乙個目錄下:gdb/manyfiles
step1:編譯**,記得加引數 -g

gdb/manyfiles$ g++ main.cpp test1.cpp test2.cpp -o test -g

gdb/manyfiles$ ls

head.h main.cpp test test1.cpp test2.cpp

step 2:開始除錯

gdb/manyfiles$ gdb test
step 3:同乙個資料夾中的檔案,我們可以用 break file1.cpp: linenum

(gdb) l 1

1 #include "head.h"

2 3 int main()

4 (gdb) b test1.cpp:4

breakpoint 1 at 0x4008b2: file test1.cpp, line 4.

step 4:啟動程式,程式會在斷點處停止執行

(gdb) l 1

1 #include "head.h"

2 3 int main()

4 (gdb) b test1.cpp:4

breakpoint 1 at 0x4008b2: file test1.cpp, line 4.

(gdb) run

starting program: /mnt/hgfs/share/c++/gdb/manyfiles/test

breakpoint 1, test1 () at test1.cpp:5

5 cout

退出gdb除錯

(gdb) c

continuing.

test1

test2

[inferior 1 (process 56202) exited normally]

(gdb) quit

上面這個步驟就是我們的多檔案除錯,當然,在大型專案中,檔案往往都是在不同的資料夾中,所以,我們也要掌握在不同問價夾中除錯的辦法。

二、不同資料夾中檔案除錯

**還是上面的**,只是會放在不同的目錄下:

gdb/test1:test1.cpp

gdb/test2:test2.cpp

gdb/manyfiles:main.cpp

step1:編譯**,記得加引數 -g

gdb/manyfiles$ gdb/manyfiles$ g++ main.cpp ../test1/test1.cpp ../test2/test2.cpp -o test -g

gdb$ ls

manyfiles test1 test2

step 2:開始除錯

gdb/manyfiles$ gdb test
step 3:不同資料夾中的檔案,我們可以用 directory 命令修改路徑

(gdb) directory ../test1/

source directories searched: /mnt/hgfs/share/c++/gdb/manyfiles/../test1:$cdir:$cwd

(gdb) b test1.cpp:2

breakpoint 1 at 0x4008b2: file ../test1/test1.cpp, line 2.

(gdb) r

starting program: /mnt/hgfs/share/c++/gdb/manyfiles/test

breakpoint 1, test1 () at ../test1/test1.cpp:5

5 cout

啟動程式,程式會在斷點處停止執行

(gdb) l 1

1 #include "head.h"

2 3 int main()

4 (gdb) b test1.cpp:4

breakpoint 1 at 0x4008b2: file test1.cpp, line 4.

(gdb) run

starting program: /mnt/hgfs/share/c++/gdb/manyfiles/test

breakpoint 1, test1 () at test1.cpp:5

5 cout

退出gdb除錯

(gdb) c

continuing.

test1

test2

[inferior 1 (process 56202) exited normally]

(gdb) quit

這就是今天介紹的gdb多檔案斷點除錯的全部內容。

exe觸發了乙個斷點 opencv人臉檢測

利用opencv進行人臉檢測,遇到乙個十分不解的問題,每次程式退出都會觸發斷點,單步除錯無數次根本沒用,最後偶然得以解決,記錄在此,防止後來者踩坑。事情發生在女朋友的電腦上,她之前裝的vs2010,然後我給她推薦vs2013,就裝上vs2013,但是她的c盤太小,空間不夠,就使勁刪,把2010也給解...

開發了乙個ripple effect元件

目前來看網上的除了material ui的ripple effect效果很棒以外,其餘的ripple元件都不夠完美。github位址 專案演示 sowhitesocoll.github.io dodo ripple yarn add dodo ripple 複製 直接當作block使用的時候,會認為...

乙個觸發器

設計乙個觸發器,當刪除employees中的某個雇員時,刪除orders表中的與這個雇員 相關的一切記錄。第一步 建立儲存過程 drop trigger employees delete gocreate trigger employees delete on employees instead o...