Unable to inspect local Swift variables or step over await calls in Xcode

Hi @gnachman, I attempted to reproduce the error you're seeing on commit 257fd8858811766867b4741b4d5da18a0e31d9cf, but I got what is seemingly correct output.

(lldb) po self
<TokenExecutorImpl: 0x0000000126226980: queue=<OS_dispatch_queue_serial: com.iterm2.mutation[0x126227700] = { xref = 129, ref = 7, sref = 4, target = com.apple.root.default-qos.overcommit[0x1de792440], width = 0x1, state = 0x006000a40000ca05, enqueued, dirty, max qos 4, draining on 0xca07, in-barrier}> taskQueue=0 sideEffects=0 pauseCount=0 throughput=0 delegate=Optional(<VT100ScreenMutableState: 0x125a08c80 sideEffectPerformer=<VT100Screen: 0x120ca9ea0 grid:<VT100Grid: 0x11a2bafe0 size=80 x 25, cursor @ (0,0)> mutableState:0x125a08c80>>)>

Could you provide us with a types/expression log by:

  • Adding the following to your ~/.lldbinit file: log enable lldb types expr -f path/to/file
  • Killing lldb (killall lldb-rpc-server)
  • Reproducing the issue

Make sure to remove the log line in your ~/.lldbinit file after generating the log, as writing to the log can slightly affect the debugger's performance.

1 Like

Hi @augusto2112 thanks for the quick response. Here's a gist with the log file:

1 Like

ā€¦and for reference, I did po self in TokenExecutor as I described earlier.

Fascinating. The underlying error in the log seems to be:

 SwiftASTContextForExpressions::GetModule("iTerm2SharedARC") -- error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/simd/base.h:88:5: error: module 'Darwin' is defined in both '/var/folders/jk/2nklbh0x5ksc192jsm9nhnhc0000gn/C/clang/ModuleCache/1BABVJDR8LQ0H/Darwin-14TRD15FCACV2.pcm' and '/var/folders/jk/2nklbh0x5ksc192jsm9nhnhc0000gn/C/clang/ModuleCache/1BABVJDR8LQ0H/Darwin-1PYVG0M6EKTXE.pcm'

This would indicate that you have two copies of the Darwin module (basically two different SDKs) in the same project. If you could delete your clang module cache at /var/folders/jk/2nklbh0x5ksc192jsm9nhnhc0000gn/C/clang/ModuleCache and then restart Xcode and rerun the expression, the types log should include a -Rmodule-build remark that could potentially indicate where the second copy of the Darwin module comes from.

2 Likes

After deleting the module cache, the problem has gone away and po self no longer crashes. Is there anything I can do to help find the root cause, or do we just chalk this up to evil spirits?

Could you delete the clang module cache again, add that log line I sent you earlier to your ~/.lldbinit (remember to remove it after), kill lldb, rerun the expression, and send us the generated log? As Adrian said, the types log will hopefully include some clues to how you ended up in such a state.

Second log is here:

Unfortunately the -Rmodule-build remarks will only be in the log the very first time you run the expression after deleting module cache. I think this log may have been captured on a warm cache.

@Adrian_Prantl Ok, one more try:

I quit Xcode, then deleted my ModuleCache and the build folder, then launched xcode and build & ran the app. I hope it has what you need!

I found myself here because I was getting similar errors to @gnachman:

error: Expression evaluation failed. Retrying without binding generic parameters
error: Could not evaluate the expression without binding generic types.

Iā€™m not sure if my problem is actually the same as theirs, but I was able to work around/fix mine, so for anyone else running finding themselves here for similar reasons:

A lot of searching led me to the ā€œswift-healthcheckā€ debugger command, which told me that I was ā€œMissing Swift module or Clang moduleā€ for the static framework I was trying to debug.

I had to add this to the linker flags for the app it was linked into:

-Wl,-add_ast_path,$(TARGET_BUILD_DIR)/<framework name>.framework/Modules/<framework name>.swiftmodule/$(NATIVE_ARCH_ACTUAL)-apple-$(SHALLOW_BUNDLE_TRIPLE).swiftmodule

Where ā€œ<framework name>ā€ was my framework name. Note that that is indeed all one big argument, with commas, not a few separate arguments.

Iā€™m not sure if the debugger and/or linker not finding this automatically is a bug or not. I know that ā€˜static frameworksā€™ were at least initially more of an unintended consequence of how the linker works than a designed feature, so I can see the argument that itā€™s not (it sure would be nice if it worked automatically in a future Xcode though!)

I am happy I can debug now.

4 Likes

Static archives often do need some manual work in the build system since there is no channel to communicate the existence of a .swiftmodule to the linker.

Thereā€™s a bit more background about this problem in this WWDC video:

4 Likes

@Adrian_Prantl thanks for the link! Unless I'm mistaken, this (this being having to manually point LLDB to a .swiftmodule) doesn't apply to vanilla Xcode + SPM package setups on Apple platforms?

I'm still experiencing a massive amount of issues there, especially with code that makes use of Swift concurrency.

There's a lot moving pieces that could cause a debugging session to not work properly. The first thing to check is the output of swift-healthcheck to look for errors and warning that you have control over. If you can share an isolated example with us (either here, or as a bugreport on apple.com) we can also take a look together.

@Adrian_Prantl I dumped swift-healthcheck, nothing except the usual "Swift plugin server does not exist" messages.

If you can share a small project that reproduces the issue, I can take a look.

2 Likes

@Adrian_Prantl thanks, Iā€™ll try and do that soon! It might be hard to reproduce it in a small project, I have a lot of Swift packages and LLDB seems to get worse as the number of modules increase.

Is there a list of open bug reports that I can browse to see if my issue is already covered there? I am guessing that the team is aware of some of the bugs that may have been fixed but didnā€™t make it into Xcode 15.2, where the actionable thing for me would be just to wait.

Could potentially save us both time if I can reference a list of bugs that have been officially acknowledged :)

Xcode 15.3 still can't step into async calls.

5 Likes

Dear Apple Engineering, please fix the Xcode debugger or Swift PM.

Yours truly...

1 Like