是否可以使用 GDB(在斷點處)以位元組為單位獲取堆疊的當前大小?我在互聯網上沒有找到任何關于此的資訊。
uj5u.com熱心網友回復:
不清楚您是問“到目前為止我的執行緒消耗了多少堆疊”,還是“該執行緒將來可能消耗的最大堆疊大小是多少”。
第一個問題可以通過使用以下方法輕松回答:
# go to the innermost frame
(gdb) down 100000
(gdb) set var $stack = $sp
# go to the outermost frame
(gdb) up 100000
(gdb) print $sp - $stack
要回答第二個問題,您需要libpthread使用除錯符號構建。如果使用 GLIBC,您可以這樣做:
# Go to frame which is `start_thread`
(gdb) frame 2
#2 0x00007ffff7d7eeae in start_thread (arg=0x7ffff7a4c640) at pthread_create.c:463
463 in pthread_create.c
(gdb) p pd.stackblock
$1 = (void *) 0x7ffff724c000 # low end of stack block
(gdb) p pd.stackblock_size
$1 = 8392704
在這里您可以看到整個堆疊跨越[0x7ffff724c000, 0x7ffff7a4d000]區域。您還可以確認$sp在該區域中,靠近堆疊的高地址端(在此系統上從高地址向低地址增長):
(gdb) p $sp
$9 = (void *) 0x7ffff7a4be60
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/343343.html
上一篇:進行回圈計算
