Skip to content

[lldb] Fix swift exception breakpoint command type filtering #4027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lldb/packages/Python/lldbsuite/test/lldbutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,19 @@ def run_break_set_by_file_colon_line(

return get_bpno_from_match(break_results)

def run_break_set_by_exception(
test,
language,
exception_typename=None):
command = 'breakpoint set -E ' + language
if exception_typename:
command += ' --exception-typename ' + exception_typename

break_results = run_break_set_command(test, command)
# No call to check_breakpoint_result as there's nothing to check. In
# particular, the exception breakpoint isn't yet guaranteed to be resolved.
return get_bpno_from_match(break_results)

def run_break_set_command(test, command):
"""Run the command passed in - it must be some break set variant - and analyze the result.
Returns a dictionary of information gleaned from the command-line results.
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Commands/CommandObjectBreakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
} break;

case 'O':
m_exception_extra_args.AppendArgument("-O");
m_exception_extra_args.AppendArgument("exception-typename");
m_exception_extra_args.AppendArgument(option_arg);
break;

Expand Down
6 changes: 0 additions & 6 deletions lldb/source/Commands/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,6 @@ let Command = "breakpoint set" in {
def breakpoint_set_file_colon_line : Option<"joint-specifier", "y">, Group<12>, Arg<"FileLineColumn">,
Required, Completion<"SourceFile">,

Choose a reason for hiding this comment

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

I'm a bit confused about this change — does that mean the option doesn't (and didn't) show up in the online help for the breakpoint command? Is that what we want?

Copy link
Author

Choose a reason for hiding this comment

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

I updated the PR description to point out that this commented-out definition is a duplicate. The actual definition of breakpoint_set_file_colon_line is a few lines up. Maybe this duplicate came from a merge?

Desc<"A specifier in the form filename:line[:column] for setting file & line breakpoints.">;
/* Don't add this option till it actually does something useful...
def breakpoint_set_exception_typename : Option<"exception-typename", "O">,
Arg<"TypeName">, Desc<"The breakpoint will only stop if an "
"exception Object of this type is thrown. Can be repeated multiple times "
"to stop for multiple object types">;
*/
}

let Command = "breakpoint clear" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,81 +26,70 @@ class TestSwiftErrorBreakpoint(TestBase):

@decorators.skipIfLinux # <rdar://problem/30909618>
@swiftTest
def test_swift_error_no_pattern(self):
def test_swift_error_no_typename(self):
"""Tests that swift error throws are correctly caught by the Swift Error breakpoint"""
self.build()
self.do_test(lldb.SBStringList(), True)
self.do_tests(None, True)

@swiftTest
def test_swift_error_matching_base_pattern(self):
def test_swift_error_matching_base_typename(self):
"""Tests that swift error throws are correctly caught by the Swift Error breakpoint"""
self.build()
pattern = lldb.SBStringList()
pattern.AppendString("exception-typename")
pattern.AppendString("EnumError")
self.do_test(pattern, True)
self.do_tests("EnumError", True)

@swiftTest
def test_swift_error_matching_full_pattern(self):
def test_swift_error_matching_full_typename(self):
"""Tests that swift error throws are correctly caught by the Swift Error breakpoint"""
self.build()
pattern = lldb.SBStringList()
pattern.AppendString("exception-typename")
pattern.AppendString("a.EnumError")
self.do_test(pattern, True)
self.do_tests("a.EnumError", True)

@swiftTest
def test_swift_error_bogus_pattern(self):
def test_swift_error_bogus_typename(self):
"""Tests that swift error throws are correctly caught by the Swift Error breakpoint"""
self.build()
pattern = lldb.SBStringList()
pattern.AppendString("exception-typename")
pattern.AppendString("NoSuchErrorHere")
self.do_test(pattern, False)
self.do_tests("NoSuchErrorHere", False)

def setUp(self):
TestBase.setUp(self)
self.main_source = "main.swift"
self.main_source_spec = lldb.SBFileSpec(self.main_source)
self.build()

def do_test(self, patterns, should_stop):
"""Tests that swift error throws are correctly caught by the Swift Error breakpoint"""
def do_tests(self, typename, should_stop):
self.do_test(typename, should_stop, self.create_breakpoint_with_api)
self.do_test(typename, should_stop, self.create_breakpoint_with_command)

def create_breakpoint_with_api(self, target, typename):
types = lldb.SBStringList()
if typename:
types.AppendString("exception-typename")
types.AppendString(typename)
return target.BreakpointCreateForException(
lldb.eLanguageTypeSwift, False, True, types).GetID()

def create_breakpoint_with_command(self, target, typename):
return lldbutil.run_break_set_by_exception(
self, "swift", exception_typename=typename)

def do_test(self, typename, should_stop, make_breakpoint):
exe_name = "a.out"
exe = self.getBuildArtifact(exe_name)

# Create the target
target = self.dbg.CreateTarget(exe)
self.target = target
self.assertTrue(target, VALID_TARGET)

# Set the breakpoints
swift_error_bkpt = target.BreakpointCreateForException(
lldb.eLanguageTypeSwift, False, True, patterns)
swift_error_bkpt_id = make_breakpoint(target, typename)
# Note, I'm not checking locations here because we never know them
# before launch.

# Launch the process, and do not stop at the entry point.
process = target.LaunchSimple(None, None, os.getcwd())
self.process = process

if should_stop:
self.assertTrue(process, PROCESS_IS_VALID)
breakpoint_threads = lldbutil.get_threads_stopped_at_breakpoint(
process, swift_error_bkpt)
self.assertTrue(
len(breakpoint_threads) == 1,
breakpoint_threads = lldbutil.get_threads_stopped_at_breakpoint_id(
process, swift_error_bkpt_id)
self.assertEqual(len(breakpoint_threads), 1,
"We didn't stop at the error breakpoint")
else:
exit_state = process.GetState()
self.assertTrue(
exit_state == lldb.eStateExited,
self.assertEqual(exit_state, lldb.eStateExited,
"We stopped at the error breakpoint when we shouldn't have.")

target.BreakpointDelete(swift_error_bkpt.GetID())

if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lldb.SBDebugger.Terminate)
unittest2.main()
target.BreakpointDelete(swift_error_bkpt_id)