Skip to content

[lldb][test][NFC] Add LLDB test for UBSan trap frame recognizer #151231

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 3 commits into from
Jul 31, 2025

Conversation

anthonyhatran
Copy link
Contributor

@anthonyhatran anthonyhatran commented Jul 29, 2025

In #145967 Clang was taught to emit trap reasons on UBSan traps in debug info using the same method as __builtin_verbose_trap. This patch adds a test case to make sure that the existing "Verbose Trap StackFrame Recognizer" recognizes the trap reason and sets the stop reason and stack frame appropriately.

Part of a GSoC 2025 Project.

@llvmbot
Copy link
Member

llvmbot commented Jul 29, 2025

@llvm/pr-subscribers-lldb

Author: Anthony Tran (anthonyhatran)

Changes

@Michael137 @delcypher

Part of a GSoC 2025 Project.


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

2 Files Affected:

  • (added) lldb/test/Shell/Recognizer/Inputs/ubsan_add_overflow.cpp (+8)
  • (added) lldb/test/Shell/Recognizer/ubsan_add_overflow.test (+17)
diff --git a/lldb/test/Shell/Recognizer/Inputs/ubsan_add_overflow.cpp b/lldb/test/Shell/Recognizer/Inputs/ubsan_add_overflow.cpp
new file mode 100644
index 0000000000000..0258ff296ea63
--- /dev/null
+++ b/lldb/test/Shell/Recognizer/Inputs/ubsan_add_overflow.cpp
@@ -0,0 +1,8 @@
+#include <limits.h>
+
+int main() {
+  volatile int a = INT_MAX;
+  volatile int b = 1;
+  volatile int c = a + b;
+  return c;
+}
\ No newline at end of file
diff --git a/lldb/test/Shell/Recognizer/ubsan_add_overflow.test b/lldb/test/Shell/Recognizer/ubsan_add_overflow.test
new file mode 100644
index 0000000000000..f9312b5bf15bb
--- /dev/null
+++ b/lldb/test/Shell/Recognizer/ubsan_add_overflow.test
@@ -0,0 +1,17 @@
+# REQUIRES: clang
+
+# RUN: %clang_host -g -O0 %S/Inputs/ubsan_add_overflow.cpp -o %t.out \
+# RUN: -fsanitize=signed-integer-overflow -fsanitize-trap=signed-integer-overflow
+
+# RUN: %lldb -b -s %s %t.out | FileCheck %s
+
+run
+# CHECK: thread #{{.*}} stop reason = Undefined Behavior Sanitizer: Integer addition overflowed
+
+frame info
+# CHECK: frame #{{.*}}`main at ubsan_add_overflow.cpp
+
+frame recognizer info 0
+# CHECK: frame 0 is recognized by Verbose Trap StackFrame Recognizer
+
+quit
\ No newline at end of file

@anthonyhatran anthonyhatran force-pushed the ubsan-lldb-stop-reason-test branch from bb76775 to bdf7487 Compare July 29, 2025 21:10
@DavidSpickett
Copy link
Collaborator

FYI I put the tagged people in reviewers for you (GitHub probably isn't letting you do that yourself, at some point you'll get permissions to do so). This way we don't land this with @ s in there and create an endless series of pings as llvm forks pull in this change.

Myself I usually put any review process related comments in my first comment after the PR is opened, keeps the description clean.

# REQUIRES: clang

# RUN: %clang_host -g -O0 %S/Inputs/ubsan_add_overflow.cpp -o %t.out \
# RUN: -fsanitize=signed-integer-overflow -fsanitize-trap=signed-integer-overflow
Copy link
Member

Choose a reason for hiding this comment

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

Lets indent here to make it easier to read

Suggested change
# RUN: -fsanitize=signed-integer-overflow -fsanitize-trap=signed-integer-overflow
# RUN: -fsanitize=signed-integer-overflow -fsanitize-trap=signed-integer-overflow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

Copy link
Collaborator

@DavidSpickett DavidSpickett left a comment

Choose a reason for hiding this comment

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

Some comments since I'm here but I leave it to your chosen reviewers to do the rest.

