10
10
from lldbsuite .test import lldbutil
11
11
from lldbsuite .test_event .build_exception import BuildError
12
12
13
- class AsanTestCase (TestBase ):
13
+ class MemoryHistoryTestCase (TestBase ):
14
14
@skipIfFreeBSD # llvm.org/pr21136 runtimes not yet available by default
15
15
@expectedFailureNetBSD
16
16
@skipUnlessAddressSanitizer
17
- def test (self ):
18
- self .build (make_targets = ["asan" ])
19
- self .asan_tests ()
17
+ def test_compiler_rt_asan (self ):
18
+ self .build (make_targets = ["compiler_rt- asan" ])
19
+ self .compiler_rt_asan_tests ()
20
20
21
- @skipIf ( oslist = no_match ([ "macosx" ]))
22
- @skipIf (bugnumber = "rdar://144997976 " )
21
+ @skipUnlessDarwin
22
+ @skipIf (bugnumber = "rdar://109913184&143590169 " )
23
23
def test_libsanitizers_asan (self ):
24
24
try :
25
- self .build (make_targets = ["libsanitizers" ])
25
+ self .build (make_targets = ["libsanitizers-asan " ])
26
26
except BuildError as e :
27
27
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 ()
29
35
30
36
def setUp (self ):
31
37
# Call super's setUp().
@@ -36,35 +42,60 @@ def setUp(self):
36
42
self .line_breakpoint = line_number ("main.c" , "// break line" )
37
43
38
44
# Test line numbers: rdar://126237493
39
- def libsanitizer_tests (self ):
40
- target = self .createTestTarget ()
41
-
42
- self .runCmd (
43
- "env SanitizersAddress=1 MallocSanitizerZone=1 MallocSecureAllocator=0"
44
- )
45
-
46
- self .runCmd ("run" )
47
-
48
- # In libsanitizers, memory history is not supported until a report has been generated
49
- self .expect (
50
- "thread list" ,
51
- "Process should be stopped due to ASan report" ,
52
- substrs = ["stopped" , "stop reason = Use of deallocated memory" ],
53
- )
54
-
55
- # test the 'memory history' command
45
+ # for libsanitizers and remove `skip_line_numbers` parameter
46
+ def check_traces (self , skip_line_numbers = False ):
56
47
self .expect (
57
48
"memory history 'pointer'" ,
58
49
substrs = [
59
50
"Memory deallocated by Thread" ,
60
51
"a.out`f2" ,
61
- "main.c" ,
52
+ "main.c" if skip_line_numbers else f"main.c: { self . line_free } " ,
62
53
"Memory allocated by Thread" ,
63
54
"a.out`f1" ,
64
- "main.c" ,
55
+ "main.c" if skip_line_numbers else f"main.c: { self . line_malloc } " ,
65
56
],
66
57
)
67
58
59
+ # Set breakpoint: after free, but before bug
60
+ def set_breakpoint (self , target ):
61
+ bkpt = target .BreakpointCreateByLocation ("main.c" , self .line_breakpoint )
62
+ self .assertGreater (bkpt .GetNumLocations (), 0 , "Set the breakpoint successfully" )
63
+
64
+ def run_to_breakpoint (self , target ):
65
+ self .set_breakpoint (target )
66
+ self .runCmd ("run" )
67
+ self .expect (
68
+ "thread list" ,
69
+ STOPPED_DUE_TO_BREAKPOINT ,
70
+ substrs = ["stopped" , "stop reason = breakpoint" ],
71
+ )
72
+
73
+ def libsanitizers_traces_tests (self ):
74
+ target = self .createTestTarget ()
75
+
76
+ self .runCmd ("env SanitizersAllocationTraces=all" )
77
+
78
+ self .run_to_breakpoint (target )
79
+ self .check_traces (skip_line_numbers = True )
80
+
81
+ def libsanitizers_asan_tests (self ):
82
+ target = self .createTestTarget ()
83
+
84
+ self .runCmd ("env SanitizersAddress=1 MallocSanitizerZone=1" )
85
+
86
+ self .run_to_breakpoint (target )
87
+ self .check_traces (skip_line_numbers = True )
88
+
89
+ self .runCmd ("continue" )
90
+
91
+ # Stop on report
92
+ self .expect (
93
+ "thread list" ,
94
+ "Process should be stopped due to ASan report" ,
95
+ substrs = ["stopped" , "stop reason = Use of deallocated memory" ],
96
+ )
97
+ self .check_traces (skip_line_numbers = True )
98
+
68
99
# do the same using SB API
69
100
process = self .dbg .GetSelectedTarget ().process
70
101
val = (
@@ -97,12 +128,12 @@ def libsanitizer_tests(self):
97
128
"main.c" ,
98
129
)
99
130
100
- def asan_tests (self ):
131
+ def compiler_rt_asan_tests (self ):
101
132
target = self .createTestTarget ()
102
133
103
134
self .registerSanitizerLibrariesWithTarget (target )
104
135
105
- self .runCmd ( "breakpoint set -f main.c -l %d" % self . line_breakpoint )
136
+ self .set_breakpoint ( target )
106
137
107
138
# "memory history" command should not work without a process
108
139
self .expect (
@@ -135,18 +166,7 @@ def asan_tests(self):
135
166
substrs = ["1 match found" ],
136
167
)
137
168
138
- # test the 'memory history' command
139
- self .expect (
140
- "memory history 'pointer'" ,
141
- substrs = [
142
- "Memory deallocated by Thread" ,
143
- "a.out`f2" ,
144
- "main.c:%d" % self .line_free ,
145
- "Memory allocated by Thread" ,
146
- "a.out`f1" ,
147
- "main.c:%d" % self .line_malloc ,
148
- ],
149
- )
169
+ self .check_traces ()
150
170
151
171
# do the same using SB API
152
172
process = self .dbg .GetSelectedTarget ().process
@@ -198,6 +218,8 @@ def asan_tests(self):
198
218
substrs = ["stopped" , "stop reason = Use of deallocated memory" ],
199
219
)
200
220
221
+ self .check_traces ()
222
+
201
223
# make sure the 'memory history' command still works even when we're
202
224
# generating a report now
203
225
self .expect (
0 commit comments