Skip to content

Conversation

plemarquand
Copy link
Contributor

@plemarquand plemarquand commented Sep 2, 2025

Introduces interactive debugging capabilities to swift test via a --debugger flag enabling developers to failing tests directly within LLDB.

This adds debugging parity with swift run --debugger which allows users to debug their executables directly.

When launching lldb this implenentation uses execv() to replace the swift-test process with LLDB. This approach avoids process hierarchy complications and ensures LLDB has full terminal control for interactive debugging features.

When there is only one type of tests the debugger creates a single LLDB target configured specifically for that framework. For XCTest, this means targeting the test bundle with xctest as the executable, while Swift Testing targets the test binary directly with appropriate command-line arguments.

When both testing frameworks have tests available we create multiple LLDB targets within a single debugging session. A Python script automatically switches targets as the executable exits, which lets users debug both types of tests spread across two executables in the same session. The Python script also maintains breakpoint persistence across target switches, allowing you to set a breakpoint for either test type no matter the active target.

Finally, we add a failbreak command alias that sets breakpoint(s) that break on test failure, allowing users to automatically stop on failed tests.

Issue: #8129

@plemarquand
Copy link
Contributor Author

@swift-ci please test

}

@Test(arguments: SupportedBuildSystemOnAllPlatforms)
func debuggerFlagWithBothTestingSuites(buildSystem: BuildSystemProvider.Kind) async throws {
Copy link
Contributor

@pmattos pmattos Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Would there be an easy way to actually interact with LLDB during tests (eg,stdin)? For instance, send it some commands and check back the expected results? Maybe you did it already... and I missed it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the reasons this is still in draft is I want to address that. I think I'd have to add supplemental commands to the file that gets passed to LLDB that contains its setup commands. That would let us set specific breakpoints in tests, though I still haven't figured out how to inspect the output since we replace the running process with execv.

@plemarquand
Copy link
Contributor Author

@swift-ci test

Introduces interactive debugging capabilities to `swift test` via a
`--debugger` flag enabling developers to failing tests directly within LLDB.

This adds debugging parity with `swift run --debugger` which allows users
to debug their executables directly.

When launching lldb this implenentation uses `execv()` to replace the
`swift-test` process with LLDB. This approach avoids process hierarchy
complications and ensures LLDB has full terminal control for interactive
debugging features.

When there is only one type of tests the debugger creates a single LLDB
target configured specifically for that framework. For XCTest, this means
targeting the test bundle with xctest as the executable, while Swift Testing
targets the test binary directly with appropriate command-line arguments.

When both testing frameworks have tests available we create multiple LLDB
targets within a single debugging session. A Python script automatically switches
targets as the executable exits, which lets users debug both types of tests
spread across two executables in the same session. The Python script also
maintains breakpoint persistence across target switches, allowing you to set
a breakpoint for either test type no matter the active target.

Finally, we add a `failbreak` command alias that sets breakpoint(s) that break
on test failure, allowing users to automatically stop on failed tests.

Issue: swiftlang#8129
@plemarquand
Copy link
Contributor Author

@swift-ci test windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants