2010-11-12 64 views
11

我想在gdb斷點上設置一個條件,只有當某個函數名稱出現在回溯中時纔會中斷。什麼是最好的方法來做到這一點?GDB如果幀在回溯中斷

+0

的[?有什麼辦法來設置一個斷點,在gdb是在調用堆棧條件(可能的複製http://stackoverflow.com/questions/5336403/is-there-any-way-to-set-a-breakpoint-in-gdb-that-is-conditional-on-the-call-stac) – 2016-12-30 12:32:01

回答

2

我不確定如何完全按照您的要求進行操作,但是如果您有權訪問相關函數的源代碼,則可能的解決方法是在函數的開頭將一些全局布爾變量設置爲true ,並在函數退出之前將其設置爲false。然後,您可以設置條件斷點(使用condition命令)僅在此布爾變量爲true時停止。

+0

這就是我最終做的,但我很想知道如何不用重新編譯就可以做到。 – Chazz 2010-11-15 06:02:37

3

比Python腳本更簡單的解決方案是使用temporary breakpoint

它看起來像這樣:

b ParentFunction 
command 1 
    tb FunctionImInterestedIn 
    c 
end 

每次你在ParentFunction休息時間,你會設定一個一次性斷點功能,你真正感興趣的,然後繼續運行(大概直到你打該斷點)。

既然你打破FunctionImInterestedIn只有一次,這是不行的,如果FunctionImInterestedIn中的ParentFunction情況下多次調用,並要在每次調用中斷。

0

替代rix0rrr的回答是:

b main 
commands 
set $inParentFunction = 0 
c 
end 

b ParentFunction 
commands 
set $inParentFunction = 1 
c 
end 

b FunctionImInterestedIn if ($inParentFunction)