Cannot debug SwiftPM package in Xcode

I've been trying to debug a program that is packaged/built with SwiftPM.
Unfortunately, the Xcode project generated via `swift package
generate-xcodeproj` cannot inspect the variables. Whenever I try to
print an object from the lldb command-line in Xcode I get this error:

po r
warning: Swift error in module example.
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module SourceKittenFramework.
Debug info from this module will be unavailable in the debugger.

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

I've narrowed it down to a specific dependency, SourceKittenFramework,
but I'm not sure if it is a bug in SwiftPM or in the package
configuration or something else completely.

I've attached a minimal SwiftPM package (`$ tar xvf
cannot-debug.tar.xz`) that should generate an Xcode project that
exemplifies the issue.

Can someone please help me understand why this is not debuggable?

Thank you,

Ryan Lovelett

cannot-debug.tar.xz (628 Bytes)

Can you file a JIRA for this?

- Daniel

···

On Nov 11, 2016, at 11:08 AM, Ryan Lovelett via swift-build-dev <swift-build-dev@swift.org> wrote:

I've been trying to debug a program that is packaged/built with SwiftPM.
Unfortunately, the Xcode project generated via `swift package
generate-xcodeproj` cannot inspect the variables. Whenever I try to
print an object from the lldb command-line in Xcode I get this error:

po r
warning: Swift error in module example.
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module SourceKittenFramework.
Debug info from this module will be unavailable in the debugger.

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

I've narrowed it down to a specific dependency, SourceKittenFramework,
but I'm not sure if it is a bug in SwiftPM or in the package
configuration or something else completely.

I've attached a minimal SwiftPM package (`$ tar xvf
cannot-debug.tar.xz`) that should generate an Xcode project that
exemplifies the issue.

Can someone please help me understand why this is not debuggable?

Thank you,

Ryan Lovelett
<cannot-debug.tar.xz>_______________________________________________
swift-build-dev mailing list
swift-build-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-build-dev

There's a bug in the code that's supposed to dump the error message when we can't reconstitute a module which cause the error not to get printed. You can work around that to get lldb to show you the error by setting the environment variable LLDB_SWIFT_DUMP_DIAGS, and then running lldb with that set. Then you should get you whatever error was causing the clang importer used by lldb to fall over.

Jim

···

On Nov 11, 2016, at 5:14 PM, Daniel Dunbar <daniel_dunbar@apple.com> wrote:

Can you file a JIRA for this?

- Daniel

On Nov 11, 2016, at 11:08 AM, Ryan Lovelett via swift-build-dev <swift-build-dev@swift.org> wrote:

I've been trying to debug a program that is packaged/built with SwiftPM.
Unfortunately, the Xcode project generated via `swift package
generate-xcodeproj` cannot inspect the variables. Whenever I try to
print an object from the lldb command-line in Xcode I get this error:

po r
warning: Swift error in module example.
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module SourceKittenFramework.
Debug info from this module will be unavailable in the debugger.

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

I've narrowed it down to a specific dependency, SourceKittenFramework,
but I'm not sure if it is a bug in SwiftPM or in the package
configuration or something else completely.

I've attached a minimal SwiftPM package (`$ tar xvf
cannot-debug.tar.xz`) that should generate an Xcode project that
exemplifies the issue.

Can someone please help me understand why this is not debuggable?

Thank you,

Ryan Lovelett
<cannot-debug.tar.xz>_______________________________________________
swift-build-dev mailing list
swift-build-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-build-dev

Done!

Thank you Daniel.

Jim,

Thanks for that pointer. The behavior is even stranger now. When I run
Xcode with that environment variable set the debugger ends up kind of
working. The "auto" variables still do not show up in Xcode but when I
print from lldb (e.g., `po r`) it actually dumps the object information.
If I close and re-run Xcode without the environment variable it goes
back to printing those errors and I get nothing. ¯\_(ツ)_/¯

I've attached the log output from Xcode when running with this variable
to this email. I do not think the logs are germane to this issue. I
think they are just Xcode general layout diagnostics.

Obviously there is still something wrong since the "auto" variables
still are not populating and all the types report as `<<error type>>`.

BUT I now have a work-around and I can at least dump the variables from
that.

Thank you for the suggestion!

lldb.log (1.81 KB)

···

On Fri, Nov 11, 2016, at 08:33 PM, Jim Ingham wrote:

There's a bug in the code that's supposed to dump the error message when
we can't reconstitute a module which cause the error not to get printed.
You can work around that to get lldb to show you the error by setting the
environment variable LLDB_SWIFT_DUMP_DIAGS, and then running lldb with
that set. Then you should get you whatever error was causing the clang
importer used by lldb to fall over.