简体   繁体   English

Xcode观看“无效表达式”

[英]Xcode watch 'invalid expression'

I'm stepping through some Swift code in Xcode and I'd like to watch values. 我正在逐步完成Xcode中的一些Swift代码,我想观察值。 Following the advice in many of the answers here (eg 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. 我所处的断点是Starscream库 (由daltoniam编写 )中该片段的最后一行,我将其包括为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 buffer[0]
  2. MemoryLayout<UInt32>.size

For both the value I see is "invalid expression": 对于我看到的两个值都是“无效表达式”:

xcode屏幕截图

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' 我应该如何看,而不要得到“无效的表达”

NB If I call p buffer[0] from the lldb prompt I get the cryptic error: 注意:如果我从lldb提示符下调用p buffer[0] ,则会收到错误消息:

(lldb) p buffer[0] (lldb)p缓冲区[0]
error: warning: :12:9: warning: initialization of variable 错误:警告::12:9:警告:变量初始化
'$__lldb_error_result' was never used; 从未使用过'$ __ lldb_error_result'; consider replacing with assignment to '_' 考虑替换为“ _”
or removing it 或将其删除
var $__lldb_error_result = __lldb_tmp_error var $ __ lldb_error_result = __lldb_tmp_error
~~~~^~~~~~~~~~~~~~~~~~~~ ~~~~ ^ ~~~~~~~~~~~~~~~~~~~
_ _

error: :19:5: error: value of type 'WebSocket' has no member 错误:: 19:5:错误:“ WebSocket”类型的值没有成员
'$__lldb_wrapped_expr_72' $__lldb_injected_self.$__lldb_wrapped_expr_72( ^~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~ '$ __ 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: 我尝试过更改podfile(根据Jim的answer ),以便它明确获得调试代码:

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. 我什至在移除吊舱,克隆Starscream以及将源代码包括在子项目中方面都做了很大的努力。 I still get the same error. 我仍然遇到相同的错误。

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. 当我在某些简单函数中停止时,访问buffer[0]其中buffer是UnsafeMutablePointer)的表达式在表达式解析器中可以正常工作。 And from your experience with the expr command directly, it looks like your problem is not with this particular expression. 从您直接使用expr命令的经验来看,您的问题似乎不在于此特定表达式。 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. 确保您没有使用二进制cocoapods,并且已经重建了所有代码,并且所使用的所有pod已经使用相同的快速编译器从头开始重建。 At present, lldb and swiftc are version locked - lldb can only debug programs built with the swiftc that it ships with. 目前,lldb和swiftc已被版本锁定-lldb只能调试使用其随附的swiftc构建的程序。

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 ). 通过在swift项目( http://bugs.swift.org )中提交错误,似乎可以更好地解决这种问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM