16

Why doesn't this work?

(lldb) po [NSString stringWithFormat:@"%f", 1.0]
error: too many arguments to method call, expected 1, have 2
error: 1 errors parsing expression

But this does:

(lldb) p (void)printf("%f", 1.0)
1.000000

Is Objective-C variable arguments syntax not supported in LLDB?

Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213

2 Answers2

22

As Martin R pointed out in the comments, it's apparently a general LLDB issue with variable argument lists.

On the other hand, as Patrik Schmittat pointed out, -initWithFormat: works just fine:

(lldb) po [[NSString alloc] initWithFormat:@"%f", 1.0]
1.000000

I've filed a radar for this: rdar://15261415 (stringWithFormat not working in LLDB)

Community
  • 1
  • 1
Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
2
Basically this is the bug in lldb, if you try the same in gdb it works. 
lldb is only passing the low 32 bits of the argument.

Please follow this link Strange behaviours with stringWithFormat float

Also samthing i have tried in GDB and its work fine as attached in the screens shot:- enter image description here

Now i tried the samething in GDB:- enter image description here

Community
  • 1
  • 1
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56