2 Tests basic UndefinedBehaviorSanitizer support (detecting an alignment error).
7 from lldbsuite
.test
.lldbtest
import *
8 from lldbsuite
.test
.decorators
import *
9 import lldbsuite
.test
.lldbutil
as lldbutil
13 class UbsanBasicTestCase(TestBase
):
14 @skipUnlessUndefinedBehaviorSanitizer
21 # Call super's setUp().
23 self
.line_align
= line_number("main.c", "// align line")
25 def ubsan_tests(self
):
27 exe
= self
.getBuildArtifact("a.out")
28 target
= self
.dbg
.CreateTarget(exe
)
29 self
.assertTrue(target
, VALID_TARGET
)
30 self
.registerSanitizerLibrariesWithTarget(target
)
34 process
= self
.dbg
.GetSelectedTarget().process
35 thread
= process
.GetSelectedThread()
36 frame
= thread
.GetSelectedFrame()
38 # the stop reason of the thread should be breakpoint.
41 "A ubsan issue should be detected",
42 substrs
=["stopped", "stop reason ="],
45 stop_reason
= thread
.GetStopReason()
46 self
.assertStopReason(stop_reason
, lldb
.eStopReasonInstrumentation
)
48 # test that the UBSan dylib is present
50 "image lookup -n __ubsan_on_report",
51 "__ubsan_on_report should be present",
52 substrs
=["1 match found"],
55 # We should be stopped in __ubsan_on_report
56 self
.assertIn("__ubsan_on_report", frame
.GetFunctionName())
58 # The stopped thread backtrace should contain either 'align line'
60 for i
in range(thread
.GetNumFrames()):
61 frame
= thread
.GetFrameAtIndex(i
)
62 if frame
.GetLineEntry().GetFileSpec().GetFilename() == "main.c":
63 if frame
.GetLineEntry().GetLine() == self
.line_align
:
65 self
.assertTrue(found
)
67 backtraces
= thread
.GetStopReasonExtendedBacktraces(
68 lldb
.eInstrumentationRuntimeTypeUndefinedBehaviorSanitizer
70 self
.assertEqual(backtraces
.GetSize(), 1)
74 "The extended stop info should contain the UBSan provided fields",
79 "instrumentation_class",
85 output_lines
= self
.res
.GetOutput().split("\n")
86 json_line
= "\n".join(output_lines
[2:])
87 data
= json
.loads(json_line
)
89 self
.assertEqual(data
["instrumentation_class"], "UndefinedBehaviorSanitizer")
90 self
.assertEqual(data
["description"], "misaligned-pointer-use")
91 self
.assertEqual(os
.path
.basename(data
["filename"]), "main.c")
92 self
.assertEqual(data
["line"], self
.line_align
)
94 for count
in range(0, 8):
96 stop_reason
= thread
.GetStopReason()
99 lldb
.eStopReasonInstrumentation
,
100 "Round {0} wasn't instrumentation".format(count
),