I'm currently investigating a lldb regression on Xcode 12.5. The actual code involves complicated Swift logics: many levels of generic, protocols, extensions, etc, so I haven't figured out how to reproduce in a small sample code.
Here is what happens. po self
(or po
other local variables) doesn't work at certain breakpoints using Xcode 12.5. Below is the error message. For the same breakpoints, Xcode 12.4 works just fine.
(lldb) po self
error: warning: <EXPR>:11:7: 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: <EXPR>:19:5: error: cannot find '$__lldb_injected_self' in scope
$__lldb_injected_self.$__lldb_wrapped_expr_6(
^~~~~~~~~~~~~~~~~~~~~
If I understand correctly, when evaluating an expression, lldb
generates some code and compile it. The above error happens on compiling the generated code.
extension $__lldb_context {
@LLDBDebuggerFunction @available(iOS 14.5, *)
final func $__lldb_wrapped_expr_6(_ $__lldb_arg : UnsafeMutablePointer<Any>) {
do {
/*__LLDB_USER_START__*/
self
/*__LLDB_USER_END__*/
} catch (let __lldb_tmp_error) {
var $__lldb_error_result = __lldb_tmp_error
}
}
}
@available(iOS 14.5, *)
func $__lldb_expr(_ $__lldb_arg : UnsafeMutablePointer<Any>) {
do {
$__lldb_injected_self.$__lldb_wrapped_expr_6(
$__lldb_arg
)
}
}
I compared the lldb log (log enable lldb expr
) between a working breakpoint and a broken one, and found that, at the working breakpoint, lldb inserted __lldb_injected_self
while for the broken breakpoint it didn't. This explains why the error "cannot find '$__lldb_injected_self' in scope" because it's not inserted.
[SwiftASTManipulator::AddExternalVariables] Injected variable (var_decl implicit range=[<EXPR>:17:62 - line:17:62] "$__lldb_injected_self" type='SomeType<SomeGenericType>' interface type='SomeType<SomeGenericType>' access=public readImpl=stored writeImpl=stored readWriteImpl=stored)
I also noticed some weirdness of the frame: self=<unavailable>
and self = <Unable to determine byte size
. It may be worh mentioning we have -Onone
set.
(lldb) frame info
frame #0: 0x0000000113be3cd8 ExploreSectionPlugins`ExploreValuePropsSectionPluginV3.itemModels(section=$s23ExploreModelsFoundation0A20SearchResultsSectionVy0aF7Plugins0a10ValuePropsF8FragmentVGD @ 0x00007ffee082e8c8, context=0x0000000000000000, self=<unavailable>) at ExploreValuePropsSectionPluginV3.swift:47:5
(lldb) frame variable self
(ExploreSectionPlugins.ExploreValuePropsSectionPluginV3<Dependencies>) self = <Unable to determine byte size.>
After following along the lldb source code, it looks here is where the __lldb_injected_self
should be inserted, but I hit a wall there and didn't know what to do next.
How can I gather more information about this? I hope to figure out a sample code to repro the issue and potentially file a bug report. Any tips, suggestions and advices are appreciated!