devios1
devios1

Reputation: 37985

Xcode 6 beta 2 debugger not showing variable contents after call to String.componentsSeparatedByString

For some reason LLDB is not showing me the contents of variables while I am stepping through my Swift code. The actual execution works fine, but no matter what I try I can't see the contents of my strings!

Here's what I see in the variable list:

enter image description here

At this point type contains "name" and value contains "Logan". But you wouldn't be able to tell that looking here. If I use the "quick look" button, it says the value is "(None)".

And I get this kind of gibberish when I try to po a String from the console:

(lldb) po space
error: <REPL>:1:1: error: non-nominal type '$__lldb_context' cannot be extended
extension $__lldb_context {                            
^
<REPL>:11:5: error: 'Space.Type' does not have a member named '$__lldb_wrapped_expr_0'
    $__lldb_injected_self.$__lldb_wrapped_expr_0(     
    ^     

However this varies. Sometimes I'll get something like:

class name = __NSAtom

or

Printing description of [0]:
(String) [0] = {
  core = {
    _baseAddress = Builtin.RawPointer = 0x00000001004016f0
    _countAndFlags = -4611686018427387894
    _owner = Some {
      Some = (instance_type = Builtin.RawPointer = 0x0000000100401820 -> 0x00007fff7b3d5390 (void *)0x00007fff7b3d5340: __NSCFString)
    }
  }
}

or

Printing description of declaration:
(String) declaration = <DW_OP_piece for offset 8: top of stack is not a piece>

...but never the actual contents of the string!

Update:

I've noticed the problem only seems to start occurring once a call to componentsSeparatedByString() is made in the function. (This happens right at the top so as I was stepping I didn't notice that the debugger actually does show the value until this point.) So something weird is going on with that function. I've updated the question title to reflect this new information.

Interestingly, it seems once the string has been "corrupted" by this call, you can't view it anywhere else, even when passed to a different function. And any regular string variables are not viewable either. Definitely a bug, but I wonder if there's a workaround. It's getting really hard to debug my program!

Upvotes: 12

Views: 5070

Answers (3)

Maury Markowitz
Maury Markowitz

Reputation: 9273

I'd like to add an update: this problem still occurs in the latest versions of Xcode, both 6.2 release and 6.3 beta.

The problem is part of componentsSeparatedByString, and if you replace that with split everything works fine. I had four instances of this, and as soon as I changed them my app stopped crashing with a Zombie release of NSString, and all my variable names started working. I changed things like this...

let bits = value!.componentsSeparatedByString(" ")

with...

let bits = split(value!, { $0 == " "}, maxSplit: Int.max, allowEmptySlices: false)

I don't think split is nearly as readable, but at least it works!

Upvotes: 1

j berkman
j berkman

Reputation: 19

(note that you do not want to do NSLog("(someVariable)") as the expanded string could contain % format sequences - use NSLog("%@", "(someVariable)") or NSLog("%@", someVariable) instead)

Upvotes: 1

Dan McClain
Dan McClain

Reputation: 11920

When I've been encountering this, I've used either NSLog("\(myThing)") in the compiled code I want to debug, or have been calling expression NSLog("\(myThing)") while in the debugger's REPL

Upvotes: 2

Related Questions