gdb小技巧總結
gdb日誌使用記錄
1、顯示結構體定義:
(gdb) ptype struct kmem_cache_cpu
type = struct kmem_cache_cpu {
void **freelist;
unsigned long tid;
struct page *page;
struct page *partial;
}
(gdb)
2、顯示結構欄位偏移
(gdb) ptype /o struct kmem_cache_cpu
/* offset | size */ type = struct kmem_cache_cpu {
/* 0 | 8 */ void **freelist;
/* 8 | 8 */ unsigned long tid;
/* 16 | 8 */ struct page *page;
/* 24 | 8 */ struct page *partial;
/* total size (bytes): 32 */
}
(gdb)
3、backtrace
bt -5 顯示棧底5層棧
bt 5 顯示棧頂5層棧
set height 0 不分頁輸出
set pagination off 關閉分頁
4、command命令,實現自動化
set pagination off
set logging file gdb.log
set logging overwrite
set logging on
break sum if 0 == (a%5)
commands
silent
printf "\n"
p \$rdi
bt
continue
end
5、gdb斷點禁止執行緒切換
set scheduler-locking on/off
b func thread x
6、gdb trap相關
handle SIGTRAP nostop noprint //不中斷,不列印提示
設定watchpoint後,
x86上gdb不停收到SIGTRAP,可以檢視eflags暫存器值,TF位置被置1了
修改為0後不再收到sigtrap:
set $ps &= ~(1<<8)
【on x86-based machines $ps is an alias for the eflags register, TF is the 9th bit of eflags】
7、自定義變數
(gdb) info locals
object = 0xffff800005803400
(gdb) p object
\$11 = (void *) 0xffff800005803400
(gdb) set \$foo=object
(gdb) p \$foo
\$12 = (void *) 0xffff800005803400
8、迴圈列印連結串列
(gdb)set \$foo = next
(gdb)while 1 //while \$foo
>print \$foo
>set \$foo = next->next
>end