summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/sanitizer_common
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2012-09-14 04:35:14 +0000
committerKostya Serebryany <kcc@google.com>2012-09-14 04:35:14 +0000
commit45d849c4bddc54105f61e6f8864341664d0433ed (patch)
tree0ec94442cc651c7ec7a57cc65cf333351ded78e9 /compiler-rt/lib/sanitizer_common
parent6d149412c8619c83e4ab7de0dbd836d251b015ad (diff)
downloadbcm5719-llvm-45d849c4bddc54105f61e6f8864341664d0433ed.tar.gz
bcm5719-llvm-45d849c4bddc54105f61e6f8864341664d0433ed.zip
[asan] add asan option log_path=PATH to let users redirect asan reports to a file PATH.PID instead of stderr
llvm-svn: 163872
Diffstat (limited to 'compiler-rt/lib/sanitizer_common')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common.cc30
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_printf.cc7
2 files changed, 34 insertions, 3 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc
index 22c7093db5f..614b7b9d465 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc
@@ -16,6 +16,9 @@
namespace __sanitizer {
+static fd_t report_fd = 2; // By default, dump to stderr.
+static char report_path[4096]; // Set via __sanitizer_set_report_path.
+
static void (*DieCallback)(void);
void SetDieCallback(void (*callback)(void)) {
DieCallback = callback;
@@ -46,8 +49,17 @@ void NORETURN CheckFailed(const char *file, int line, const char *cond,
void RawWrite(const char *buffer) {
static const char *kRawWriteError = "RawWrite can't output requested buffer!";
uptr length = (uptr)internal_strlen(buffer);
- if (length != internal_write(2, buffer, length)) {
- internal_write(2, kRawWriteError, internal_strlen(kRawWriteError));
+ if (report_fd == kInvalidFd) {
+ fd_t fd = internal_open(report_path, true);
+ if (fd == kInvalidFd) {
+ report_fd = 2;
+ Report("ERROR: Can't open file: %s\n", report_path);
+ Die();
+ }
+ report_fd = fd;
+ }
+ if (length != internal_write(report_fd, buffer, length)) {
+ internal_write(report_fd, kRawWriteError, internal_strlen(kRawWriteError));
Die();
}
}
@@ -125,3 +137,17 @@ void SortArray(uptr *array, uptr size) {
}
} // namespace __sanitizer
+
+void __sanitizer_set_report_path(const char *path) {
+ if (!path) return;
+ uptr len = internal_strlen(path);
+ if (len > sizeof(__sanitizer::report_path) - 100) {
+ Report("ERROR: Path is too long: %c%c%c%c%c%c%c%c...\n",
+ path[0], path[1], path[2], path[3],
+ path[4], path[5], path[6], path[7]);
+ Die();
+ }
+ internal_snprintf(__sanitizer::report_path,
+ sizeof(__sanitizer::report_path), "%s.%d", path, GetPid());
+ __sanitizer::report_fd = kInvalidFd;
+}
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_printf.cc b/compiler-rt/lib/sanitizer_common/sanitizer_printf.cc
index 22f10fb1a00..6aeedabdf3f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_printf.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_printf.cc
@@ -86,7 +86,7 @@ static int AppendPointer(char **buff, const char *buff_end, u64 ptr_value) {
int VSNPrintf(char *buff, int buff_length,
const char *format, va_list args) {
static const char *kPrintfFormatsHelp = "Supported Printf formats: "
- "%%[z]{d,u,x}; %%p; %%s\n";
+ "%%[z]{d,u,x}; %%p; %%s; %%c\n";
RAW_CHECK(format);
RAW_CHECK(buff_length > 0);
const char *buff_end = &buff[buff_length - 1];
@@ -127,6 +127,11 @@ int VSNPrintf(char *buff, int buff_length,
result += AppendString(&buff, buff_end, va_arg(args, char*));
break;
}
+ case 'c': {
+ RAW_CHECK_MSG(!have_z, kPrintfFormatsHelp);
+ result += AppendChar(&buff, buff_end, va_arg(args, uptr));
+ break;
+ }
case '%' : {
RAW_CHECK_MSG(!have_z, kPrintfFormatsHelp);
result += AppendChar(&buff, buff_end, '%');
OpenPOWER on IntegriCloud