Debug local stack frame variables fails - Failed to get module 'Builtin' from AST context

bug
(David liu) #1

Hi all was wondering if it was something I am doing wrong and if this issue affects me only and should I create a Jira ticket from this?
During debugging sessions either in Xcode or from LLDB(REPL) in Terminal I get the AST error when i try to investigate my stack variables. Any help would be much appreciated!

How i cloned:
branch: master
clone: git clone https://github.com/apple/swift.git
./swift/utils/update-checkout --clone
How i built:
terminal: utils/build-script --release --debug-swift --debug-swift-stdlib
Xcode: utils/build-script --debug --xcode

How i am testing:
Xcode: build and run
terminal: lldb attached to Ninja-RelWithDebInfoAssert+stdlib-DebugAssert/swift-macosx-x86_64/bin/swift

Expected results - able to investigate my local variables on stack frame

Actual - error: in auto-import:
failed to get module 'Builtin' from AST context

ocess 20684 stopped

  • thread #2, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x000000010b01f657 libswiftCore.dylib`Array.stuffz.getter(self=) at Array.swift:328
    325 }
    326
    327 public var stuffz:String {
    -> 328 let x = "foobar"
    329 let y = "dem breakpoints"
    330 let combined = x + y
    331 return combined
    Target 0: (swift) stopped.
    (lldb) n
    Process 20684 stopped
  • thread #2, queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x000000010b01f67c libswiftCore.dylib`Array.stuffz.getter(self=) at Array.swift:329
    326
    327 public var stuffz:String {
    328 let x = "foobar"
    -> 329 let y = "dem breakpoints"
    330 let combined = x + y
    331 return combined
    332 }
    Target 0: (swift) stopped.
    (lldb) po x
    error: in auto-import:
    failed to get module 'Builtin' from AST context
    (lldb) s
    Process 20684 stopped
  • thread #2, queue = 'com.apple.main-thread', stop reason = step in
    frame #0: 0x000000010b0178d8 libswiftCore.dylib`String.init(start=0x000000010b75dc1f "dem breakpoints", utf8CodeUnitCount=15, isASCII=1) at String.swift:513
    510 utf8CodeUnitCount: Builtin.Word,
    511 isASCII: Builtin.Int1
    512 ) {
    -> 513 let bufPtr = UnsafeBufferPointer(
    514 start: UnsafeRawPointer(start).assumingMemoryBound(to: UInt8.self),
    515 count: Int(utf8CodeUnitCount))
    516 if let smol = _SmallString(bufPtr) {
    Target 0: (swift) stopped.
    (lldb) s
    Process 20684 stopped
  • thread #2, queue = 'com.apple.main-thread', stop reason = step in
    frame #0: 0x000000010b01b1ff libswiftCore.dylib`UnsafeBufferPointer.init(start=, count=15) at UnsafeBufferPointer.swift:892
    889 @inlinable // unsafe-performance
    890 public init(start: UnsafePointer?, count: Int) {
    891 _precondition(
    -> 892 count >= 0, "UnsafeBufferPointer with negative count")
    893 _precondition(
    894 count == 0 || start != nil,
    895 "UnsafeBufferPointer has a nil start and nonzero count")
    Target 0: (swift) stopped.
    (lldb) po count
    error: in auto-import:
    failed to get module 'Builtin' from AST context
(Adrian Prantl) #2

Does this still happen? I fixed a bug 2 weeks ago with precisely those symptoms. LLDB was trying to import the stdlib twice.

(David liu) #3

Hi Adrian, this is still happening I filed a bug for this here bug. If you could kindly take a look at this would be very appreciated! :slight_smile:

(Adrian Prantl) #4

If you are building your own Swift compiler (at this point in time) you need to debug programs compiled with that compiler with a matching LLDB. To build LLDB, just add -l (--llldb) to the build script invocation.

(David liu) #5

ohh thanks so much I will try that!

(David liu) #6

Hey Adrian,

I added the -l flag and am getting code sign issues. Do you know if I am suppose to code sign it ?

export diagnostic_message_length=282
export variant=normal
/bin/sh -c /Users/xyz/Documents/dev/swift-source/build/Ninja-DebugAssert/lldb-macosx-x86_64/lldb.build/CustomSwift-Debug/lldb-server.build/Script-4C3326CA18B2A2B800EB5DD7.sh
lldb_codesign: no identity found
Command /bin/sh failed with exit code 1

building with ./utils/build-script --debug --lldb-assertions
building with ./utils/build-script --debug --lldb

(David liu) #7

Hi Adrian,

I got fixed the codesigin issue but now not sure what to do.

I tried using the Ninja-DebugAssert/lldb-macosx-x86_64/CustomSwift-Debug/lldb to run the '../../swift-macosx-x86_64/bin/swift but that does not work. not sure how to get to REPL and debug

(Adrian Prantl) #8

either use the system debug server (--help) will tell you the right option, or run the codesign setup script in the lldb/scripts directory.

(David liu) #9

Hi Adrian

was wondering if you could elaborate, I have the current following build directory and was wondering how to launch swift from lldb

/Users/me/Documents/dev/swift-source/build/Ninja-DebugAssert/lldb-macosx-x86_64/CustomSwift-Debug
DavidLiu:CustomSwift-Debug davidliu$ ls
LLDB.framework debugserver lldb-argdumper lldb.py
LLDBWrapPython.cpp liblldb-core.a lldb-mi lldb_revision.h
darwin-debug lldb lldb-server repl_swift
DavidLiu:CustomSwift-Debug davidliu$

(Adrian Prantl) #10

If you perform a full install you should get a swift binary that invokes lldb as repl. Otherwise lldb --repl should also work.

(David liu) #11

If you perform a full install you should get a swift binary that invokes lldb as repl. Otherwise lldb --repl should also work.

Hi Adrian,

I am getting some errors

DavidLiu:CustomSwift-Debug davidliu$ ./lldb --repl

error: failed to launch REPL process: process exited with status -1 (Error 1)

And if I do just lldb --repl I get the one that is on the system Swift 4.1 and not the swift I just built

I also tried and got an error for
DavidLiu:CustomSwift-Debug davidliu$ ./lldb ../../swift-macosx-x86_64/bin/swift --repl

error: failed to launch REPL process: process exited with status -1 (Error 1)

(Adrian Prantl) #12

This is my typical build-script invocation. Using this lldb --repl works for me.

swift/utils/build-script -r --lldb -- --skip-build-benchmarks --skip-test-cmark --skip-test-swift --lldb-use-system-debugserver --lldb-test-swift-only --lldb-build-with-cmake --llvm-enable-modules=true

Does this configuration work for you?

(Adrian Prantl) #13

To clarify: does

swift/utils/build-script -r --lldb -t -- --skip-build-benchmarks --skip-test-cmark --skip-test-swift --lldb-use-system-debugserver --lldb-test-swift-only --lldb-build-with-cmake --llvm-enable-modules=true

succeed?

(David liu) #14

Thanks let me try this ! my build script I am using utils/build-script --release --debug-swift --debug-swift-stdlib --lldb-debug

(Adrian Prantl) #15

If you are building lldb with xcode, only DebugAssert and Release are tested configuration. If you build using CMake, the whole spectrum should work.

(David liu) #16

Thanks for your script I am testing it out now and I am using Cmake/ninja and not using any Xcode builds

(Adrian Prantl) #17

Basically any build-script invocation you can see in action on http://ci.swift.org/ will work.

(David liu) #18

Thanks a ton Adrian! The build options you provided works :slight_smile: you sir are a lifesaver.

Debugger (lldb or gdb) does not show variable value in swift code
(Manoj Karki) #19

I am facing this same problem.
XCode 10.2.1
In debugger po self (for example) prints
error: warning: failed to get module '<>' from AST context

error: in auto-import:

failed to get module '<>' from AST context.

I am debugging a module using Objective C and Swift.
Enable Modules (C and Objective C): YES
Link Frameworks Automatically:YES

Any clues?

(Davide C. C. Italiano) #20

@manojkarki do you have a project you can share where this reproduces? If so, can you file a JIRA ticket for us to look at ? (add me to the cc:list so I'll see it)