我想模擬一個函數(用於單元測試父函數)使用GDB。一種方法是在你打算模擬的函數中設置一個斷點,並使用GDB 返回命令。GDB腳本MOCK
但是,當GDB 調用命令被使用時,我無法做到這一點。
(gdb) b secret_check Breakpoint 1 at 0x80483ba: file ut_gdb.c, line 6. (gdb) start Temporary breakpoint 2 at 0x804843c: file ut_gdb.c, line 34. Starting program: ut.bin Temporary breakpoint 2, main() at ut_gdb.c:34 34 int res = 0; (gdb) bt #0 main() at ut_gdb.c:34 (gdb) call fact(3) Breakpoint 1, secret_check (check_type=1) at ut_gdb.c:6 6 if(check_type == 0){ The program being debugged stopped while in a function called from GDB. Evaluation of the expression containing the function (fact) will be abandoned. When the function is done executing, GDB will silently stop. (gdb) bt #0 secret_check (check_type=1) at ut_gdb.c:6 #1 0x080483ff in fact (n=3) at ut_gdb.c:19 #2 #3 main() at ut_gdb.c:34
這是GDB的限制嗎?
是否容易增加這個功能到GDB? – Kamath 2011-06-08 05:53:55
我不是GDB開發者,所以我不知道。但是我的猜測是,從與他們一起工作的角度來看,這將是非常困難的。假設有一個單獨的「繼續」狀態而不是它們的列表 - 如果我猜測其中只有一個是正確的 - 可能會在整個程序中出現在各種地方, d必須找到並解決所有這些問題。如果很容易,有人可能已經修好了。 – 2011-06-10 01:55:22