2009-08-13 87 views

回答

6

你正在使用什麼命令? next調試時會去下一行my_func1(my_func2(my_func3(val)));,但step應該輸入my_func3。 例子:

int my_func1(int i) 
{ 
    return i; 
} 

int my_func2(int i) 
{ 
    return i; 
} 

int my_func3(int i) 
{ 
    return i; 
} 

int main(void) 
{ 
    return my_func1(my_func2(my_func3(1))); 
} 

調試的:

(gdb) b main 
Breakpoint 1 at 0x4004a4: file c.c, line 19. 
(gdb) run 
Starting program: test 

Breakpoint 1, main() at c.c:19 
19 return my_func1(my_func2(my_func3(1))); 
(gdb) step 
my_func3 (i=1) at c.c:14 
14 return i; 
(gdb) step 
15 } 
(gdb) step 
my_func2 (i=1) at c.c:9 
9 return i; 
(gdb) step 
10 } 
(gdb) step 
my_func1 (i=1) at c.c:4 
4 return i; 
(gdb) step 
5 } 
(gdb) step 
main() at c.c:20 
20 } 
(gdb) cont 
Continuing. 

Program exited with code 01. 
(gdb) 
0

是的,儘管你可能得到你的手髒與拆卸。首先嚐試step命令(簡稱s)。如果這不會讓你進入my_func3(),請嘗試使用stepi命令(縮寫si)來一次執行一條指令。這可能需要幾次調用,因爲可能有很多指令設置函數調用參數並在之後進行清理。

1

如果您知道函數定義在源代碼中的位置,一種解決方案將是在該函數中放置斷點。

+0

我不認爲這真的回答了這個問題 - 有可能進入功能來做到這一點。 – ajshort 2015-11-06 04:39:31