How do I debug tests using the open-source toolchain?

I'm trying to attach lldb to my package's test suite so I can inspect state at a breakpoint. All the docs I can find on this attach to the xctest executable, but from what I understand there is no xctest executable in the open-source toolchain. If I try to attach to swift directly I get denied. How do I do this?

Are you sure there's no .xctest executable? I just got a demangled backtrace for a test on linux by running lldb .build/x86_64-unknown-linux-gnu/debug/swift-nioPackageTests.xctest and then run NIOPosixTests.SALEventLoopTests/testSchedulingTaskOnSleepingLoopWakesUpOnce in lldb.

Maybe you are on macOS and it is different there- I have never used Swift on macOS- but I'd look for something similar on there.

1 Like

Are you sure there's no .xctest executable? I just got a demangled backtrace for a test on linux by running lldb .build/x86_64-unknown-linux-gnu/debug/swift-nioPackageTests.xctest and then run NIOPosixTests.SALEventLoopTests/testSchedulingTaskOnSleepingLoopWakesUpOnce in lldb.

I can find the .xctest bundle and can set it as a target, when I try to run it I get the following error:

process exited with status -1 
(attach failed (Not allowed to attach to process.  
Look in the console messages (Console.app), 
near the debugserver entries, when the attach failed.  
The subsystem that denied the attach permission 
will likely have logged an informative message about why it was denied.))

Note: I couldn't find any related console messages.

If I get the xctest binary from Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/xctest and pass the .xctest bundle as an argument, then I can attach. My concern is running xctest from a different toolchain than was used to build the test bundle. Maybe this concern is not justified?

Maybe you are on macOS and it is different there

I believe attach permissions do work differently in macOS, so that might be why. I really appreciate the help though!

1 Like