如何检查GDB中函数的返回值? [英] How to inspect the return value of a function in GDB?

查看:163
本文介绍了如何检查GDB中函数的返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在gdb中检查函数的返回值,假定返回值是 not 赋给变量的?

Is it possible to inspect the return value of a function in gdb assuming the return value is not assigned to a variable?

推荐答案

我想有更好的方法来做到这一点,但 finish 命令执行,直到当前堆栈帧被弹出并打印返回值 - 给定程序

I imagine there are better ways to do it, but the finish command executes until the current stack frame is popped off and prints the return value -- given the program

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) 

这篇关于如何检查GDB中函数的返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