如何评估GDB中的函数? [英] How to evaluate functions in GDB?

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

问题描述

我想知道为什么评估函数在gdb中不起作用?在我的源文件中,我包括,当在gdb中调试时,这些示例是错误的评估。

 (gdb)p pow(3, 2)

$ 10 = 1

(gdb)p pow(3,3)

$ 11 = 1

(gdb)p sqrt(9)

$ 12 = 0


解决方案

我的猜测是编译器和链接器对这些特定的函数有一些魔力。最有可能提高性能。

如果您确实需要 c> pow()在gdb中可用,那么您可以创建自己的包装函数: / b>

  double mypow(double a,double b)
{
return pow(a,b);
}

也许还会将它包装到 #ifdef DEBUG 或者别的东西不要混乱最终的二进制文件。



顺便说一句,你会注意到其他库函数可以被调用(和它们的返回值被打印),例如:

 (gdb)print printf(hello world)
$ 4 = 11


I wonder why evaluate function doesn't work in gdb? In my source file I include, when debugging in gdb, these examples are wrong evaluations.

(gdb) p pow(3,2)

$10 = 1

(gdb) p pow(3,3)

$11 = 1

(gdb) p sqrt(9)

$12 = 0

解决方案

My guess is that the compiler and linker does some magic with those particular functions. Most likely to increase performance.

If you absolutely need pow() to be available in gdb then you can create your own wrapper function:

double mypow(double a, double b)
{
    return pow(a,b);
}

Maybe also wrap it into a #ifdef DEBUG or something to not clutter the final binary.

BTW, you will notice that other library functions can be called (and their return value printed), for instance:

(gdb) print printf("hello world")
$4 = 11

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

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