Did you ever encounter some strange issues when dealing with broken LLDB in Xcode leaving print()
as your final idea? Welcome to broken Xcode tooling.
TLDR; or answer the title’s question:
Actually, I have no idea how to really fix it. For keeping your sanity, just use print()
whenever LLDB seems broken.
But let me explain or let’s look at the symptoms first:
Especially in async
contexts LLDB seems really broken. You often get stuff like this:
error: expression failed to parse:
error: <EXPR>:8:1: error: cannot find 'destinationURL' in scope
destinationURL
^~~~~~~~~~~~~~
Code language: Bash (bash)
If you are think using fr v
or v
might work here:
Haha, no.
(lldb) v destinationURL
(Foundation.URL) destinationURL = <no location, value may have been optimized out>
Code language: Bash (bash)
In some cases the part using v
or fr v
might work but that is not the point here. Nobody can work with debugging tools that give ambiguous results or often don’t work.
forum.swift.org indicating brokenness
It seems to be an ongoing problem for Xcode or the tools it contains. I stumble across it now and then, regardless of whether it’s some strange Swift package manager of LLDB behavior. Often I ended up in some forum.swift.org thread. Actually, I learned whenever landing in some forum.swift.org thread while googling for anything Xcode / Swift related it seems to be a bigger issue.
E.g. when googling for broken LLDB stuff I ended up here: https://forums.swift.org/t/yo-apple-xcode-debugging-swift-is-still-horribly-broken/62702/62). The essential learning in this case: There are plenty of people reporting bugs already, Apple doesn’t seem to care too much or they were unable to fix ongoing issues for years. Best things you can do is report more bugs, just don’t care or go on with your life and use some other technique while waiting for the next Xcode.
For this specific case of broken LLDB, I recommend to just use print()
in strange cases like this. Trying to fix broken Xcode is often a waste of time and energy from my experience. Similar to how it often makes a project build again by deleting Derived Data
and restarting Xcode. It’s sad but that’s what you have to deal with.
Conclusion
I am aware that some people never use LLDB and only ever use print()
for debugging. Then everything is fine for you anyway. However, personally having to print everything out really slows my debugging down a lot. First, you have to add the statements, then you have to change them over and over again (e.g. you wanted to look at something else you do realize later, you missed something, etc.).
LLDB in Xcode is still broken after all these years. The thread linked above is not like years old, the last entry is from March 2023.
Just fall back to print()
to keep your sanity when LLDB does not work (again).