Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

po Swift String "unresolved identifier"

Tags:

swift

lldb

I am having trouble debugging Swift Strings

func stringTest() {

    let test1:String =   "test1";
    let test2:NSString = "test2";

    // <-- Breakpoint here

    println(test1);
    println(test2);
}

If I set a breakpoint after these lines and try and print test1 I get the following error:

po test1
error: <REPL>:1:1: error: use of unresolved identifier 'test1'
test1
^

But I am able to print test2 successfully:

po test2
test2
like image 259
Errortype520 Avatar asked Jun 19 '14 14:06

Errortype520


2 Answers

It is a bug of Beta. Xcode6-Beta5 has still this bug. You can only get debug info for swift's variables, but can't get it for swift's constants. Temporarily you can change let test1 to var test1 and you will got debug info. Hope this will be fixed in release version. Good Luck in debugging ;)

EDIT: Unfortunately, the same issue is still happening in first release of Xcode Version 6.0.1 (6A317)

let test1:String  -> debug info is unavailable
var test1:String  -> debug info is available

EDIT2: Yes, confirmed. It is fixed also for iOS apps in the latest Xcode 6.1 under OS X Yosemite.

like image 61
slamor Avatar answered Dec 07 '22 09:12

slamor


This is most likely a bug in the debug information output. You can check this by grabbing the PC, for instance from register read pc, and then doing:

(lldb) image lookup -va <PC VALUE>

That will print a bunch of stuff, but the last entries will be all the variables currently visible to the debugger, and where they live (in registers or memory.) If you don't see the variable there, then the debug information must have told lldb that the variable is not currently live.

If you can reproduce this in some example code you can make available, please file a bug with bug reporter.apple.com.

like image 28
Jim Ingham Avatar answered Dec 07 '22 09:12

Jim Ingham