diff options
author | Vedant Kumar <vsk@apple.com> | 2018-06-22 17:21:17 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2018-06-22 17:21:17 +0000 |
commit | 059d20360a1f872f15f063f89b784ba8352e4e09 (patch) | |
tree | c269a7f67a7449d12e060ccd798603d0e9c96413 /compiler-rt/test | |
parent | 22d1db122a921ed7608519d2461983ed687c5a87 (diff) | |
download | bcm5719-llvm-059d20360a1f872f15f063f89b784ba8352e4e09.tar.gz bcm5719-llvm-059d20360a1f872f15f063f89b784ba8352e4e09.zip |
[ubsan] Add support for reporting diagnostics to a monitor process
Add support to the ubsan runtime for reporting diagnostics to a monitor
process (e.g a debugger).
The Xcode IDE uses this by setting a breakpoint on __ubsan_on_report and
collecting diagnostic information via __ubsan_get_current_report_data,
which it then surfaces to users in the editor UI.
Testing for this functionality already exists in upstream lldb, here:
lldb/packages/Python/lldbsuite/test/functionalities/ubsan
Apart from that, this is `ninja check-{a,ub}san` clean.
Differential Revision: https://reviews.llvm.org/D48446
llvm-svn: 335371
Diffstat (limited to 'compiler-rt/test')
-rw-r--r-- | compiler-rt/test/ubsan/TestCases/Misc/monitor.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/compiler-rt/test/ubsan/TestCases/Misc/monitor.cpp b/compiler-rt/test/ubsan/TestCases/Misc/monitor.cpp new file mode 100644 index 00000000000..78187019c0f --- /dev/null +++ b/compiler-rt/test/ubsan/TestCases/Misc/monitor.cpp @@ -0,0 +1,37 @@ +// RUN: %clangxx -w -fsanitize=bool %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s + +#include <iostream> + +extern "C" { +void __ubsan_get_current_report_data(const char **OutIssueKind, + const char **OutMessage, + const char **OutFilename, + unsigned *OutLine, unsigned *OutCol, + char **OutMemoryAddr); + +// Override the weak definition of __ubsan_on_report from the runtime, just +// for testing purposes. +void __ubsan_on_report(void) { + const char *IssueKind, *Message, *Filename; + unsigned Line, Col; + char *Addr; + __ubsan_get_current_report_data(&IssueKind, &Message, &Filename, &Line, &Col, + &Addr); + + std::cout << "Issue: " << IssueKind << "\n" + << "Location: " << Filename << ":" << Line << ":" << Col << "\n" + << "Message: " << Message << std::endl; + + (void)Addr; +} +} + +int main() { + char C = 3; + bool B = *(bool *)&C; + // CHECK: Issue: invalid-bool-load + // CHECK-NEXT: Location: {{.*}}monitor.cpp:[[@LINE-2]]:12 + // CHECK-NEXT: Message: Load of value 3, which is not a valid value for type 'bool' + return 0; +} |