9
9
from lldbsuite .test import lldbplatform
10
10
from lldbsuite .test import lldbutil
11
11
12
+ from functionalities .libsanitizers .util import no_libsanitizers
12
13
13
14
class AsanTestCase (TestBase ):
14
15
@skipIfFreeBSD # llvm.org/pr21136 runtimes not yet available by default
15
16
@expectedFailureNetBSD
16
17
@skipUnlessAddressSanitizer
17
18
def test (self ):
18
- self .build ()
19
+ self .build (make_targets = [ "asan" ] )
19
20
self .asan_tests ()
20
21
22
+ @skipIf (oslist = no_match (["macosx" ]))
23
+ def test_libsanitizers_asan (self ):
24
+ self .build (make_targets = ["libsanitizers" ])
25
+ self .libsanitizer_tests ()
26
+
21
27
def setUp (self ):
22
28
# Call super's setUp().
23
29
TestBase .setUp (self )
@@ -26,6 +32,71 @@ def setUp(self):
26
32
self .line_free = line_number ("main.c" , "// free line" )
27
33
self .line_breakpoint = line_number ("main.c" , "// break line" )
28
34
35
+ # Test line numbers: rdar://126237493
36
+ def libsanitizer_tests (self ):
37
+ target = self .createTestTarget ()
38
+
39
+ if no_libsanitizers (self ):
40
+ self .skipTest ("libsanitizers not found" )
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
56
+ self .expect (
57
+ "memory history 'pointer'" ,
58
+ substrs = [
59
+ "Memory deallocated by Thread" ,
60
+ "a.out`f2" ,
61
+ "main.c" ,
62
+ "Memory allocated by Thread" ,
63
+ "a.out`f1" ,
64
+ "main.c" ,
65
+ ],
66
+ )
67
+
68
+ # do the same using SB API
69
+ process = self .dbg .GetSelectedTarget ().process
70
+ val = (
71
+ process .GetSelectedThread ().GetSelectedFrame ().EvaluateExpression ("pointer" )
72
+ )
73
+ addr = val .GetValueAsUnsigned ()
74
+ threads = process .GetHistoryThreads (addr )
75
+ self .assertEqual (threads .GetSize (), 2 )
76
+
77
+ history_thread = threads .GetThreadAtIndex (0 )
78
+ self .assertTrue (history_thread .num_frames >= 2 )
79
+ self .assertEqual (
80
+ history_thread .frames [1 ].GetLineEntry ().GetFileSpec ().GetFilename (),
81
+ "main.c" ,
82
+ )
83
+
84
+ history_thread = threads .GetThreadAtIndex (1 )
85
+ self .assertTrue (history_thread .num_frames >= 2 )
86
+ self .assertEqual (
87
+ history_thread .frames [1 ].GetLineEntry ().GetFileSpec ().GetFilename (),
88
+ "main.c" ,
89
+ )
90
+
91
+ # let's free the container (SBThreadCollection) and see if the
92
+ # SBThreads still live
93
+ threads = None
94
+ self .assertTrue (history_thread .num_frames >= 2 )
95
+ self .assertEqual (
96
+ history_thread .frames [1 ].GetLineEntry ().GetFileSpec ().GetFilename (),
97
+ "main.c" ,
98
+ )
99
+
29
100
def asan_tests (self ):
30
101
target = self .createTestTarget ()
31
102
0 commit comments