Skip to content

[lldb][Breakpoint] Allow whitespace in breakpoint address expression #126053

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
merged 5 commits into from
Feb 7, 2025

Conversation

Michael137
Copy link
Member

@Michael137 Michael137 commented Feb 6, 2025

Setting a breakpoint on <symbol> + <offset> used to work until 2c76e88e9eb284d17cf409851fb01f1d583bb22a, where this regex was reworked. Now we only accept <symbol>+ <offset> or <symbol>+<offset>.

This patch fixes the regression by adding yet another [[:space:]]* component to the regex.

One could probably simplify the regex (or even replace the regex by just calling the relevent consumeXXX APIs on llvm::StringRef). Though I left that for the future.

rdar://130780342

Setting a breakpoint on `<symbol> + <offset>` used to work until
`2c76e88e9eb284d17cf409851fb01f1d583bb22a`, where this regex was
reworked. Now we only accept `<symbol>+ <offset>`.

This patch fixes the regression by adding yet another `[[:space:]]*`
component to the regex.

One could probably simplify the regex (or even replace the regex by just
calling the relevent `consumeXXX` APIs on `llvm::StringRef`). Though I
left that for the future.

rdar://130780342
@llvmbot
Copy link
Member

llvmbot commented Feb 6, 2025

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

Changes

Setting a breakpoint on &lt;symbol&gt; + &lt;offset&gt; used to work until 2c76e88e9eb284d17cf409851fb01f1d583bb22a, where this regex was reworked. Now we only accept &lt;symbol&gt;+ &lt;offset&gt;.

This patch fixes the regression by adding yet another [[:space:]]* component to the regex.

One could probably simplify the regex (or even replace the regex by just calling the relevent consumeXXX APIs on llvm::StringRef). Though I left that for the future.

rdar://130780342


Full diff: https://github.com/llvm/llvm-project/pull/126053.diff

1 Files Affected:

  • (modified) lldb/source/Interpreter/OptionArgParser.cpp (+3-1)
diff --git a/lldb/source/Interpreter/OptionArgParser.cpp b/lldb/source/Interpreter/OptionArgParser.cpp
index 800f22b6169dc62..2d393a57452ee56 100644
--- a/lldb/source/Interpreter/OptionArgParser.cpp
+++ b/lldb/source/Interpreter/OptionArgParser.cpp
@@ -262,8 +262,10 @@ OptionArgParser::DoToAddress(const ExecutionContext *exe_ctx, llvm::StringRef s,
   // 3: The symbol/reg name if there is an offset
   // 4: +/-
   // 5: The offset value.
+  // clang-format off
   static RegularExpression g_symbol_plus_offset_regex(
-      "^(\\$[^ +-]+)|(([^ +-]+)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*)$");
+      "^(\\$[^ +-]+)|(([^ +-]+)[[:space:]]*([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*)$");
+  // clang-format on
 
   llvm::SmallVector<llvm::StringRef, 4> matches;
   if (g_symbol_plus_offset_regex.Execute(sref, &matches)) {

@DavidSpickett
Copy link
Collaborator

Can this be tested?

@Michael137
Copy link
Member Author

Can this be tested?

Oh whoops i forgot to git add the test :)

@@ -0,0 +1,3 @@
# RUN: %clang_host -g -O0 %S/Inputs/main.c -o %t.out
# RUN: %lldb -b -o 'breakpoint set -a "main + 26"' %t.out | FileCheck %s --check-prefix CHECK
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should test a few versions in case the whitespace was ever made mandatory accidentally, on either side of the +.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, will put them all in one lldb invocation

@@ -0,0 +1,12 @@
# RUN: %clang_host -g -O0 %S/Inputs/main.c -o %t.out
# RUN: %lldb -b -o 'breakpoint set -a "main+26"' \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nested quotes don't work (or maybe work differently) on windows. Better put this into a command file (i.e., this file, since it's just full of comments ).

static RegularExpression g_symbol_plus_offset_regex(
"^(\\$[^ +-]+)|(([^ +-]+)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*)$");
"^(\\$[^ +-]+)|(([^ +-]+)[[:space:]]*([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*)$");
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is using (in [^ +-])and :space: in the same regex, which seems oddly inconsistent?
Apart from Pavel's comment, this seems fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea I think the regex can be simplified. But it's was using :space: already and I didn't want to make drive-by changes to this regex in this PR

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd probably prefer to just parse the string if we did want to simplify this logic

@Michael137 Michael137 merged commit 1608fe8 into llvm:main Feb 7, 2025
7 checks passed
@Michael137 Michael137 deleted the lldb/break-by-addr-whitespace branch February 7, 2025 09:27
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
…lvm#126053)

Setting a breakpoint on `<symbol> + <offset>` used to work until
`2c76e88e9eb284d17cf409851fb01f1d583bb22a`, where this regex was
reworked. Now we only accept `<symbol>+ <offset>` or
`<symbol>+<offset>`.

This patch fixes the regression by adding yet another `[[:space:]]*`
component to the regex.

One could probably simplify the regex (or even replace the regex by just
calling the relevent `consumeXXX` APIs on `llvm::StringRef`). Though I
left that for the future.

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

Successfully merging this pull request may close these issues.

5 participants