How to evaluate functions in GDB?

Tim picture Tim · Aug 30, 2009 · Viewed 65.7k times · Source

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

Answer

anon picture anon · Nov 15, 2012

You need to tell gdb that it will find the return value in the floating point registers, not the normal ones, in addition to give the parameters the right types.

I.e.:

(gdb) p ((double(*)())pow)(2.,2.)

$1 = 4