Skip to content

Instantly share code, notes, and snippets.

@mattstevens
Last active June 22, 2018 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattstevens/7463f5cfe21328c0e738d8e4ba674c7d to your computer and use it in GitHub Desktop.
Save mattstevens/7463f5cfe21328c0e738d8e4ba674c7d to your computer and use it in GitHub Desktop.
Disabling Swift Error breakpoints for XCTAssertThrowsError calls
A couple options:
1. Disable the Swift Error breakpoint only within XCTAssertThrowsError() calls.
Add the Swift Error breakpoint as usual.
Edit the breakpoint, add a Debugger Command action, then paste in the following:
script lldb.process.Continue().Clear() if any(threadFrame.name.startswith('XCTest.XCTAssertThrows') for threadFrame in lldb.thread.frames) else None
This is ugly and the condition adds substantial overhead for each XCTAssertThrowsError call, but this method is easy to set up and the
Swift Error breakpoint will work everywhere else as usual.
2. Disable all Swift Error breakpoints when running tests
This one requires adding a custom command.
Stash xctestbreakpoints.py somewhere.
Edit ~/.lldbinit and add the following:
command script import /path/to/xctestbreakpoints.py
In Xcode, add a symbolic breakpoint on _XCTestMain.
Edit the breakpoint, check the automatically continue option, add a Debugger Command action, then paste in the following:
disable-swift-error-breakpoints
This will disable all Swift Error breakpoints when test execution starts.
import lldb
def disable_swift_error_breakpoints(debugger, command, result, dict):
for breakpoint in debugger.GetSelectedTarget().breakpoint_iter():
if not breakpoint.enabled:
continue
for location in breakpoint:
if not location.IsResolved():
continue
if location.GetAddress().symbol.name == 'swift_willThrow':
breakpoint.enabled = False
break
return None
def __lldb_init_module(debugger, dict):
debugger.HandleCommand('command script add -f xctestbreakpoints.disable_swift_error_breakpoints disable-swift-error-breakpoints')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment