How to evaluate functions in GDB?

前端 未结 5 833
北海茫月
北海茫月 2020-12-03 01:18

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,         


        
5条回答
  •  臣服心动
    2020-12-03 01:33

    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
    

提交回复
热议问题