日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

gdb高级调试技巧

發(fā)布時(shí)間:2023/11/27 生活经验 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 gdb高级调试技巧 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1. 反向調(diào)試

gdb支持程序反向執(zhí)行。

record??讓程序開始記錄反向調(diào)試所必要的信息

rn :?reverse next

rc: reverse continue ,Continue program being debugged but run?it in reverse

record stop:?停止記錄

2.?格式化(pretty print)打印結(jié)構(gòu)體內(nèi)容

GDB調(diào)試C程序時(shí),默認(rèn)情況下輸出很不直觀,看起來很費(fèi)勁.

set print pretty on

3.AddressSanitizerAndDebugger

https://github.com/google/sanitizers/wiki/AddressSanitizerAndDebugger

b __asan::ReportGenericError

p?__asan_describe_address(0x7ffff73c3f80)

4. 條件斷點(diǎn)不生效

設(shè)置條件斷點(diǎn):

cond 1?$rdi==0x0? ?//在斷點(diǎn)一設(shè)置條件斷點(diǎn)

b 57 if?$rdi==0x0? ?//在當(dāng)前文件的57行設(shè)置條件斷點(diǎn)

有時(shí)候你會(huì)發(fā)現(xiàn)條件斷點(diǎn)沒有生效,我的解決方案是,先單步運(yùn)行(n)幾行,在運(yùn)行c.

Greg 在他的blog中也提到過這個(gè)問題:http://www.brendangregg.com/blog/2016-08-09/gdb-example-ncurses.html

5. Command 阻塞

上例中在斷點(diǎn)1設(shè)置command,? 先打印堆棧,再continue, 你會(huì)發(fā)現(xiàn)gdb 還是會(huì)被自動(dòng)阻塞住。

你需要在gdb的配置文件.gdbinit中添加?set height 0,?會(huì)自動(dòng)避免阻塞問題

6.ptype

Print definition of type TYPE. 可以顯示類型的定義。

有個(gè)重要參數(shù): \o

/o ? ?? ?print offsets and sizes??of fields in a struct (like pahole)

struct tuv
{
int a1;
char *a2;
int a3;
};
(gdb) ptype /o struct tuv
/* offset | size */ type = struct tuv {
/* 0 | 4 */ int a1;
/* XXX 4-byte hole */
/* 8 | 8 */ char *a2;
/* 16 | 4 */ int a3;
/* total size (bytes): 24 */
}

Notice the format of the first column of comments. There, you
can find two parts separated by the ‘|’ character: the offset, which
indicates where the field is located inside the struct, in bytes, and
the size of the field. Another interesting line is the marker of a hole
in the struct, indicating that it may be possible to pack the struct
and make it use less space by reorganizing its fields.

7 File filename

修改code后,重新build。

gdb無須退出,在gdb中運(yùn)行 file a.out?命令,新編譯的a.out會(huì)自動(dòng)加載到gdb。

8.?調(diào)試多線程

info threads

thread 1

set scheduler-locking on/off/step

set?schedule-multiple on/off

thead apply all bt

thead apply 1 bt

總結(jié)

以上是生活随笔為你收集整理的gdb高级调试技巧的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。