volatile int a = INT_MAX;
volatile int b = 1;
volatile int c = a + b;
return c;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this could be done in one line. return INT_MAX + 1; assuming INT_MAX defaults to unsigned int still.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made it into one line.

@DavidSpickett DavidSpickett changed the title [lldb] Add LLDB test for UBSan trap frame recognizer [lldb][test] Add LLDB test for UBSan trap frame recognizer Jul 30, 2025
@DavidSpickett
Copy link
Collaborator

Also surprised that we didn't have tests for this already, but I presume that's why you are contributing this now.

@@ -0,0 +1,17 @@
# REQUIRES: clang

# RUN: %clang_host -g -O0 %S/Inputs/ubsan_add_overflow.cpp -o %t.out \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also I have a feeling this doesn't need to be host, because the shell tests can be run remotely. I looked at the other tests and they are all %clang_host though.

So this is not an issue with this test it's with a category of tests. Which is not your responsibility, so you don't need to change anything here.

@Michael137
Copy link
Member

Also surprised that we didn't have tests for this already, but I presume that's why you are contributing this now.

There are tests for the __builtin_verbose_trap builtin, which was the only way Clang used to emit the artificial frames for LLDB to recognize. After #145967 we now also emit those fake frames for ubsan traps. The test added here ensures the UBSAN traps get recognized by LLDB

@anthonyhatran lets put this context into the PR description

Copy link
Contributor

@delcypher delcypher left a comment

Choose a reason for hiding this comment

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

Mostly looks good. Please remove the uses of volatile unless there's a good reason for them to be there. Also please make the description/commit message be more descriptive. Something like

[lldb][NFC] Add test cases for UBSan trap reasons

In #145967 Clang was taught to emit trap reasons on UBSan traps in debug info using the same method as __builtin_verbose_trap. This patch adds a test case to make sure that the existing "Verbose Trap StackFrame Recognizer" recognizes the trap reason and sets the stop reason and stack frame appropriately.


frame info
Copy link
Contributor

Choose a reason for hiding this comment

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

@anthonyhatran You should keep the frame info command and checking the output because this checks that the selected frame is in main and not the fake frame.

Copy link
Contributor

Choose a reason for hiding this comment

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

To be clear. What you added (bt and checking the output) is good but we should also make sure that frame 1 is the selected frame.

Copy link
Contributor Author

@anthonyhatran anthonyhatran Jul 30, 2025

Choose a reason for hiding this comment

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

Thanks for the clarification; I thought it would be potentially redundant so I removed it. I also didn't see Michael's comment before the initial revision commit. Re-added.

@anthonyhatran anthonyhatran changed the title [lldb][test] Add LLDB test for UBSan trap frame recognizer [lldb][test][NFC] Add LLDB test for UBSan trap frame recognizer Jul 30, 2025
@delcypher delcypher merged commit a8d0ae3 into llvm:main Jul 31, 2025
9 checks passed
@dzhidzhoev
Copy link
Member

Apparently, these changes break lldb-x86_64-win buildbot with the following error:

C:\buildbot\as-builder-10\lldb-x86-64\llvm-project\lldb\test\Shell\Recognizer\ubsan_add_overflow.test:7:10: error: CHECK: expected string not found in input
# | # CHECK: thread #{{.*}} stop reason = Undefined Behavior Sanitizer: Integer addition overflowed
# |          ^

https://lab.llvm.org/buildbot/#/builders/211/builds/945/steps/10/logs/stdio

https://lab.llvm.org/buildbot/#/builders/211/builds/945

Could you please take a look at it?

@Michael137
Copy link
Member

Apparently, these changes break lldb-x86_64-win buildbot with the following error:

C:\buildbot\as-builder-10\lldb-x86-64\llvm-project\lldb\test\Shell\Recognizer\ubsan_add_overflow.test:7:10: error: CHECK: expected string not found in input
# | # CHECK: thread #{{.*}} stop reason = Undefined Behavior Sanitizer: Integer addition overflowed
# |          ^

https://lab.llvm.org/buildbot/#/builders/211/builds/945/steps/10/logs/stdio

https://lab.llvm.org/buildbot/#/builders/211/builds/945

Could you please take a look at it?

I skipped it on Windows in 21bf2fa

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.

6 participants