99from lldbsuite .test import lldbplatform
1010from lldbsuite .test import lldbutil
1111
12+ from functionalities .libsanitizers .util import no_libsanitizers
1213
1314class AsanTestCase (TestBase ):
1415 @skipIfFreeBSD # llvm.org/pr21136 runtimes not yet available by default
1516 @expectedFailureNetBSD
1617 @skipUnlessAddressSanitizer
1718 def test (self ):
18- self .build ()
19+ self .build (make_targets = [ "asan" ] )
1920 self .asan_tests ()
2021
22+ @skipIf (oslist = no_match (["macosx" ]))
23+ def test_libsanitizers_asan (self ):
24+ self .build (make_targets = ["libsanitizers" ])
25+ self .libsanitizer_tests ()
26+
2127 def setUp (self ):
2228 # Call super's setUp().
2329 TestBase .setUp (self )
@@ -26,6 +32,71 @@ def setUp(self):
2632 self .line_free = line_number ("main.c" , "// free line" )
2733 self .line_breakpoint = line_number ("main.c" , "// break line" )
2834
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+
29100 def asan_tests (self ):
30101 target = self .createTestTarget ()
31102
0 commit comments