1

Is it possible to call functions from math.h while using the lldb debugger?

I am trying to debug some math-related iOS code and am getting incorrect results from the Xcode5 debugger:

(lldb) p (double)pow(2., 2.)
(double) $0 = NaN

Another post mentioned that the debugger doesn't know the prototype of the pow function so I also tried casting the function to the correct type but it still didn't work:

(lldb) p ((double(*)(double, double))pow)(2., 2.)
(double) $0 = NaN

However it does work when called from my running Objective C code:

NSLog(@"Power is %f", pow(2., 2.));

2013-12-10 14:41:25.651 Foo[27481:70b] Power is 4.000000
Community
  • 1
  • 1
tboyce12
  • 1,449
  • 14
  • 28
  • It's definitely possible. For example try (lldb) p (double) sin(70.0) ... that works, but for some reason I am unable to get pow to work... – Eric Dec 10 '13 at 23:26
  • Yeah `sin` works for me too, but not all the other math functions. I am specifically interested in using the `log` function in my debugging but it isn't working: `(lldb) p (double)log(1.)` outputs `(double) $0 = NaN`. – tboyce12 Dec 11 '13 at 01:09

1 Answers1

2

What version of Xcode are you using when you're seeing this? Are you seeing this in Xcode 5.0? I'm using something a tiny bit newer and it looks fine debugging an iOS app on an armv7s device:

(lldb) p (double)pow(2.0,2.0)
(double) $0 = 4
(lldb) p (double)log(1.0)
(double) $1 = 0
(lldb) 
Jason Molenda
  • 14,835
  • 1
  • 59
  • 61
  • I'm currently on XCode Version 5.0.2 (5A3005). Can't remember the precise version I was on when I posted this question. Debugging on my device did the trick, but it still doesn't work for me in the simulator. I may not have actually tried it on the device earlier, so thanks for this tip! – tboyce12 Feb 13 '14 at 21:58
  • Interesting, I'll try on the simulator when I get home tonight. – Jason Molenda Feb 13 '14 at 23:32