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

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

问题描述

假设返回值分配给变量,是否可以检查 gdb 中函数的返回值?

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) 

finish 命令可以缩写为 fin.不要使用 f,它是 frame 命令的缩写!

The finish command can be abbreviated as fin. Do NOT use the f, which is abbreviation of frame command!

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

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