假设返回值未分配给变量,是否可以检查 gdb 中函数的返回值?
最佳答案
我想有更好的方法可以做到这一点,但是 finish命令执行直到当前堆栈帧被弹出并打印返回值 - 给定程序
int fun() {
return 42;
}
int main( int argc, char *v[] ) {
fun();
return 0;
}
你可以这样调试它——
(gdb) r
Starting program: /usr/home/hark/a.out
Breakpoint 1, fun () at test.c:2
2 return 42;
(gdb) finish
Run till exit from #0 fun () at test.c:2
main () at test.c:7
7 return 0;
Value returned is $1 = 42
(gdb)
finish
命令可以缩写为 fin
。不要使用 f
,它是 frame
命令的缩写!
关于debugging - 如何检查GDB中函数的返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/267674/