We use Buck as our swift application build system and we are getting some intermittent behaviors while debugging the app with LLDB.
When stopping at some breakpoints and running a po
with some instance value of self we're getting this:
(lldb) po self.customView
error: Couldn't realize type of self.
Searching for some more information about the error with log enable lldb types expr
that's what I get for this case:
== [UserExpression::Evaluate] Parsing expression self.customView ==
SwiftASTContextForExpressions::GetModule("Swift")
SwiftUserExpression::ScanContext()
[SUE::SC] Compilation unit is swift
SwiftASTContext("CoolApplication")::ReconstructType("$s26CoolModulePresentation0A18MenuViewControllerCD")
SwiftASTContext("CoolApplication")::ReconstructType("$s26CoolModulePresentation0A18MenuViewControllerCD") -- found in the negative cache
could not get type metadata from address 4628814032 : an unknown failure occurred
SwiftASTContext("CoolApplication")::ReconstructType("$s26CoolModulePresentation0A18MenuViewControllerCD")
SwiftASTContext("CoolApplication")::ReconstructType("$s26CoolModulePresentation0A18MenuViewControllerCD") -- found in the negative cache
[SUE::SC] Containing class name: CoolModulePresentation.CoolMenuViewController
Parsing the following code:
extension $__lldb_context {
@LLDBDebuggerFunction @available(iOS 14.5, *)
final func $__lldb_wrapped_expr_0(_ $__lldb_arg : UnsafeMutablePointer<Any>) {
do {
/*__LLDB_USER_START__*/
self.customView
/*__LLDB_USER_END__*/
} catch (let __lldb_tmp_error) {
var $__lldb_error_result = __lldb_tmp_error
}
... (thousand lines of loading/linking every application module)
...
SwiftASTContext("CoolApplication")::ReconstructType("$s26CoolModulePresentation0A18MenuViewControllerCD")
SwiftASTContext("CoolApplication")::ReconstructType("$s26CoolModulePresentation0A18MenuViewControllerCD") -- found in the negative cache
SwiftASTContextForExpressions::ReconstructType("$s26CoolModulePresentation0A18MenuViewControllerCD")
SwiftASTContextForExpressions::ReconstructType("$s26CoolModulePresentation0A18MenuViewControllerCD") -- not cached, searching
SwiftASTContextForExpressions::SwiftDWARFImporterDelegate::lookupValue("CoolMenuViewController")
SwiftASTContext("CoolApplication")::SwiftDWARFImporterDelegate::lookupValue("CoolMenuViewController")
thousands of ...SwiftDWARFImporterDelegate::lookupValue("CoolMenuViewController") on each application module
After some clean builds with no change in the codebase or build process, finally get some successful response:
(lldb) po self.customView
<SomeCoolModulePresentation.MenuView: 0x7fbea0883fa0; frame = (0 0; 0 0); layer = <CALayer: 0x600002f65e40>>
Lldb types expr log:
== [UserExpression::Evaluate] Parsing expression self.customView ==
SwiftASTContextForExpressions::GetModule("Swift")
SwiftUserExpression::ScanContext()
[SUE::SC] Compilation unit is swift
SwiftASTContext("CoolApplication")::ReconstructType("$s26SomeCoolModulePresentation0A18MenuViewControllerCD")
SwiftASTContext("CoolApplication")::ReconstructType("$s26SomeCoolModulePresentation0A18MenuViewControllerCD") -- found in the positive cache
[self 0x7fa00a27a000] might have a dynamic type
[self 0x7fa00a27a000] has a new dynamic type SomeCoolModulePresentation.MenuViewController
[SUE::SC] Containing class name: SomeCoolModulePresentation.MenuViewController
Parsing the following code:
extension $__lldb_context {
@LLDBDebuggerFunction @available(iOS 14.5, *)
final func $__lldb_wrapped_expr_3(_ $__lldb_arg : UnsafeMutablePointer<Any>) {
do {
/*__LLDB_USER_START__*/
self.customView
/*__LLDB_USER_END__*/
} catch (let __lldb_tmp_error) {
var $__lldb_error_result = __lldb_tmp_error
}
(thousand lines of loading/linking every application module)
-- EXPR evaluation generated raw sil --
-- EXPR evaluation generated canonical sil --
-- EXPR evaluation generated IR --
Registering JITted Functions:
Function: s26CoolModulePresentation0A18MenuViewControllerC14__lldb_expr_10E03$__g9_wrapped_H2_4yySpyypGF at 0x16be209c0.
Function: __swift_destroy_boxed_opaque_existential_0 at 0x16be20a80.
Function: $sSSWOh at 0x16be20ab0.
Registering JIIted Symbols:
== [UserExpression::Evaluate] Executing expression ==
IRMemoryMap::Malloc process_sp=0x7fa0f50d7a18, process_sp->CanJIT()=true, process_sp->IsAlive()=true
IRMemoryMap::Malloc (39, 0x8, 0x3, eAllocationPolicyMirror) -> 0x16bca2ed0
EntityVariable::Materialize [address = 0x16bca2ed0, m_variable_sp = self]
SwiftASTContextForExpressions::ReconstructType("$s26SomeCoolModulePresentation0A18MenuViewControllerCD")
...
SwiftASTContextForExpressions::ReconstructType("$s26SomeCoolModulePresentation0A18MenuViewControllerCD") -- found in the positive cache
SwiftASTContextForExpressions::ReconstructType("$s26SomeCoolModulePresentation0A16MenuViewProtocol_pD")
...
SwiftASTContextForExpressions::ReconstructType("$s26SomeCoolModulePresentation0A16MenuViewProtocol_pD") -- found in the positive cache
[$R1 0x7fa021f93200] might have a dynamic type
After cleaning the caches/derived data and running a new build the problem returned to appear. My limited knowledge about swift and lldb integration doesn't let me figure out what's different between those two cases.
The app codebase is Swift with some pre-built third-party libs (swift, obj-c, c++). To deal with Buck relative paths and be able to set breakpoints we're using some settings set target.source-map
.
We're not generating dsym files to debug, only using object files embedded DWARF (only generating dsyms to symbolicate crashes). But, by generating dsym files we're getting a different error output:
(lldb) po self.customView
error: Couldn't lookup symbols:
direct field offset for SomeCoolModulePresentation.CoolMenuViewController.customView : SomeCoolModulePresentation.CoolMenuViewProtocol