Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@ -0,0 +1,6 @@
LEVEL = ../../../make
C_SOURCES := main.c
CFLAGS_EXTRAS := -fsanitize=undefined -g
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,90 @@
"""
Tests basic UndefinedBehaviorSanitizer support (detecting an alignment error).
"""
import os
import time
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import json
class UbsanBasicTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
@skipUnlessUndefinedBehaviorSanitizer
def test(self):
self.build()
self.ubsan_tests()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
self.line_align = line_number('main.c', '// align line')
def ubsan_tests(self):
# Load the test
exe = os.path.join(os.getcwd(), "a.out")
self.expect(
"file " + exe,
patterns=["Current executable set to .*a.out"])
self.runCmd("run")
process = self.dbg.GetSelectedTarget().process
thread = process.GetSelectedThread()
frame = thread.GetSelectedFrame()
# the stop reason of the thread should be breakpoint.
self.expect("thread list", "A ubsan issue should be detected",
substrs=['stopped', 'stop reason ='])
stop_reason = thread.GetStopReason()
self.assertEqual(stop_reason, lldb.eStopReasonInstrumentation)
# test that the UBSan dylib is present
self.expect(
"image lookup -n __ubsan_on_report",
"__ubsan_on_report should be present",
substrs=['1 match found'])
# We should be stopped in __ubsan_on_report
self.assertTrue("__ubsan_on_report" in frame.GetFunctionName())
# The stopped thread backtrace should contain either 'align line'
found = False
for i in range(thread.GetNumFrames()):
frame = thread.GetFrameAtIndex(i)
if frame.GetLineEntry().GetFileSpec().GetFilename() == "main.c":
if frame.GetLineEntry().GetLine() == self.line_align:
found = True
self.assertTrue(found)
backtraces = thread.GetStopReasonExtendedBacktraces(
lldb.eInstrumentationRuntimeTypeUndefinedBehaviorSanitizer)
self.assertTrue(backtraces.GetSize() == 1)
self.expect(
"thread info -s",
"The extended stop info should contain the UBSan provided fields",
substrs=[
"instrumentation_class",
"memory_address",
"description",
"filename",
"line",
"col"])
output_lines = self.res.GetOutput().split('\n')
json_line = '\n'.join(output_lines[2:])
data = json.loads(json_line)
self.assertEqual(data["instrumentation_class"], "UndefinedBehaviorSanitizer")
self.assertEqual(data["description"], "misaligned-pointer-use")
self.assertEqual(data["filename"], "main.c")
self.assertEqual(data["line"], self.line_align)
self.runCmd("continue")

View File

@ -0,0 +1,4 @@
int main() {
int data[4];
return *(int *)(((char *)&data[0]) + 2); // align line
}

View File

@ -0,0 +1,6 @@
LEVEL = ../../../make
C_SOURCES := main.c
CFLAGS_EXTRAS := -fsanitize=undefined -g
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,49 @@
"""
Test that hitting a UBSan issue while running user expression doesn't break the evaluation.
"""
import os
import time
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import json
class UbsanUserExpressionTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
@skipUnlessUndefinedBehaviorSanitizer
def test(self):
self.build()
self.ubsan_tests()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
self.line_breakpoint = line_number('main.c', '// breakpoint line')
def ubsan_tests(self):
# Load the test
exe = os.path.join(os.getcwd(), "a.out")
self.expect(
"file " + exe,
patterns=["Current executable set to .*a.out"])
self.runCmd("breakpoint set -f main.c -l %d" % self.line_breakpoint)
self.runCmd("run")
process = self.dbg.GetSelectedTarget().process
thread = process.GetSelectedThread()
frame = thread.GetSelectedFrame()
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped', 'stop reason = breakpoint'])
self.expect("p foo()", substrs=["(int) $0 = 42"])
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped', 'stop reason = breakpoint'])

View File

@ -0,0 +1,9 @@
int foo() {
int data[4];
int x = *(int *)(((char *)&data[0]) + 2);
return 42;
}
int main() {
return 0; // breakpoint line
}