-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[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
[lldb][test][NFC] Add LLDB test for UBSan trap frame recognizer #151231
Conversation
@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:
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
|
bb76775
to
bdf7487
Compare
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 |
There was a problem hiding this comment.
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
# RUN: -fsanitize=signed-integer-overflow -fsanitize-trap=signed-integer-overflow | |
# RUN: -fsanitize=signed-integer-overflow -fsanitize-trap=signed-integer-overflow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 \ |
There was a problem hiding this comment.
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.
There are tests for the @anthonyhatran lets put this context into the PR description |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Apparently, these changes break lldb-x86_64-win buildbot with the following error:
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 |
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.