How to evaluate functions in GDB without painful typecasting?

孤者浪人 提交于 2020-06-01 03:40:04

问题


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) 

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)

Specifically, I would like to not have to open up the man page on floor to find the function signature:

double floor(double x);

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.

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++?

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).


回答1:


What do I need to do

You should install libc6-dbg or similar package of debugging symbols for libc (floor is in libm, which is part of GLIBC).

Without debug symbols, GDB has no idea what the type of floor is.



来源:https://stackoverflow.com/questions/60839314/how-to-evaluate-functions-in-gdb-without-painful-typecasting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!