@@ -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 (
0 commit comments