Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode watch 'invalid expression'

I'm stepping through some Swift code in Xcode and I'd like to watch values. Following the advice in many of the answers here (e.g. this one) I can add the expression to the local variables window.

The breakpoint I am on is the last line of this fragment from the Starscream library (by daltoniam) which I include as a pod.

for i in 0..<dataLength {
  buffer[offset] = data[i] ^ maskKey[i % MemoryLayout<UInt32>.size]
  offset += 1
}
var total = 0

I've added two expressions to watch:

  1. buffer[0] and
  2. MemoryLayout<UInt32>.size

For both the value I see is "invalid expression":

xcode screenshot

These expressions are clearly are not invalid, if they were the code would have thrown an exception when they were encountered executing the previous few lines. What am I missing? How should I watch and not get 'invalid expression'

N.B. If I call p buffer[0] from the lldb prompt I get the cryptic error:

(lldb) p buffer[0]
error: warning: :12:9: warning: initialization of variable
'$__lldb_error_result' was never used; consider replacing with assignment to '_'
or removing it
var $__lldb_error_result = __lldb_tmp_error
~~~~^~~~~~~~~~~~~~~~~~~~
_

error: :19:5: error: value of type 'WebSocket' has no member
'$__lldb_wrapped_expr_72' $__lldb_injected_self.$__lldb_wrapped_expr_72( ^~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~

I have tried changing the podfile (as per Jim's answer) so that it explicitly gets the debug code:

pod 'Starscream', '~> 3.0.6', :configuration => 'Debug'

and I have even gone as far as removing the pods, cloning Starscream, and including the source code as a sub-project. I still get the same error.

like image 373
dumbledad Avatar asked Jun 29 '26 15:06

dumbledad


1 Answers

An expression that accesses buffer[0] where buffer is a UnsafeMutablePointer works correctly in the expression parser when I'm stopped in some simple function. And from your experience with the expr command directly, it looks like your problem is not with this particular expression. Rather it looks like there's something about the context you are stopped in that's tripping up the expression parser altogether.

Make sure that you aren't using binary cocoapods's and that you've rebuilt all your code and all the pods you are using have been rebuilt from scratch with the same swift compiler. At present, lldb and swiftc are version locked - lldb can only debug programs built with the swiftc that it ships with.

If that doesn't fix the issue, then we'll need to figure out what about the particular function you are stopped in that's causing the problem. This seems like the sort of thing better dealt with by filing a bug with the swift project (http://bugs.swift.org).

like image 91
Jim Ingham Avatar answered Jul 01 '26 12:07

Jim Ingham