summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2013-10-04 08:55:03 +0000
committerAlexey Samsonov <samsonov@google.com>2013-10-04 08:55:03 +0000
commit90b0f1e3ba126bb2e92ab51ef379c98782c23d90 (patch)
treeeda44d02ca7ca5dd1d2171cb14dcd2cbda7bb293
parent92b54796149a8b5995fa49c43f43b709b83c5644 (diff)
downloadcompiler-rt-90b0f1e3ba126bb2e92ab51ef379c98782c23d90.tar.gz
compiler-rt-90b0f1e3ba126bb2e92ab51ef379c98782c23d90.tar.bz2
compiler-rt-90b0f1e3ba126bb2e92ab51ef379c98782c23d90.tar.xz
Refactor the usage of strip_path_prefix option and make it more consistent across sanitizers
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@191943 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/asan/asan_report.cc5
-rw-r--r--lib/asan/asan_stack.cc4
-rw-r--r--lib/lsan/lsan_common.cc3
-rw-r--r--lib/msan/msan_report.cc8
-rw-r--r--lib/sanitizer_common/sanitizer_common.cc35
-rw-r--r--lib/sanitizer_common/sanitizer_common.h7
-rw-r--r--lib/sanitizer_common/sanitizer_stacktrace.cc45
-rw-r--r--lib/sanitizer_common/sanitizer_stacktrace.h7
-rw-r--r--lib/sanitizer_common/tests/sanitizer_common_test.cc9
-rw-r--r--lib/tsan/rtl/tsan_flags.cc1
-rw-r--r--lib/ubsan/lit_tests/TypeCheck/misaligned.cpp2
-rw-r--r--lib/ubsan/ubsan_diag.cc18
12 files changed, 76 insertions, 68 deletions
diff --git a/lib/asan/asan_report.cc b/lib/asan/asan_report.cc
index 55a9a4ef..6a688452 100644
--- a/lib/asan/asan_report.cc
+++ b/lib/asan/asan_report.cc
@@ -550,10 +550,7 @@ static void ReportSummary(const char *error_type, StackTrace *stack) {
// Maybe sometimes we need to choose another frame (e.g. skip memcpy/etc).
uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
getSymbolizer()->SymbolizeCode(pc, &ai, 1);
- ReportErrorSummary(error_type,
- StripPathPrefix(ai.file,
- common_flags()->strip_path_prefix),
- ai.line, ai.function);
+ ReportErrorSummary(error_type, ai.file, ai.line, ai.function);
}
// FIXME: do we need to print anything at all if there is no symbolizer?
}
diff --git a/lib/asan/asan_stack.cc b/lib/asan/asan_stack.cc
index 06f48eae..ca75f630 100644
--- a/lib/asan/asan_stack.cc
+++ b/lib/asan/asan_stack.cc
@@ -25,8 +25,8 @@ static bool MaybeCallAsanSymbolize(const void *pc, char *out_buffer,
}
void PrintStack(StackTrace *stack) {
- stack->PrintStack(stack->trace, stack->size, common_flags()->symbolize,
- common_flags()->strip_path_prefix, MaybeCallAsanSymbolize);
+ StackTrace::PrintStack(stack->trace, stack->size, common_flags()->symbolize,
+ MaybeCallAsanSymbolize);
}
} // namespace __asan
diff --git a/lib/lsan/lsan_common.cc b/lib/lsan/lsan_common.cc
index 7fa06752..416828ab 100644
--- a/lib/lsan/lsan_common.cc
+++ b/lib/lsan/lsan_common.cc
@@ -283,8 +283,7 @@ static void PrintStackTraceById(u32 stack_trace_id) {
CHECK(stack_trace_id);
uptr size = 0;
const uptr *trace = StackDepotGet(stack_trace_id, &size);
- StackTrace::PrintStack(trace, size, common_flags()->symbolize,
- common_flags()->strip_path_prefix, 0);
+ StackTrace::PrintStack(trace, size, common_flags()->symbolize, 0);
}
// ForEachChunk callback. Aggregates unreachable chunks into a LeakReport.
diff --git a/lib/msan/msan_report.cc b/lib/msan/msan_report.cc
index 00890347..997959ef 100644
--- a/lib/msan/msan_report.cc
+++ b/lib/msan/msan_report.cc
@@ -36,8 +36,7 @@ class Decorator: private __sanitizer::AnsiColorDecorator {
static void PrintStack(const uptr *trace, uptr size) {
SymbolizerScope sym_scope;
- StackTrace::PrintStack(trace, size, true,
- common_flags()->strip_path_prefix, 0);
+ StackTrace::PrintStack(trace, size, true, 0);
}
static void DescribeOrigin(u32 origin) {
@@ -80,10 +79,7 @@ static void ReportSummary(const char *error_type, StackTrace *stack) {
SymbolizerScope sym_scope;
getSymbolizer()->SymbolizeCode(pc, &ai, 1);
}
- ReportErrorSummary(error_type,
- StripPathPrefix(ai.file,
- common_flags()->strip_path_prefix),
- ai.line, ai.function);
+ ReportErrorSummary(error_type, ai.file, ai.line, ai.function);
}
void ReportUMR(StackTrace *stack, u32 origin) {
diff --git a/lib/sanitizer_common/sanitizer_common.cc b/lib/sanitizer_common/sanitizer_common.cc
index 97198ea2..4cf694aa 100644
--- a/lib/sanitizer_common/sanitizer_common.cc
+++ b/lib/sanitizer_common/sanitizer_common.cc
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "sanitizer_common.h"
+#include "sanitizer_flags.h"
#include "sanitizer_libc.h"
namespace __sanitizer {
@@ -136,13 +137,41 @@ void *MmapAlignedOrDie(uptr size, uptr alignment, const char *mem_type) {
return (void*)res;
}
+const char *StripPathPrefix(const char *filepath,
+ const char *strip_path_prefix) {
+ if (filepath == 0) return 0;
+ if (strip_path_prefix == 0) return filepath;
+ const char *pos = internal_strstr(filepath, strip_path_prefix);
+ if (pos == 0) return filepath;
+ pos += internal_strlen(strip_path_prefix);
+ if (pos[0] == '.' && pos[1] == '/')
+ pos += 2;
+ return pos;
+}
+
+void PrintSourceLocation(const char *file, int line, int column) {
+ CHECK(file);
+ Printf("%s", StripPathPrefix(file, common_flags()->strip_path_prefix));
+ if (line > 0) {
+ Printf(":%d", line);
+ if (column > 0)
+ Printf(":%d", column);
+ }
+}
+
+void PrintModuleAndOffset(const char *module, uptr offset) {
+ Printf("(%s+0x%zx)",
+ StripPathPrefix(module, common_flags()->strip_path_prefix), offset);
+}
+
void ReportErrorSummary(const char *error_type, const char *file,
int line, const char *function) {
const int kMaxSize = 1024; // We don't want a summary too long.
InternalScopedBuffer<char> buff(kMaxSize);
- internal_snprintf(buff.data(), kMaxSize, "%s: %s %s:%d %s",
- SanitizerToolName, error_type,
- file ? file : "??", line, function ? function : "??");
+ internal_snprintf(
+ buff.data(), kMaxSize, "%s: %s %s:%d %s", SanitizerToolName, error_type,
+ file ? StripPathPrefix(file, common_flags()->strip_path_prefix) : "??",
+ line, function ? function : "??");
__sanitizer_report_error_summary(buff.data());
}
diff --git a/lib/sanitizer_common/sanitizer_common.h b/lib/sanitizer_common/sanitizer_common.h
index 90f32191..e0f0d2f9 100644
--- a/lib/sanitizer_common/sanitizer_common.h
+++ b/lib/sanitizer_common/sanitizer_common.h
@@ -132,6 +132,13 @@ uptr ReadFileToBuffer(const char *file_name, char **buff,
// in '*buff_size'.
void *MapFileToMemory(const char *file_name, uptr *buff_size);
+// Error report formatting.
+const char *StripPathPrefix(const char *filepath,
+ const char *strip_file_prefix);
+void PrintSourceLocation(const char *file, int line, int column);
+void PrintModuleAndOffset(const char *module, uptr offset);
+
+
// OS
void DisableCoreDumper();
void DumpProcessMap();
diff --git a/lib/sanitizer_common/sanitizer_stacktrace.cc b/lib/sanitizer_common/sanitizer_stacktrace.cc
index 665627bc..e9ecfc9c 100644
--- a/lib/sanitizer_common/sanitizer_stacktrace.cc
+++ b/lib/sanitizer_common/sanitizer_stacktrace.cc
@@ -12,21 +12,13 @@
//===----------------------------------------------------------------------===//
#include "sanitizer_common.h"
+#include "sanitizer_flags.h"
#include "sanitizer_procmaps.h"
#include "sanitizer_stacktrace.h"
#include "sanitizer_symbolizer.h"
namespace __sanitizer {
-const char *StripPathPrefix(const char *filepath,
- const char *strip_file_prefix) {
- if (filepath == 0) return 0;
- const char *prefix_beg = internal_strstr(filepath, strip_file_prefix);
- if (prefix_beg)
- return prefix_beg + internal_strlen(strip_file_prefix);
- return filepath;
-}
-// ----------------------- StackTrace ----------------------------- {{{1
uptr StackTrace::GetPreviousInstructionPc(uptr pc) {
#ifdef __arm__
// Cancel Thumb bit.
@@ -46,25 +38,8 @@ static void PrintStackFramePrefix(uptr frame_num, uptr pc) {
Printf(" #%zu 0x%zx", frame_num, pc);
}
-static void PrintSourceLocation(const char *file, int line, int column,
- const char *strip_file_prefix) {
- CHECK(file);
- Printf(" %s", StripPathPrefix(file, strip_file_prefix));
- if (line > 0) {
- Printf(":%d", line);
- if (column > 0)
- Printf(":%d", column);
- }
-}
-
-static void PrintModuleAndOffset(const char *module, uptr offset,
- const char *strip_file_prefix) {
- Printf(" (%s+0x%zx)", StripPathPrefix(module, strip_file_prefix), offset);
-}
-
-void StackTrace::PrintStack(const uptr *addr, uptr size,
- bool symbolize, const char *strip_file_prefix,
- SymbolizeCallback symbolize_callback ) {
+void StackTrace::PrintStack(const uptr *addr, uptr size, bool symbolize,
+ SymbolizeCallback symbolize_callback) {
MemoryMappingLayout proc_maps(/*cache_enabled*/true);
InternalScopedBuffer<char> buff(GetPageSizeCached() * 2);
InternalScopedBuffer<AddressInfo> addr_frames(64);
@@ -82,7 +57,8 @@ void StackTrace::PrintStack(const uptr *addr, uptr size,
// We can't know anything about the string returned by external
// symbolizer, but if it starts with filename, try to strip path prefix
// from it.
- Printf(" %s\n", StripPathPrefix(buff.data(), strip_file_prefix));
+ Printf(" %s\n",
+ StripPathPrefix(buff.data(), common_flags()->strip_path_prefix));
frame_num++;
}
}
@@ -97,11 +73,11 @@ void StackTrace::PrintStack(const uptr *addr, uptr size,
Printf(" in %s", info.function);
}
if (info.file) {
- PrintSourceLocation(info.file, info.line, info.column,
- strip_file_prefix);
+ Printf(" ");
+ PrintSourceLocation(info.file, info.line, info.column);
} else if (info.module) {
- PrintModuleAndOffset(info.module, info.module_offset,
- strip_file_prefix);
+ Printf(" ");
+ PrintModuleAndOffset(info.module, info.module_offset);
}
Printf("\n");
info.Clear();
@@ -116,7 +92,8 @@ void StackTrace::PrintStack(const uptr *addr, uptr size,
if (proc_maps.GetObjectNameAndOffset(pc, &offset,
buff.data(), buff.size(),
/* protection */0)) {
- PrintModuleAndOffset(buff.data(), offset, strip_file_prefix);
+ Printf(" ");
+ PrintModuleAndOffset(buff.data(), offset);
}
Printf("\n");
frame_num++;
diff --git a/lib/sanitizer_common/sanitizer_stacktrace.h b/lib/sanitizer_common/sanitizer_stacktrace.h
index 187fb032..b2e0d6b5 100644
--- a/lib/sanitizer_common/sanitizer_stacktrace.h
+++ b/lib/sanitizer_common/sanitizer_stacktrace.h
@@ -34,8 +34,7 @@ struct StackTrace {
uptr size;
uptr max_size;
uptr trace[kStackTraceMax];
- static void PrintStack(const uptr *addr, uptr size,
- bool symbolize, const char *strip_file_prefix,
+ static void PrintStack(const uptr *addr, uptr size, bool symbolize,
SymbolizeCallback symbolize_callback);
void CopyTo(uptr *dst, uptr dst_size) {
for (uptr i = 0; i < size && i < dst_size; i++)
@@ -68,10 +67,6 @@ struct StackTrace {
u32 *compressed, uptr size);
};
-
-const char *StripPathPrefix(const char *filepath,
- const char *strip_file_prefix);
-
void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp,
uptr stack_top, uptr stack_bottom, bool fast);
diff --git a/lib/sanitizer_common/tests/sanitizer_common_test.cc b/lib/sanitizer_common/tests/sanitizer_common_test.cc
index 6c6e55c8..fd51e4fc 100644
--- a/lib/sanitizer_common/tests/sanitizer_common_test.cc
+++ b/lib/sanitizer_common/tests/sanitizer_common_test.cc
@@ -183,4 +183,13 @@ TEST(SanitizerCommon, FindPathToBinary) {
}
#endif
+TEST(SanitizerCommon, StripPathPrefix) {
+ EXPECT_EQ(0, StripPathPrefix(0, "prefix"));
+ EXPECT_STREQ("foo", StripPathPrefix("foo", 0));
+ EXPECT_STREQ("dir/file.cc",
+ StripPathPrefix("/usr/lib/dir/file.cc", "/usr/lib/"));
+ EXPECT_STREQ("/file.cc", StripPathPrefix("/usr/myroot/file.cc", "/myroot"));
+ EXPECT_STREQ("file.h", StripPathPrefix("/usr/lib/./file.h", "/usr/lib/"));
+}
+
} // namespace __sanitizer
diff --git a/lib/tsan/rtl/tsan_flags.cc b/lib/tsan/rtl/tsan_flags.cc
index acf787d5..b864f929 100644
--- a/lib/tsan/rtl/tsan_flags.cc
+++ b/lib/tsan/rtl/tsan_flags.cc
@@ -119,6 +119,7 @@ void InitializeFlags(Flags *f, const char *env) {
}
common_flags()->allocator_may_return_null = f->allocator_may_return_null;
+ common_flags()->strip_path_prefix = f->strip_path_prefix;
}
} // namespace __tsan
diff --git a/lib/ubsan/lit_tests/TypeCheck/misaligned.cpp b/lib/ubsan/lit_tests/TypeCheck/misaligned.cpp
index 3abacae8..e5254982 100644
--- a/lib/ubsan/lit_tests/TypeCheck/misaligned.cpp
+++ b/lib/ubsan/lit_tests/TypeCheck/misaligned.cpp
@@ -64,7 +64,7 @@ int main(int, char **argv) {
case 'n':
// FIXME: Provide a better source location here.
- // CHECK-NEW: misaligned{{.*}}:0x{{[0-9a-f]*}}: runtime error: constructor call on misaligned address [[PTR:0x[0-9a-f]*]] for type 'S', which requires 4 byte alignment
+ // CHECK-NEW: misaligned{{.*}}+0x{{[0-9a-f]*}}): runtime error: constructor call on misaligned address [[PTR:0x[0-9a-f]*]] for type 'S', which requires 4 byte alignment
// CHECK-NEW-NEXT: [[PTR]]: note: pointer points here
// CHECK-NEW-NEXT: {{^ 00 00 00 01 02 03 04 05}}
// CHECK-NEW-NEXT: {{^ \^}}
diff --git a/lib/ubsan/ubsan_diag.cc b/lib/ubsan/ubsan_diag.cc
index 65df48c8..e4ca4e4a 100644
--- a/lib/ubsan/ubsan_diag.cc
+++ b/lib/ubsan/ubsan_diag.cc
@@ -72,25 +72,23 @@ static void renderLocation(Location Loc) {
case Location::LK_Source: {
SourceLocation SLoc = Loc.getSourceLocation();
if (SLoc.isInvalid())
- Printf("<unknown>:");
- else {
- Printf("%s:%d:", SLoc.getFilename(), SLoc.getLine());
- if (SLoc.getColumn())
- Printf("%d:", SLoc.getColumn());
- }
+ Printf("<unknown>");
+ else
+ PrintSourceLocation(SLoc.getFilename(), SLoc.getLine(), SLoc.getColumn());
break;
}
case Location::LK_Module:
- Printf("%s:0x%zx:", Loc.getModuleLocation().getModuleName(),
- Loc.getModuleLocation().getOffset());
+ PrintModuleAndOffset(Loc.getModuleLocation().getModuleName(),
+ Loc.getModuleLocation().getOffset());
break;
case Location::LK_Memory:
- Printf("%p:", Loc.getMemoryLocation());
+ Printf("%p", Loc.getMemoryLocation());
break;
case Location::LK_Null:
- Printf("<unknown>:");
+ Printf("<unknown>");
break;
}
+ Printf(":");
}
static void renderText(const char *Message, const Diag::Arg *Args) {