forked from OSchip/llvm-project
[ASan] Add process basename to log name and error message to
simplify analysis of sanitized systems logs. Differential Revision: http://reviews.llvm.org/D7333 llvm-svn: 239134
This commit is contained in:
parent
d8308fbed9
commit
2d45554b82
|
@ -57,7 +57,13 @@ void ReportFile::ReopenIfNecessary() {
|
||||||
CloseFile(fd);
|
CloseFile(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *exe_name = GetBinaryBasename();
|
||||||
|
if (common_flags()->log_exe_name && exe_name) {
|
||||||
|
internal_snprintf(full_path, kMaxPathLength, "%s.%s.%zu", path_prefix,
|
||||||
|
exe_name, pid);
|
||||||
|
} else {
|
||||||
internal_snprintf(full_path, kMaxPathLength, "%s.%zu", path_prefix, pid);
|
internal_snprintf(full_path, kMaxPathLength, "%s.%zu", path_prefix, pid);
|
||||||
|
}
|
||||||
fd = OpenFile(full_path, WrOnly);
|
fd = OpenFile(full_path, WrOnly);
|
||||||
if (fd == kInvalidFd) {
|
if (fd == kInvalidFd) {
|
||||||
const char *ErrorMsgPrefix = "ERROR: Can't open file: ";
|
const char *ErrorMsgPrefix = "ERROR: Can't open file: ";
|
||||||
|
|
|
@ -50,6 +50,10 @@ COMMON_FLAG(
|
||||||
const char *, log_path, "stderr",
|
const char *, log_path, "stderr",
|
||||||
"Write logs to \"log_path.pid\". The special values are \"stdout\" and "
|
"Write logs to \"log_path.pid\". The special values are \"stdout\" and "
|
||||||
"\"stderr\". The default is \"stderr\".")
|
"\"stderr\". The default is \"stderr\".")
|
||||||
|
COMMON_FLAG(
|
||||||
|
bool, log_exe_name, false,
|
||||||
|
"Mention name of executable when reporting error and "
|
||||||
|
"append executable name to logs (as in \"log_path.exe_name.pid\").")
|
||||||
COMMON_FLAG(
|
COMMON_FLAG(
|
||||||
int, verbosity, 0,
|
int, verbosity, 0,
|
||||||
"Verbosity level (0 - silent, 1 - a bit of output, 2+ - more output).")
|
"Verbosity level (0 - silent, 1 - a bit of output, 2+ - more output).")
|
||||||
|
|
|
@ -251,26 +251,32 @@ static void SharedPrintfCode(bool append_pid, const char *format,
|
||||||
buffer_size = kLen;
|
buffer_size = kLen;
|
||||||
}
|
}
|
||||||
needed_length = 0;
|
needed_length = 0;
|
||||||
|
// Check that data fits into the current buffer.
|
||||||
|
# define CHECK_NEEDED_LENGTH \
|
||||||
|
if (needed_length >= buffer_size) { \
|
||||||
|
if (!use_mmap) continue; \
|
||||||
|
RAW_CHECK_MSG(needed_length < kLen, \
|
||||||
|
"Buffer in Report is too short!\n"); \
|
||||||
|
}
|
||||||
if (append_pid) {
|
if (append_pid) {
|
||||||
int pid = internal_getpid();
|
int pid = internal_getpid();
|
||||||
needed_length += internal_snprintf(buffer, buffer_size, "==%d==", pid);
|
const char *exe_name = GetBinaryBasename();
|
||||||
if (needed_length >= buffer_size) {
|
if (common_flags()->log_exe_name && exe_name) {
|
||||||
// The pid doesn't fit into the current buffer.
|
needed_length += internal_snprintf(buffer, buffer_size,
|
||||||
if (!use_mmap)
|
"==%s", exe_name);
|
||||||
continue;
|
CHECK_NEEDED_LENGTH
|
||||||
RAW_CHECK_MSG(needed_length < kLen, "Buffer in Report is too short!\n");
|
|
||||||
}
|
}
|
||||||
|
needed_length += internal_snprintf(buffer + needed_length,
|
||||||
|
buffer_size - needed_length,
|
||||||
|
"==%d==", pid);
|
||||||
|
CHECK_NEEDED_LENGTH
|
||||||
}
|
}
|
||||||
needed_length += VSNPrintf(buffer + needed_length,
|
needed_length += VSNPrintf(buffer + needed_length,
|
||||||
buffer_size - needed_length, format, args);
|
buffer_size - needed_length, format, args);
|
||||||
if (needed_length >= buffer_size) {
|
CHECK_NEEDED_LENGTH
|
||||||
// The message doesn't fit into the current buffer.
|
|
||||||
if (!use_mmap)
|
|
||||||
continue;
|
|
||||||
RAW_CHECK_MSG(needed_length < kLen, "Buffer in Report is too short!\n");
|
|
||||||
}
|
|
||||||
// If the message fit into the buffer, print it and exit.
|
// If the message fit into the buffer, print it and exit.
|
||||||
break;
|
break;
|
||||||
|
# undef CHECK_NEEDED_LENGTH
|
||||||
}
|
}
|
||||||
RawWrite(buffer);
|
RawWrite(buffer);
|
||||||
AndroidLogWrite(buffer);
|
AndroidLogWrite(buffer);
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
// RUN: %clangxx_asan %s -o %T/verbose-log-path_test-binary
|
||||||
|
|
||||||
|
// Good log_path.
|
||||||
|
// RUN: rm -f %T/asan.log.*
|
||||||
|
// RUN: env ASAN_OPTIONS=log_path=%T/asan.log:log_exe_name=1 not %run %T/verbose-log-path_test-binary 2> %t.out
|
||||||
|
// RUN: FileCheck %s --check-prefix=CHECK-ERROR < %T/asan.log.verbose-log-path_test-binary.*
|
||||||
|
|
||||||
|
// FIXME: only FreeBSD and Linux have verbose log paths now.
|
||||||
|
// XFAIL: win32,android,darwin
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
if (argc > 2) return 0;
|
||||||
|
char *x = (char*)malloc(10);
|
||||||
|
memset(x, 0, 10);
|
||||||
|
int res = x[argc * 10]; // BOOOM
|
||||||
|
free(x);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
// CHECK-ERROR: ERROR: AddressSanitizer
|
Loading…
Reference in New Issue