2009-08-13 43 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

相关问题