@@ -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,68 @@ 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
+
44
+ # In libsanitizers, memory history is not supported until a report has been generated
45
+ self .expect (
46
+ "thread list" ,
47
+ "Process should be stopped due to ASan report" ,
48
+ substrs = ["stopped" , "stop reason = Use of deallocated memory" ],
49
+ )
50
+
51
+ # test the 'memory history' command
52
+ self .expect (
53
+ "memory history 'pointer'" ,
54
+ substrs = [
55
+ "Memory deallocated by Thread" ,
56
+ "a.out`f2" ,
57
+ "main.c" ,
58
+ "Memory allocated by Thread" ,
59
+ "a.out`f1" ,
60
+ "main.c" ,
61
+ ],
62
+ )
63
+
64
+ # do the same using SB API
65
+ process = self .dbg .GetSelectedTarget ().process
66
+ val = (
67
+ process .GetSelectedThread ().GetSelectedFrame ().EvaluateExpression ("pointer" )
68
+ )
69
+ addr = val .GetValueAsUnsigned ()
70
+ threads = process .GetHistoryThreads (addr )
71
+ self .assertEqual (threads .GetSize (), 2 )
72
+
73
+ history_thread = threads .GetThreadAtIndex (0 )
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
+ history_thread = threads .GetThreadAtIndex (1 )
81
+ self .assertTrue (history_thread .num_frames >= 2 )
82
+ self .assertEqual (
83
+ history_thread .frames [1 ].GetLineEntry ().GetFileSpec ().GetFilename (),
84
+ "main.c" ,
85
+ )
86
+
87
+ # let's free the container (SBThreadCollection) and see if the
88
+ # SBThreads still live
89
+ threads = None
90
+ self .assertTrue (history_thread .num_frames >= 2 )
91
+ self .assertEqual (
92
+ history_thread .frames [1 ].GetLineEntry ().GetFileSpec ().GetFilename (),
93
+ "main.c" ,
94
+ )
95
+
29
96
def asan_tests (self ):
30
97
target = self .createTestTarget ()
31
98
0 commit comments