[Lldb-commits] [lldb] [LLDB] Add integration test for libsanitizers trace collection (PR #134323)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Apr 3 16:45:31 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Julian Lettner (yln)
<details>
<summary>Changes</summary>
Add integration test for libsanitizers trace collection (`SanitizersAllocationTraces=all`).
rdar://144244084
---
Full diff: https://github.com/llvm/llvm-project/pull/134323.diff
3 Files Affected:
- (modified) lldb/test/API/functionalities/asan/Makefile (+7-4)
- (modified) lldb/test/API/functionalities/asan/TestMemoryHistory.py (+58-34)
- (modified) lldb/test/API/functionalities/asan/TestReportData.py (+5-7)
``````````diff
diff --git a/lldb/test/API/functionalities/asan/Makefile b/lldb/test/API/functionalities/asan/Makefile
index d66696fed7078..eae5ca3e4626c 100644
--- a/lldb/test/API/functionalities/asan/Makefile
+++ b/lldb/test/API/functionalities/asan/Makefile
@@ -1,8 +1,11 @@
C_SOURCES := main.c
-asan: CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info
-asan: all
+compiler_rt-asan: CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info
+compiler_rt-asan: all
-libsanitizers: CFLAGS_EXTRAS := -fsanitize=address -fsanitize-stable-abi -g -gcolumn-info
-libsanitizers: all
+libsanitizers-asan: CFLAGS_EXTRAS := -fsanitize=address -fsanitize-stable-abi -g -gcolumn-info
+libsanitizers-asan: all
+
+libsanitizers-traces: CFLAGS_EXTRAS := -g -gcolumn-info
+libsanitizers-traces: all
include Makefile.rules
diff --git a/lldb/test/API/functionalities/asan/TestMemoryHistory.py b/lldb/test/API/functionalities/asan/TestMemoryHistory.py
index b04182a543719..894235481c440 100644
--- a/lldb/test/API/functionalities/asan/TestMemoryHistory.py
+++ b/lldb/test/API/functionalities/asan/TestMemoryHistory.py
@@ -15,17 +15,23 @@ class AsanTestCase(TestBase):
@expectedFailureNetBSD
@skipUnlessAddressSanitizer
def test(self):
- self.build(make_targets=["asan"])
+ self.build(make_targets=["compiler_rt-asan"])
self.asan_tests()
- @skipIf(oslist=no_match(["macosx"]))
- @skipIf(bugnumber="rdar://144997976")
+ @skipUnlessDarwin
+ @skipIf(bugnumber="rdar://109913184&143590169")
def test_libsanitizers_asan(self):
try:
- self.build(make_targets=["libsanitizers"])
+ self.build(make_targets=["libsanitizers-asan"])
except BuildError as e:
self.skipTest("failed to build with libsanitizers")
- self.libsanitizer_tests()
+ self.libsanitizers_asan_tests()
+
+ @skipUnlessDarwin
+ @skipIf(macos_version=["<", "15.5"])
+ def test_libsanitizers_traces(self):
+ self.build(make_targets=["libsanitizers-traces"])
+ self.libsanitizers_traces_tests()
def setUp(self):
# Call super's setUp().
@@ -36,34 +42,61 @@ def setUp(self):
self.line_breakpoint = line_number("main.c", "// break line")
# Test line numbers: rdar://126237493
- def libsanitizer_tests(self):
- target = self.createTestTarget()
+ # for libsanitizers and remove `skip_line_numbers` parameter
+ def check_traces(self, skip_line_numbers):
+ self.expect(
+ "memory history 'pointer'",
+ substrs=[
+ "Memory deallocated by Thread",
+ "a.out`f2",
+ "main.c" if skip_line_numbers else f"main.c:{self.line_free}",
+ "Memory allocated by Thread",
+ "a.out`f1",
+ "main.c" if skip_line_numbers else f"main.c:{self.line_malloc}",
+ ],
+ )
+
+ def libsanitizers_traces_tests(self):
+ self.createTestTarget()
+
+ self.runCmd("env SanitizersAllocationTraces=all")
- self.runCmd(
- "env SanitizersAddress=1 MallocSanitizerZone=1 MallocSecureAllocator=0"
+ self.runCmd("breakpoint set -f main.c -l %d" % self.line_breakpoint)
+ self.runCmd("run")
+
+ # Stop on breakpoint, before report
+ self.expect(
+ "thread list",
+ STOPPED_DUE_TO_BREAKPOINT,
+ substrs=["stopped", "stop reason = breakpoint"],
)
+ self.check_traces(skip_line_numbers=True)
+
+ def libsanitizers_asan_tests(self):
+ self.createTestTarget()
+
+ self.runCmd("env SanitizersAddress=1 MallocSanitizerZone=1")
+ self.runCmd("breakpoint set -f main.c -l %d" % self.line_breakpoint)
self.runCmd("run")
- # In libsanitizers, memory history is not supported until a report has been generated
+ # Stop on breakpoint, before report
self.expect(
"thread list",
- "Process should be stopped due to ASan report",
- substrs=["stopped", "stop reason = Use of deallocated memory"],
+ STOPPED_DUE_TO_BREAKPOINT,
+ substrs=["stopped", "stop reason = breakpoint"],
)
+ self.check_traces(skip_line_numbers=True)
+
+ self.runCmd("continue")
- # test the 'memory history' command
+ # Stop on report
self.expect(
- "memory history 'pointer'",
- substrs=[
- "Memory deallocated by Thread",
- "a.out`f2",
- "main.c",
- "Memory allocated by Thread",
- "a.out`f1",
- "main.c",
- ],
+ "thread list",
+ "Process should be stopped due to ASan report",
+ substrs=["stopped", "stop reason = Use of deallocated memory"],
)
+ self.check_traces(skip_line_numbers=True)
# do the same using SB API
process = self.dbg.GetSelectedTarget().process
@@ -135,18 +168,7 @@ def asan_tests(self):
substrs=["1 match found"],
)
- # test the 'memory history' command
- self.expect(
- "memory history 'pointer'",
- substrs=[
- "Memory deallocated by Thread",
- "a.out`f2",
- "main.c:%d" % self.line_free,
- "Memory allocated by Thread",
- "a.out`f1",
- "main.c:%d" % self.line_malloc,
- ],
- )
+ self.check_traces()
# do the same using SB API
process = self.dbg.GetSelectedTarget().process
@@ -198,6 +220,8 @@ def asan_tests(self):
substrs=["stopped", "stop reason = Use of deallocated memory"],
)
+ self.check_traces()
+
# make sure the 'memory history' command still works even when we're
# generating a report now
self.expect(
diff --git a/lldb/test/API/functionalities/asan/TestReportData.py b/lldb/test/API/functionalities/asan/TestReportData.py
index fabc985d0ed44..dd6834a01b80c 100644
--- a/lldb/test/API/functionalities/asan/TestReportData.py
+++ b/lldb/test/API/functionalities/asan/TestReportData.py
@@ -16,14 +16,14 @@ class AsanTestReportDataCase(TestBase):
@skipUnlessAddressSanitizer
@skipIf(archs=["i386"], bugnumber="llvm.org/PR36710")
def test(self):
- self.build(make_targets=["asan"])
+ self.build(make_targets=["compiler_rt-asan"])
self.asan_tests()
- @skipIf(oslist=no_match(["macosx"]))
- @skipIf(bugnumber="rdar://144997976")
+ @skipUnlessDarwin
+ @skipIf(bugnumber="rdar://109913184&143590169")
def test_libsanitizers_asan(self):
try:
- self.build(make_targets=["libsanitizers"])
+ self.build(make_targets=["libsanitizers-asan"])
except BuildError as e:
self.skipTest("failed to build with libsanitizers")
self.asan_tests(libsanitizers=True)
@@ -42,9 +42,7 @@ def asan_tests(self, libsanitizers=False):
target = self.createTestTarget()
if libsanitizers:
- self.runCmd(
- "env SanitizersAddress=1 MallocSanitizerZone=1 MallocSecureAllocator=0"
- )
+ self.runCmd("env SanitizersAddress=1 MallocSanitizerZone=1")
else:
self.registerSanitizerLibrariesWithTarget(target)
``````````
</details>
https://github.com/llvm/llvm-project/pull/134323
More information about the lldb-commits
mailing list