Currently when I try to debug some libraries with LLDB and see the values of variables I get errors of the form failed to get module "XXX" from AST context. I read in another thread that I should try passing -Xfrontend -serialize-debugging-options when compiling. Is there a way to do that with SwiftPM when I call swift build? If not, what else could be causing these errors?
I would recommend trying to figure out why the module couldn't be imported first. In very new versions of LLDB the underlying error should be printed to the lldb console, on older versions, putting "log enable lldb types" into ~/.lldbinit should surface the underlying error.
@Adrian_Prantl thanks for the prompt response! I actually tried that but don't know how to interpret the result. I have attached it in the end of this reply. I want also point out that everything works fine within Xcode. The issue I am describing has to do with using LLDB from either the command-line or VS code. I do not really understand why Xcode would work fine but LLDB directly would not.
The log you mentioned is (example after trying to set a breakpoint):
SwiftASTContext("ReinforcementLearningExperiments")::CreateInstance() -- Corresponding source not found for /Users/eaplatanios/Development/GitHub/retro-swift/_Builtin_stddef_max_align_t, loading module is unlikely to succeed
SwiftASTContext("ReinforcementLearningExperiments")::SetTriple("x86_64-apple-macosx10.14.0") setting to "x86_64-apple-macosx10.14.0"
SwiftASTContext("ReinforcementLearningExperiments")::SetTriple("x86_64-apple-macosx10.14.0") setting to "x86_64-apple-macosx10.14.0"
SwiftASTContext("ReinforcementLearningExperiments")::DeserializeAllCompilerFlags() -- Found 0 AST file data entries.
SwiftASTContext("ReinforcementLearningExperiments")::CreateInstance() -- Found serialized triple x86_64-apple-macosx10.14.0.
SwiftASTContext("ReinforcementLearningExperiments")::SetTriple("x86_64-apple-macosx10.14.0") setting to "x86_64-apple-macosx10.14.0"
SwiftASTContext("ReinforcementLearningExperiments")::CreateInstance() -- No serialized SDK path.
SwiftASTContext::GetResourceDir() -- trying ePathTypeSwiftDir: /Users/eaplatanios/Development/GitHub/swift-source-temp/build/buildbot_osx/lldb-macosx-x86_64/bin/LLDB.framework/Resources/Swift
SwiftASTContext::GetResourceDir() -- found Swift resource dir via ePathTypeSwiftDir': /Users/eaplatanios/Development/GitHub/swift-source-temp/build/buildbot_osx/lldb-macosx-x86_64/bin/LLDB.framework/Resources/Swift
SwiftASTContext("ReinforcementLearningExperiments")::GetASTContext() -- Using clang module cache path: /var/folders/lz/kkv6ld7j5q94nvrrywz5_8w00000gn/C/org.llvm.clang.eaplatanios/ModuleCache
SwiftASTContext("ReinforcementLearningExperiments")::GetASTContext() -- Using prebuilt module cache path: /Users/eaplatanios/Development/GitHub/swift-source-temp/build/buildbot_osx/lldb-macosx-x86_64/bin/LLDB.framework/Resources/Swift/macosx/prebuilt-modules
SwiftASTContext("ReinforcementLearningExperiments")::RegisterSectionModules("ReinforcementLearningExperiments") retrieved 0 AST Data blobs from the symbol vendor.
SwiftASTContext("ReinforcementLearningExperiments")::CreateInstance((Module*)0x7fce47d01c88, "ReinforcementLearningExperiments") = 0x7fcde7883560
SwiftASTContext("ReinforcementLearningExperiments")::LogConfiguration(SwiftASTContext*)0x7fcde7883560:
Architecture : x86_64-apple-macosx10.14.0
SDK path : /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk
Runtime resource path : /Users/eaplatanios/Development/GitHub/swift-source-temp/build/buildbot_osx/lldb-macosx-x86_64/bin/LLDB.framework/Resources/Swift
Runtime library path : /Users/eaplatanios/Development/GitHub/swift-source-temp/build/buildbot_osx/lldb-macosx-x86_64/bin/LLDB.framework/Resources/Swift/macosx
Runtime library import paths : (1 items)
/Users/eaplatanios/Development/GitHub/swift-source-temp/build/buildbot_osx/lldb-macosx-x86_64/bin/LLDB.framework/Resources/Swift/macosx
Framework search paths : (0 items)
Import search paths : (0 items)
Extra clang arguments : (0 items)
SwiftASTContext("ReinforcementLearningExperiments")::GetTypeFromMangledTypename("$s21ReinforcementLearning8PPOAgentV6update5usingSfAA10TrajectoryVy5InputQy_11ActionSpace_5ValueQZ10TensorFlow0K0VySfG5StateQy_G_tF")
SwiftASTContext("ReinforcementLearningExperiments")::GetTypeFromMangledTypename("$s21ReinforcementLearning8PPOAgentV6update5usingSfAA10TrajectoryVy5InputQy_11ActionSpace_5ValueQZ10TensorFlow0K0VySfG5StateQy_G_tF") -- not cached, searching
SwiftASTContext("ReinforcementLearningExperiments")::GetTypeFromMangledTypename("$s21ReinforcementLearning8PPOAgentV6update5usingSfAA10TrajectoryVy5InputQy_11ActionSpace_5ValueQZ10TensorFlow0K0VySfG5StateQy_G_tF")
SwiftASTContext("ReinforcementLearningExperiments")::GetModule("")
SwiftASTContext("ReinforcementLearningExperiments")::GetModule((FileSpec)"") -- no basename
SwiftASTContext("ReinforcementLearningExperiments")::GetModule("")
SwiftASTContext("ReinforcementLearningExperiments")::GetModule((FileSpec)"") -- no basename
SwiftASTContext("ReinforcementLearningExperiments")::GetModule("")
SwiftASTContext("ReinforcementLearningExperiments")::GetModule((FileSpec)"") -- no basename
Breakpoint 1: where = ReinforcementLearningExperiments`ReinforcementLearning.PPOAgent.update(using: ReinforcementLearning.Trajectory<Network.Input, Environment.ActionSpace.Value, TensorFlow.Tensor<Swift.Float>, Network.State>) -> Swift.Float + 8542 at PolicyGradientAgents.swift:484:28, address = 0x000000010002f7ee
I can also confirm the same thing happens when building swift-lldb from the latest stable branch. What surprises me is that this only happens when working from the command-line or vscode, but not when working with xcode. And it happens when I use the lldb executable provided either by the xcode installation or the Swift for TensorFlow toolchain I used to build my project.
I don't think I know anything helpful about your overall question, but I can tell you how to pass these args to swiftpm: swift build -Xswiftc -Xfrontend -Xswiftc -serialize-debugging-options.
Thanks Marc! I tried adding the flags but I still get the same error when I try to inspect variables. @Adrian_Prantl do you have any suggestions of what I could try?
@Adrian_Prantl I obtained some more information from the log in case it helps. First of all, if I do image list when lldb starts I see that it does load something for my library:
However, when I hit the breakpoint and run po loss (where loss is the name of a variable), I see lots of stuff in the log, but I copied here some that looked relevant:
SwiftASTContextForExpressions::RegisterSectionModules("ReinforcementLearningExperiments") retrieved 0 AST Data blobs from the symbol vendor.
...
SwiftASTContextForExpressions::CreateInstance((Target*)0x7f8ebe8c7600) = 0x7f8e3de07be0
SwiftASTContextForExpressions::LogConfiguration(SwiftASTContext*)0x7f8e3de07be0:
Architecture : x86_64-apple-macosx10.14.0
SDK path : /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk
Runtime resource path : /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift
Runtime library path : /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx
Runtime library import paths : (1 items)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx
Framework search paths : (0 items)
Import search paths : (0 items)
Extra clang arguments : (0 items)
SwiftASTContextForExpressions::GetModule("Swift")
SwiftASTContextForExpressions::GetModule("Swift") -- found Swift
...
SwiftASTContextForExpressions::() -- Loading link library "swiftCore" of kind: 0.
SwiftASTContextForExpressions::LoadLibraryUsingPaths() -- Skipping swift standard library "swiftCore" - we don't hand load that one.
SwiftASTContextForExpressions::GetModule("ReinforcementLearning")
SwiftASTContextForExpressions::GetModule() -- failed with no error
SwiftASTContextForExpressions::GetModule("Swift")
SwiftASTContextForExpressions::() -- Loading link library "swiftCore" of kind: 0.
SwiftASTContextForExpressions::LoadLibraryUsingPaths() -- Skipping swift standard library "swiftCore" - we don't hand load that one.
SwiftASTContextForExpressions::GetModule("ReinforcementLearning")
SwiftASTContextForExpressions::GetModule() -- failed with no error
SwiftASTContextForExpressions::GetModule("Swift")
SwiftASTContextForExpressions::() -- Loading link library "swiftCore" of kind: 0.
SwiftASTContextForExpressions::LoadLibraryUsingPaths() -- Skipping swift standard library "swiftCore" - we don't hand load that one.
SwiftASTContextForExpressions::GetModule("ReinforcementLearning")
SwiftASTContextForExpressions::GetModule() -- failed with no error
SwiftASTContext("ReinforcementLearningExperiments")::GetTypeFromMangledTypename("$s21ReinforcementLearning8PPOAgentVyxq_q0_GD")
SwiftASTContext("ReinforcementLearningExperiments")::GetTypeFromMangledTypename("$s21ReinforcementLearning8PPOAgentVyxq_q0_GD") -- found in the negative cache
...
SwiftASTContextForExpressions::GetModule("ReinforcementLearning")
SwiftASTContextForExpressions::GetModule() -- failed with no error
error: warning: failed to get module "ReinforcementLearning" from AST context
error: in auto-import:
failed to get module "ReinforcementLearning" from AST context
Is that information any useful in determining what's wrong?
Sorry for the delayed and superficial response; I am traveling at the moment. What I would look for is an error message that looks like it was produced by Clang (i.e., a line starting with "error:".
@Adrian_Prantl sorry for not responding earlier. This is the only log with errors I was able to find when trying to evaluate an array of tensors:
expression produced error: error: warning: failed to get module \"ArcadeLearningEnvironment\" from AST context
error: in auto-import:",type="ShapedArray<UInt8>",thread-id="1",has_more="0"
expression produced error: error: warning: failed to get module \"ArcadeLearningEnvironment\" from AST context
error: in auto-import:",has_more="0"},child={name="var4.[1]",exp="[1]",numchild="1",type="Tensor<UInt8>",thread-id="1",value="
expression produced error: error: warning: failed to get module \"ArcadeLearningEnvironment\" from AST context
error: in auto-import:",has_more="0"},child={name="var4.[2]",exp="[2]",numchild="1",type="Tensor<UInt8>",thread-id="1",value="
expression produced error: error: warning: failed to get module \"ArcadeLearningEnvironment\" from AST context
error: in auto-import:",has_more="0"},child={name="var4.[3]",exp="[3]",numchild="1",type="Tensor<UInt8>",thread-id="1",value="
expression produced error: error: warning: failed to get module \"ArcadeLearningEnvironment\" from AST context
error: in auto-import:",has_more="0"}],has_more="0"
@Adrian_Prantl I found out something interesting. If I run swift build -Xlinker -add_ast_path -Xlinker .build/debug/ArcadeLearningEnvironmentExperiments.swiftmodule -Xlinker -add_ast_path -Xlinker .build/debug/ReinforcementLearning.swiftmodule -Xlinker -add_ast_path -Xlinker .build/debug/Logging.swiftmodule this after swift build, then I am able to get a step further and see some of the variable values, but then LLDB crashes unexpectedly. Also, some breakpoints are never hit. Do you think this may be a SwiftPM issue rather than an LLDB issue?
This also makes me think that this may be related to this issue.
I think I found out what causes the LLDB crash in VSCode. When I try to debug the same program in XCode I see this log:
warning: Swift error in fallback scratch context: /System/Library/Frameworks/CoreGraphics.framework/Headers/CGDisplayConfiguration.h:12:10: note: while building module 'IOKit' imported from /System/Library/Frameworks/CoreGraphics.framework/Headers/CGDisplayConfiguration.h:12:
#include <IOKit/IOKitLib.h>
^
<module-includes>:30:9: note: in file included from <module-includes>:30:
#import "Headers/graphics/IOGraphicsLib.h"
^
/System/Library/Frameworks/IOKit.framework/Headers/graphics/IOGraphicsLib.h:32:10: note: in file included from /System/Library/Frameworks/IOKit.framework/Headers/graphics/IOGraphicsLib.h:32:
#include <IOKit/graphics/IOFramebufferShared.h>
^
warning: /System/Library/Frameworks/IOKit.framework/Headers/graphics/IOFramebufferShared.h:180:5: warning: 'OSSpinLock' is deprecated: first deprecated in macOS 10.12 - Use os_unfair_lock() from <os/lock.h> instead
OSSpinLock cursorSema;
^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/libkern/OSSpinLockDeprecated.h:79:17: note: 'OSSpinLock' has been explicitly marked deprecated here
typedef int32_t OSSpinLock OSSPINLOCK_DEPRECATED_REPLACE_WITH(os_unfair_lock);
^
/System/Library/Frameworks/CoreGraphics.framework/Headers/CGDisplayConfiguration.h:12:10: note: while building module 'IOKit' imported from /System/Library/Frameworks/CoreGraphics.framework/Headers/CGDisplayConfiguration.h:12:
#include <IOKit/IOKitLib.h>
^
<module-includes>:33:9: note: in file included from <module-includes>:33:
#import "Headers/graphics/IOGraphicsEngine.h"
^
warning: /System/Library/Frameworks/IOKit.framework/Headers/graphics/IOGraphicsEngine.h:32:5: warning: 'OSSpinLock' is deprecated: first deprecated in macOS 10.12 - Use os_unfair_lock() from <os/lock.h> instead
OSSpinLock contextLock;
^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/libkern/OSSpinLockDeprecated.h:79:17: note: 'OSSpinLock' has been explicitly marked deprecated here
typedef int32_t OSSpinLock OSSPINLOCK_DEPRECATED_REPLACE_WITH(os_unfair_lock);
^
/System/Library/Frameworks/CoreGraphics.framework/Headers/CGDisplayConfiguration.h:12:10: note: while building module 'IOKit' imported from /System/Library/Frameworks/CoreGraphics.framework/Headers/CGDisplayConfiguration.h:12:
#include <IOKit/IOKitLib.h>
^
<module-includes>:46:9: note: in file included from <module-includes>:46:
#import "Headers/hidsystem/IOHIDLib.h"
^
/System/Library/Frameworks/IOKit.framework/Headers/hidsystem/IOHIDLib.h:33:10: note: in file included from /System/Library/Frameworks/IOKit.framework/Headers/hidsystem/IOHIDLib.h:33:
#include <IOKit/hidsystem/IOHIDShared.h>
^
warning: /System/Library/Frameworks/IOKit.framework/Headers/hidsystem/IOHIDShared.h:59:5: warning: 'OSSpinLock' is deprecated: first deprecated in macOS 10.12 - Use os_unfair_lock() from <os/lock.h> instead
OSSpinLock sema; /* Is high-level code reading this event now? */
^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/libkern/OSSpinLockDeprecated.h:79:17: note: 'OSSpinLock' has been explicitly marked deprecated here
typedef int32_t OSSpinLock OSSPINLOCK_DEPRECATED_REPLACE_WITH(os_unfair_lock);
^
/System/Library/Frameworks/CoreGraphics.framework/Headers/CGDisplayConfiguration.h:12:10: note: while building module 'IOKit' imported from /System/Library/Frameworks/CoreGraphics.framework/Headers/CGDisplayConfiguration.h:12:
#include <IOKit/IOKitLib.h>
^
<module-includes>:46:9: note: in file included from <module-includes>:46:
#import "Headers/hidsystem/IOHIDLib.h"
^
/System/Library/Frameworks/IOKit.framework/Headers/hidsystem/IOHIDLib.h:33:10: note: in file included from /System/Library/Frameworks/IOKit.framework/Headers/hidsystem/IOHIDLib.h:33:
#include <IOKit/hidsystem/IOHIDShared.h>
^
warning: /System/Library/Frameworks/IOKit.framework/Headers/hidsystem/IOHIDShared.h:121:5: warning: 'OSSpinLock' is deprecated: first deprecated in macOS 10.12 - Use os_unfair_lock() from <os/lock.h> instead
OSSpinLock cursorSema; /* set to disable periodic code */
^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/libkern/OSSpinLockDeprecated.h:79:17: note: 'OSSpinLock' has been explicitly marked deprecated here
typedef int32_t OSSpinLock OSSPINLOCK_DEPRECATED_REPLACE_WITH(os_unfair_lock);
^
/System/Library/Frameworks/CoreGraphics.framework/Headers/CGDisplayConfiguration.h:12:10: note: while building module 'IOKit' imported from /System/Library/Frameworks/CoreGraphics.framework/Headers/CGDisplayConfiguration.h:12:
#include <IOKit/IOKitLib.h>
^
<module-includes>:46:9: note: in file included from <module-includes>:46:
#import "Headers/hidsystem/IOHIDLib.h"
^
/System/Library/Frameworks/IOKit.framework/Headers/hidsystem/IOHIDLib.h:33:10: note: in file included from /System/Library/Frameworks/IOKit.framework/Headers/hidsystem/IOHIDLib.h:33:
#include <IOKit/hidsystem/IOHIDShared.h>
^
warning: /System/Library/Frameworks/IOKit.framework/Headers/hidsystem/IOHIDShared.h:149:5: warning: 'OSSpinLock' is deprecated: first deprecated in macOS 10.12 - Use os_unfair_lock() from <os/lock.h> instead
OSSpinLock waitCursorSema; /* protects wait cursor fields */
^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/libkern/OSSpinLockDeprecated.h:79:17: note: 'OSSpinLock' has been explicitly marked deprecated here
typedef int32_t OSSpinLock OSSPINLOCK_DEPRECATED_REPLACE_WITH(os_unfair_lock);
^
/System/Library/Frameworks/Foundation.framework/Headers/NSURLCredential.h:9:9: note: while building module 'Security' imported from /System/Library/Frameworks/Foundation.framework/Headers/NSURLCredential.h:9:
#import <Security/Security.h>
^
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "Headers/Security.h"
^
/System/Library/Frameworks/Security.framework/Headers/Security.h:98:10: note: in file included from /System/Library/Frameworks/Security.framework/Headers/Security.h:98:
#include <Security/CMSDecoder.h>
^
error: /System/Library/Frameworks/Security.framework/Headers/CMSDecoder.h:130:5: error: expected function body after function declarator
__OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_5, __MAC_10_13, __IPHONE_NA, __IPHONE_NA,
^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/Availability.h:286:57: note: expanded from macro '__OSX_AVAILABLE_BUT_DEPRECATED_MSG'
__AVAILABILITY_INTERNAL##_osxIntro##_DEP##_osxDep##_MSG(_msg)
^
<scratch space>:74:1: note: expanded from here
__AVAILABILITY_INTERNAL__MAC_10_5_DEP__MAC_10_13_MSG
warning: <module-includes>:1:1: warning: umbrella header for module 'Security' does not include header 'SecProtocol.h'
#import "Headers/Security.h"
^
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "Headers/Foundation.h"
^
/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:85:9: note: in file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:85:
#import <Foundation/NSURLCredential.h>
^
error: /System/Library/Frameworks/Foundation.framework/Headers/NSURLCredential.h:9:9: error: could not build module 'Security'
#import <Security/Security.h>
^
/System/Library/Frameworks/Foundation.framework/Headers/NSURLError.h:15:9: note: while building module 'CoreServices' imported from /System/Library/Frameworks/Foundation.framework/Headers/NSURLError.h:15:
#import <CoreServices/CoreServices.h>
^
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Headers/Files.h:56:10: note: while building module 'DiskArbitration' imported from /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Headers/Files.h:56:
#include <DiskArbitration/DADisk.h>
^
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "Headers/DiskArbitration.h"
^
warning: /System/Library/Frameworks/DiskArbitration.framework/Headers/DiskArbitration.h:282:39: warning: inferring '_Nonnull' for pointer type within array is deprecated
CFStringRef arguments[] );
^
/System/Library/Frameworks/Foundation.framework/Headers/NSURLError.h:15:9: note: while building module 'CoreServices' imported from /System/Library/Frameworks/Foundation.framework/Headers/NSURLError.h:15:
#import <CoreServices/CoreServices.h>
^
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Headers/Files.h:56:10: note: while building module 'DiskArbitration' imported from /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Headers/Files.h:56:
#include <DiskArbitration/DADisk.h>
^
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "Headers/DiskArbitration.h"
^
warning: /System/Library/Frameworks/DiskArbitration.framework/Headers/DiskArbitration.h:282:79: warning: array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)
CFStringRef arguments[] );
^
/System/Library/Frameworks/DiskArbitration.framework/Headers/DiskArbitration.h:282:79: note: insert '_Nullable' if the array parameter may be null
CFStringRef arguments[] );
^
/System/Library/Frameworks/DiskArbitration.framework/Headers/DiskArbitration.h:282:79: note: insert '_Nonnull' if the array parameter should never be null
CFStringRef arguments[] );
^
/System/Library/Frameworks/Foundation.framework/Headers/NSURLError.h:15:9: note: while building module 'CoreServices' imported from /System/Library/Frameworks/Foundation.framework/Headers/NSURLError.h:15:
#import <CoreServices/CoreServices.h>
^
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "Headers/CoreServices.h"
^
/System/Library/Frameworks/CoreServices.framework/Headers/CoreServices.h:45:10: note: in file included from /System/Library/Frameworks/CoreServices.framework/Headers/CoreServices.h:45:
#include <LaunchServices/LaunchServices.h>
^
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Headers/LaunchServices.h:23:10: note: in file included from /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Headers/LaunchServices.h:23:
#include <LaunchServices/IconsCore.h>
^
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Headers/IconsCore.h:23:10: note: in file included from /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Headers/IconsCore.h:23:
#include <OSServices/OSServices.h>
^
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Headers/OSServices.h:29:10: note: in file included from /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Headers/OSServices.h:29:
#include <OSServices/CSIdentity.h>
^
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Headers/CSIdentity.h:26:10: note: in file included from /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Headers/CSIdentity.h:26:
#include <OSServices/CSIdentityBase.h>
^
error: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Headers/CSIdentityBase.h:23:10: error: could not build module 'Security'
#include <Security/SecBase.h>
^
/System/Library/Frameworks/Foundation.framework/Headers/NSAppleEventDescriptor.h:8:9: note: while building module 'ApplicationServices' imported from /System/Library/Frameworks/Foundation.framework/Headers/NSAppleEventDescriptor.h:8:
#import <ApplicationServices/ApplicationServices.h>
^
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "Headers/ApplicationServices.h"
^
error: /System/Library/Frameworks/ApplicationServices.framework/Headers/ApplicationServices.h:23:10: error: could not build module 'CoreServices'
#include <CoreServices/CoreServices.h>
^
error: could not build Objective-C module 'Foundation'
note: This error message is displayed only once. If the error displayed above is due to conflicting search paths to Clang modules in different images of the debugged executable, this can slow down debugging of Swift code significantly, since a fresh Swift context has to be created every time a conflict is encountered.
So, I am wondering if this error causes a crash in the VSCode plugin, but don't know for sure because I wasn't able to work around it.
Once The SwiftASTContext failed to initialize like this, all sorts of assumptions in LLDB are broken. I would focus on understanding the root cause of the Clang errors you pasted and fix that as my first priority.
That said, I am really puzzled by the actually error message. It seems to fail system modules from the macOS SDK. Is there any way you can send me a reduced reproducer for this issue?
@Adrian_Prantl I think my posts may have been a bit confusing because I was dumping everything I observed in case it's helpful. To organize things a bit, there are two issues, in order of priority:
When using SwiftPM and doing swift build LLDB reports errors of the form:
error: warning: failed to get module "ReinforcementLearning" from AST context
error: in auto-import:
failed to get module "ReinforcementLearning" from AST context
and I cannot evaluate expressions or variables. This is resolved if I build using swift build -Xlinker -add_ast_path -Xlinker .build/debug/ArcadeLearningEnvironmentExperiments.swiftmodule -Xlinker -add_ast_path -Xlinker .build/debug/ReinforcementLearning.swiftmodule -Xlinker -add_ast_path -Xlinker .build/debug/Logging.swiftmodule. This indicates that SwiftPM is not adding the -add_ast_path options when building in debug mode that seem to be necessary.
After 1 is resolved, LLDB is working and I am able to debug and evaluate expressions etc. However, this long list of warnings and some errors is generated. This is ignored by XCode and by one VSCode plugin for LLDB, but some other VSCode plugins crash. I assume the crash is due to this list of warnings and errors and I haven't figured out a workaround yet.
So, how about we figure out a solution for point 1 first and then resolve point 2? Point 1 is much more important because it completely prevents debugging. Also, given the workaround for point 1, I assume there may be some easy fix for SwiftPM.
@Adrian_Prantl I was wondering if you had a chance to take a look at my response above. Regarding the SwiftPM issue and given the already relevant PR, do you think point 1 is easy to fix?
Your summary for point (1) is accurate. This is a well-known bug in swiftpm (rdar://46509520 and SR-11008). It is probably not very difficult to implement, but someone like @NeoNacho will have a better idea how much work it is to fix.