0

When I use LLDB on a Swift application in Xcode (e.g. by setting a breakpoint), I can call

settings set target.language swift

to have LLDB understand Swift code in commands like expression (and therefore po and print).

When I run lldb from the command line and try setting the target language as above, I get the error:

error: invalid language type 'swift', valid values are:
    c89
    c
    c++
    c99
    objective-c
    objective-c++
    c++03
    c++11
    c11
    c++14

Is anyone else having this same problem? How could I fix this?


I'm running macOS 10.15.7

Marcus Rossel
  • 3,196
  • 1
  • 26
  • 41
  • The command-line lldb that comes with Xcode uses exactly the same LLDB.framework that Xcode does. However, there are two versions of lldb available, the version hosted by llvm.org which doesn't have swift support, and the one hosted on the swift project's GitHub repository that does. You might have gotten a package with the llvm.org version which is in front of /usr/bin/lldb on your path. What is the version of lldb you get when you run `lldb --version` from Terminal? – Jim Ingham Oct 28 '20 at 17:01
  • Note also, the command `xcrun lldb` will always run the lldb that comes with Xcode, so even if you have other lldb's around it will pick a swift-enabled one from your Xcode install. If `xcrun lldb` doesn't recognize swift, then please file a bug with Apple. – Jim Ingham Oct 28 '20 at 21:54
  • @JimIngham Running `lldb --version` prints `lldb version 10.0.0`. Running `xcrun lldb --version` prints `lldb-1200.0.32.1 Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)`. Could you add your comment as an answer? Then I can accept it. – Marcus Rossel Nov 07 '20 at 10:37

1 Answers1

3

You probably have a brew or llvm.org install of the clang toolchain, including lldb, in front of /usr/bin/lldb on your path. The clang toolchains don't include the swift compiler, or a swift-enabled lldb.

Running the lldb will find the first lldb installed on your path, which is probably a clang one from home-brew or llvm.org.

Running the command xcrun lldb will always run the one from your installed Xcode. Also, you can tell by the result of the version command in lldb. The swift enabled versions will print the Apple Swift version along with the lldb version. The clang ones won't.

Jim Ingham
  • 25,260
  • 2
  • 55
  • 63