Skip to content

Commit 803214e

Browse files
committed
[LLDB] Add integration test for libsanitizers trace collection
Add integration test for libsanitizers trace collection (`SanitizersAllocationTraces=all`). rdar://144244084
1 parent 8aa5e0e commit 803214e

File tree

3 files changed

+67
-38
lines changed

3 files changed

+67
-38
lines changed
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
C_SOURCES := main.c
2-
asan: CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info
3-
asan: all
2+
compiler_rt-asan: CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info
3+
compiler_rt-asan: all
44

5-
libsanitizers: CFLAGS_EXTRAS := -fsanitize=address -fsanitize-stable-abi -g -gcolumn-info
6-
libsanitizers: all
5+
libsanitizers-asan: CFLAGS_EXTRAS := -fsanitize=address -fsanitize-stable-abi -g -gcolumn-info
6+
libsanitizers-asan: all
7+
8+
libsanitizers-traces: CFLAGS_EXTRAS := -g -gcolumn-info
9+
libsanitizers-traces: all
710

811
include Makefile.rules

lldb/test/API/functionalities/asan/TestMemoryHistory.py

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,23 @@ class AsanTestCase(TestBase):
1515
@expectedFailureNetBSD
1616
@skipUnlessAddressSanitizer
1717
def test(self):
18-
self.build(make_targets=["asan"])
18+
self.build(make_targets=["compiler_rt-asan"])
1919
self.asan_tests()
2020

21-
@skipIf(oslist=no_match(["macosx"]))
21+
@skipUnlessDarwin
2222
@skipIf(bugnumber="rdar://109913184&143590169")
2323
def test_libsanitizers_asan(self):
2424
try:
25-
self.build(make_targets=["libsanitizers"])
25+
self.build(make_targets=["libsanitizers-asan"])
2626
except BuildError as e:
2727
self.skipTest("failed to build with libsanitizers")
28-
self.libsanitizer_tests()
28+
self.libsanitizers_asan_tests()
29+
30+
@skipUnlessDarwin
31+
@skipIf(macos_version=["<", "15.5"])
32+
def test_libsanitizers_traces(self):
33+
self.build(make_targets=["libsanitizers-traces"])
34+
self.libsanitizers_traces_tests()
2935

3036
def setUp(self):
3137
# Call super's setUp().
@@ -36,32 +42,61 @@ def setUp(self):
3642
self.line_breakpoint = line_number("main.c", "// break line")
3743

3844
# Test line numbers: rdar://126237493
39-
def libsanitizer_tests(self):
40-
target = self.createTestTarget()
45+
# for libsanitizers and remove `skip_line_numbers` parameter
46+
def check_traces(self, skip_line_numbers):
47+
self.expect(
48+
"memory history 'pointer'",
49+
substrs=[
50+
"Memory deallocated by Thread",
51+
"a.out`f2",
52+
"main.c" if skip_line_numbers else f"main.c:{self.line_free}",
53+
"Memory allocated by Thread",
54+
"a.out`f1",
55+
"main.c" if skip_line_numbers else f"main.c:{self.line_malloc}",
56+
],
57+
)
58+
59+
def libsanitizers_traces_tests(self):
60+
self.createTestTarget()
61+
62+
self.runCmd("env SanitizersAllocationTraces=all")
63+
64+
self.runCmd("breakpoint set -f main.c -l %d" % self.line_breakpoint)
65+
self.runCmd("run")
66+
67+
# Stop on breakpoint, before report
68+
self.expect(
69+
"thread list",
70+
STOPPED_DUE_TO_BREAKPOINT,
71+
substrs=["stopped", "stop reason = breakpoint"],
72+
)
73+
self.check_traces(skip_line_numbers=True)
74+
75+
def libsanitizers_asan_tests(self):
76+
self.createTestTarget()
4177

4278
self.runCmd("env SanitizersAddress=1 MallocSanitizerZone=1")
4379

80+
self.runCmd("breakpoint set -f main.c -l %d" % self.line_breakpoint)
4481
self.runCmd("run")
4582

46-
# In libsanitizers, memory history is not supported until a report has been generated
83+
# Stop on breakpoint, before report
4784
self.expect(
4885
"thread list",
49-
"Process should be stopped due to ASan report",
50-
substrs=["stopped", "stop reason = Use of deallocated memory"],
86+
STOPPED_DUE_TO_BREAKPOINT,
87+
substrs=["stopped", "stop reason = breakpoint"],
5188
)
89+
self.check_traces(skip_line_numbers=True)
5290

53-
# test the 'memory history' command
91+
self.runCmd("continue")
92+
93+
# Stop on report
5494
self.expect(
55-
"memory history 'pointer'",
56-
substrs=[
57-
"Memory deallocated by Thread",
58-
"a.out`f2",
59-
"main.c",
60-
"Memory allocated by Thread",
61-
"a.out`f1",
62-
"main.c",
63-
],
95+
"thread list",
96+
"Process should be stopped due to ASan report",
97+
substrs=["stopped", "stop reason = Use of deallocated memory"],
6498
)
99+
self.check_traces(skip_line_numbers=True)
65100

66101
# do the same using SB API
67102
process = self.dbg.GetSelectedTarget().process
@@ -133,18 +168,7 @@ def asan_tests(self):
133168
substrs=["1 match found"],
134169
)
135170

136-
# test the 'memory history' command
137-
self.expect(
138-
"memory history 'pointer'",
139-
substrs=[
140-
"Memory deallocated by Thread",
141-
"a.out`f2",
142-
"main.c:%d" % self.line_free,
143-
"Memory allocated by Thread",
144-
"a.out`f1",
145-
"main.c:%d" % self.line_malloc,
146-
],
147-
)
171+
self.check_traces()
148172

149173
# do the same using SB API
150174
process = self.dbg.GetSelectedTarget().process
@@ -196,6 +220,8 @@ def asan_tests(self):
196220
substrs=["stopped", "stop reason = Use of deallocated memory"],
197221
)
198222

223+
self.check_traces()
224+
199225
# make sure the 'memory history' command still works even when we're
200226
# generating a report now
201227
self.expect(

lldb/test/API/functionalities/asan/TestReportData.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ class AsanTestReportDataCase(TestBase):
1616
@skipUnlessAddressSanitizer
1717
@skipIf(archs=["i386"], bugnumber="llvm.org/PR36710")
1818
def test(self):
19-
self.build(make_targets=["asan"])
19+
self.build(make_targets=["compiler_rt-asan"])
2020
self.asan_tests()
2121

22-
@skipIf(oslist=no_match(["macosx"]))
22+
@skipUnlessDarwin
2323
@skipIf(bugnumber="rdar://109913184&143590169")
2424
def test_libsanitizers_asan(self):
2525
try:
26-
self.build(make_targets=["libsanitizers"])
26+
self.build(make_targets=["libsanitizers-asan"])
2727
except BuildError as e:
2828
self.skipTest("failed to build with libsanitizers")
2929
self.asan_tests(libsanitizers=True)

0 commit comments

Comments
 (0)