Debugging with Xcode/LLDB

Hi,
I’m using LLDB when debugging in Xcode. `p x->dump()` works fine, but what about vectors? For example `SmallVectorImpl` doesn’t offer `dump()`, and I can’t even get it’s size:

error: Couldn't lookup symbols:
  __ZNK4llvm25SmallVectorTemplateCommonIN5swift11constraints8SolutionEE4sizeEv

Hi, Pawel. Unfortunately, this is what happens to inlinable code in debug builds (not just for LLDB, Xcode, or the Swift compiler). The debugger doesn’t have the body of inlinable functions, and the binary doesn’t have a copy of the code (since it was always inlined away). You have a handful of options here:

1. Poke at the members of SmallVectorImpl directly. (BeginX and EndX are the useful ones.)
2. Load the “data formatters” provided with LLVM into your LLDB session: `command script import llvm/utils/lldbDataFormatters.py`. This very conveniently shows formatted views of certain LLVM types, including SmallVector, without running code in the process you’re debugging. (This also isn’t magic; you can write your own for your own types, and we totally could write some for Swift types.)
3. Use a debug compiler, where nothing will get inlined away. Sometimes this is necessary anyway because it’s always hard to debug optimized code, but it does have its downsides.

Some day we’ll also have

4. `expr @import LLVMADT` (or similar), to have LLDB pull in all the declarations from the LLVM ADT headers using the modules <http://clang.llvm.org/docs/Modules.html&gt; feature. Support for C++ modules is still pretty shaky, but it should still be possible to do this with LLVM, which has its headers properly grouped into modules. I haven’t tried it, though, and Swift hasn’t undergone this treatment yet.

Hope that helps,
Jordan

···

On Mar 8, 2017, at 00:00, Pawel Szot (PGS Software) via swift-dev <swift-dev@swift.org> wrote:

Hi,
I’m using LLDB when debugging in Xcode. `p x->dump()` works fine, but what about vectors? For example `SmallVectorImpl` doesn’t offer `dump()`, and I can’t even get it’s size:

error: Couldn't lookup symbols:
 __ZNK4llvm25SmallVectorTemplateCommonIN5swift11constraints8SolutionEE4sizeEv

_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

3 Likes