8
8
from lldbsuite .test .lldbtest import *
9
9
from lldbsuite .test import lldbplatform
10
10
from lldbsuite .test import lldbutil
11
-
11
+ from lldbsuite . test_event . build_exception import BuildError
12
12
13
13
class AsanTestCase (TestBase ):
14
14
@skipIfFreeBSD # llvm.org/pr21136 runtimes not yet available by default
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
+ try :
24
+ self .build (make_targets = ["libsanitizers" ])
25
+ except BuildError as e :
26
+ self .skipTest ("failed to build with libsanitizers" )
27
+ self .libsanitizer_tests ()
28
+
21
29
def setUp (self ):
22
30
# Call super's setUp().
23
31
TestBase .setUp (self )
@@ -26,6 +34,68 @@ def setUp(self):
26
34
self .line_free = line_number ("main.c" , "// free line" )
27
35
self .line_breakpoint = line_number ("main.c" , "// break line" )
28
36
37
+ # Test line numbers: rdar://126237493
38
+ def libsanitizer_tests (self ):
39
+ target = self .createTestTarget ()
40
+
41
+ self .runCmd (
42
+ "env SanitizersAddress=1 MallocSanitizerZone=1 MallocSecureAllocator=0"
43
+ )
44
+
45
+ self .runCmd ("run" )
46
+
47
+ # In libsanitizers, memory history is not supported until a report has been generated
48
+ self .expect (
49
+ "thread list" ,
50
+ "Process should be stopped due to ASan report" ,
51
+ substrs = ["stopped" , "stop reason = Use of deallocated memory" ],
52
+ )
53
+
54
+ # test the 'memory history' command
55
+ self .expect (
56
+ "memory history 'pointer'" ,
57
+ substrs = [
58
+ "Memory deallocated by Thread" ,
59
+ "a.out`f2" ,
60
+ "main.c" ,
61
+ "Memory allocated by Thread" ,
62
+ "a.out`f1" ,
63
+ "main.c" ,
64
+ ],
65
+ )
66
+
67
+ # do the same using SB API
68
+ process = self .dbg .GetSelectedTarget ().process
69
+ val = (
70
+ process .GetSelectedThread ().GetSelectedFrame ().EvaluateExpression ("pointer" )
71
+ )
72
+ addr = val .GetValueAsUnsigned ()
73
+ threads = process .GetHistoryThreads (addr )
74
+ self .assertEqual (threads .GetSize (), 2 )
75
+
76
+ history_thread = threads .GetThreadAtIndex (0 )
77
+ self .assertTrue (history_thread .num_frames >= 2 )
78
+ self .assertEqual (
79
+ history_thread .frames [1 ].GetLineEntry ().GetFileSpec ().GetFilename (),
80
+ "main.c" ,
81
+ )
82
+
83
+ history_thread = threads .GetThreadAtIndex (1 )
84
+ self .assertTrue (history_thread .num_frames >= 2 )
85
+ self .assertEqual (
86
+ history_thread .frames [1 ].GetLineEntry ().GetFileSpec ().GetFilename (),
87
+ "main.c" ,
88
+ )
89
+
90
+ # let's free the container (SBThreadCollection) and see if the
91
+ # SBThreads still live
92
+ threads = None
93
+ self .assertTrue (history_thread .num_frames >= 2 )
94
+ self .assertEqual (
95
+ history_thread .frames [1 ].GetLineEntry ().GetFileSpec ().GetFilename (),
96
+ "main.c" ,
97
+ )
98
+
29
99
def asan_tests (self ):
30
100
target = self .createTestTarget ()
31
101
0 commit comments