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

Conversation

kastiglione
Copy link

@kastiglione kastiglione commented Mar 7, 2022

Specifying a typename filter for Swift exception breakpoints has been broken when creating breakpoints from the command line.

In other words, this command:

(lldb) breakpoint set -E swift --exception-typename MyError

would create a breakpoint that stopped for any Swift exception.

The fix is a one-line fix, changing the way m_exception_extra_args is constructed in CommandObjectBreakpoint. These args are consumed in SwiftExceptionPrecondition::ConfigurePrecondition.

Most of the changes included in this PR are to refactor the associated unit tests. The tests had been creating the exception breakpoint via SB API, not via command line which is why this bug wasn't caught by the tests. The tests have been updated to create exception breakpoints via both API and CLI. While editing the tests, I cleaned them up too.

I also deleted a duplicate and commented-out definition of breakpoint_set_exception_typename in Commands/Options.td.

rdar://75959015

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test Linux

@adrian-prantl adrian-prantl requested a review from jimingham March 7, 2022 18:19
@@ -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?

Copy link

@jimingham jimingham left a comment

Choose a reason for hiding this comment

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

This looks fine. I would prefer all the tests that set breakpoints do so through facilities in lldbutil so we can centralize checking and getting the result out. Here guessing that the breakpoint you make is the first one in the target seems like laying a little landmine for people coming to revise the test later.

cmd = "breakpoint set -E swift"
if typename:
cmd += " --exception-typename " + typename
self.runCmd(cmd)

Choose a reason for hiding this comment

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

Might be better to make a lldbutil.run_break_for_exception along the lines of "run_break_set_by_name, etc. Then you can use the check_breakpoint_result to pull the breakpoint out and make sure that the setting actually worked.

Choose a reason for hiding this comment

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

Should we be adding those on the Swift branch? (no strong opinion either way)

Choose a reason for hiding this comment

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

Break for exception works for C++ & ObjC, so there's no reason not to. The Object type would be an extra argument, so you don't need to bring along any explicit swiftness.

Copy link
Author

Choose a reason for hiding this comment

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

I have added lldbutil.run_break_set_by_exception. I will open a diff to upstream llvm too.

@kastiglione kastiglione requested a review from jimingham March 8, 2022 01:14
@kastiglione
Copy link
Author

@swift-ci test

Copy link

@jimingham jimingham left a comment

Choose a reason for hiding this comment

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

LGTM

@kastiglione kastiglione merged commit 0a70434 into stable/20211026 Mar 8, 2022
@kastiglione kastiglione deleted the lldb-Fix-swift-exception-breakpoint-command-type-filtering branch March 8, 2022 15:34
kastiglione added a commit that referenced this pull request Mar 24, 2022
Specifying a typename filter for Swift exception breakpoints has been broken when creating breakpoints from the command line.

In other words, this command:

```
(lldb) breakpoint set -E swift --exception-typename MyError
```

would create a breakpoint that stopped for **any** Swift exception.

The fix is a one-line fix, changing the way `m_exception_extra_args` is constructed in `CommandObjectBreakpoint`. These args are consumed in [`SwiftExceptionPrecondition::ConfigurePrecondition`](https://github.com/apple/llvm-project/blob/9509716734619d7299d296cb175e5d50f1d0a857/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp#L1524-L1531).

Most of the changes included in this PR are to refactor the associated unit tests. The tests had been creating the exception breakpoint via SB API, not via command line which is why this bug wasn't caught by the tests. The tests have been updated to create exception breakpoints via both API and CLI. While editing the tests, I cleaned them up too.

I also deleted a duplicate and commented-out definition of `breakpoint_set_exception_typename` in `Commands/Options.td`.

rdar://75959015
(cherry picked from commit 0a70434)
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.

3 participants