@@ -15,9 +15,14 @@ class AsanTestCase(TestBase):
15
15
@expectedFailureNetBSD
16
16
@skipUnlessAddressSanitizer
17
17
def test (self ):
18
- self .build ()
18
+ self .build (make_targets = [ "asan" ] )
19
19
self .asan_tests ()
20
20
21
+ @skipIf (oslist = no_match (["macosx" ]))
22
+ def test_libsanitizers_asan (self ):
23
+ self .build (make_targets = ["libsanitizers" ])
24
+ self .libsanitizer_tests ()
25
+
21
26
def setUp (self ):
22
27
# Call super's setUp().
23
28
TestBase .setUp (self )
@@ -26,6 +31,67 @@ def setUp(self):
26
31
self .line_free = line_number ("main.c" , "// free line" )
27
32
self .line_breakpoint = line_number ("main.c" , "// break line" )
28
33
34
+ # Test line numbers: rdar://126237493
35
+ def libsanitizer_tests (self ):
36
+ target = self .createTestTarget ()
37
+
38
+ self .runCmd (
39
+ "env SanitizersAddress=1 MallocSanitizerZone=1 MallocSecureAllocator=0"
40
+ )
41
+
42
+ self .runCmd ("run" )
43
+ # In libsanitizers, memory history is not supported until a report has been generated
44
+ # test the 'memory history' command
45
+ self .expect (
46
+ "memory history 'pointer'" ,
47
+ substrs = [
48
+ "Memory deallocated by Thread" ,
49
+ "a.out`f2" ,
50
+ "main.c" ,
51
+ "Memory allocated by Thread" ,
52
+ "a.out`f1" ,
53
+ "main.c" ,
54
+ ],
55
+ )
56
+
57
+ # do the same using SB API
58
+ process = self .dbg .GetSelectedTarget ().process
59
+ val = (
60
+ process .GetSelectedThread ().GetSelectedFrame ().EvaluateExpression ("pointer" )
61
+ )
62
+ addr = val .GetValueAsUnsigned ()
63
+ threads = process .GetHistoryThreads (addr )
64
+ self .assertEqual (threads .GetSize (), 2 )
65
+
66
+ history_thread = threads .GetThreadAtIndex (0 )
67
+ self .assertTrue (history_thread .num_frames >= 2 )
68
+ self .assertEqual (
69
+ history_thread .frames [1 ].GetLineEntry ().GetFileSpec ().GetFilename (),
70
+ "main.c" ,
71
+ )
72
+
73
+ history_thread = threads .GetThreadAtIndex (1 )
74
+ self .assertTrue (history_thread .num_frames >= 2 )
75
+ self .assertEqual (
76
+ history_thread .frames [1 ].GetLineEntry ().GetFileSpec ().GetFilename (),
77
+ "main.c" ,
78
+ )
79
+
80
+ # let's free the container (SBThreadCollection) and see if the
81
+ # SBThreads still live
82
+ threads = None
83
+ self .assertTrue (history_thread .num_frames >= 2 )
84
+ self .assertEqual (
85
+ history_thread .frames [1 ].GetLineEntry ().GetFileSpec ().GetFilename (),
86
+ "main.c" ,
87
+ )
88
+
89
+ self .expect (
90
+ "thread list" ,
91
+ "Process should be stopped due to ASan report" ,
92
+ substrs = ["stopped" , "stop reason = Use of deallocated memory" ],
93
+ )
94
+
29
95
def asan_tests (self ):
30
96
target = self .createTestTarget ()
31
97
0 commit comments