问题描述
在如何在GDB中评估函数的答案?我找到了在程序外部调用函数的方法在GDB中被称为floor
,如下所示:
In an answer to How to evaluate functions in GDB? I found the recipe to call a function outside of my program called floor
from within GDB like this:
(gdb) p floor
$20 = {<text variable, no debug info>} 0x38e10197b0 <floor>
(gdb) p ((double(*)(double))floor)(2.9999)
$21 = 2
(gdb) p ((double(*)(double))floor)(2.000001)
$22 = 2
(gdb)
我需要做些什么,短是编译器升级,目前对我来说这不是 的选项,以便我可以在我将在原始C/C ++文本文件中执行的相同方法,例如:
What do I need to do, short of a compiler upgrade which is not an option for me at the moment, in order for me to call the function in the same manner in which I would do inside the original C/C++ text file, e.g.,:
p floor(2.9999)
具体来说,我想不必必须打开floor
上的手册页以找到功能签名:
Specifically, I would like to not have to open up the man page on floor
to find the function signature:
double floor(double x);
然后编写表达式以馈送给gdb的print
命令,该命令是使用double
返回double
并带有大量括号的指针.
and then concoct an expression to feed to gdb's print
command that is a pointer taking a double
returning a double
, with lots of parentheses.
那么,这是我们在GDB中调用这些类型的低级函数的唯一方法吗?还是我想念的东西?是因为我根本没有加载某种类型的调试符号"或类似的东西吗?上面输出中的参考文献no debug info
使我相信,我的机器可能缺少用于调试符号"的软件包或与之等效的软件包,这些软件包可以让我用本机C或C ++表示出来?
So, is this the only way for us to call these types of low level functions in GDB? Or is there something I'm missing? Is it because I simply don't have some type of "debug symbols" loaded or something like that? Reference no debug info
in the output above that leads me to believe that perhaps my machine is lacking some package for "debug symbols" or the equivalent that would allow me to express this in the native C or C++?
这是专门针对Linux的.我对平台无关的答案不感兴趣,因为它们与我的用例无关(尽管一般而言,仅针对此问题).
This is specifically for Linux. I'm not interested in platform-agnostic answers as they are irrelevant in my use-case (not in general, though, just for this question).
推荐答案
您应该为libc安装libc6-dbg
或类似的调试符号软件包(floor
在libm
中,它是GLIBC的一部分).
You should install libc6-dbg
or similar package of debugging symbols for libc (floor
is in libm
, which is part of GLIBC).
没有调试符号,GDB不知道floor
是什么类型.
Without debug symbols, GDB has no idea what the type of floor
is.
这篇关于如何在不痛苦地进行类型转换的情况下评估GDB中的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!