[compiler-rt] r191943 - Refactor the usage of strip_path_prefix option and make it more consistent across sanitizers
Alexey Samsonov
samsonov at google.com
Fri Oct 4 01:55:04 PDT 2013
Author: samsonov
Date: Fri Oct 4 03:55:03 2013
New Revision: 191943
URL: http://llvm.org/viewvc/llvm-project?rev=191943&view=rev
Log:
Refactor the usage of strip_path_prefix option and make it more consistent across sanitizers
Modified:
compiler-rt/trunk/lib/asan/asan_report.cc
compiler-rt/trunk/lib/asan/asan_stack.cc
compiler-rt/trunk/lib/lsan/lsan_common.cc
compiler-rt/trunk/lib/msan/msan_report.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
compiler-rt/trunk/lib/ubsan/lit_tests/TypeCheck/misaligned.cpp
compiler-rt/trunk/lib/ubsan/ubsan_diag.cc
Modified: compiler-rt/trunk/lib/asan/asan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.cc?rev=191943&r1=191942&r2=191943&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_report.cc Fri Oct 4 03:55:03 2013
@@ -550,10 +550,7 @@ static void ReportSummary(const char *er
// 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?
}
Modified: compiler-rt/trunk/lib/asan/asan_stack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stack.cc?rev=191943&r1=191942&r2=191943&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_stack.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_stack.cc Fri Oct 4 03:55:03 2013
@@ -25,8 +25,8 @@ static bool MaybeCallAsanSymbolize(const
}
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
Modified: compiler-rt/trunk/lib/lsan/lsan_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.cc?rev=191943&r1=191942&r2=191943&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.cc Fri Oct 4 03:55:03 2013
@@ -283,8 +283,7 @@ static void PrintStackTraceById(u32 stac
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.
Modified: compiler-rt/trunk/lib/msan/msan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_report.cc?rev=191943&r1=191942&r2=191943&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_report.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_report.cc Fri Oct 4 03:55:03 2013
@@ -36,8 +36,7 @@ class Decorator: private __sanitizer::An
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 *er
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) {
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=191943&r1=191942&r2=191943&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Fri Oct 4 03:55:03 2013
@@ -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 a
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());
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=191943&r1=191942&r2=191943&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Fri Oct 4 03:55:03 2013
@@ -132,6 +132,13 @@ uptr ReadFileToBuffer(const char *file_n
// 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();
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc?rev=191943&r1=191942&r2=191943&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc Fri Oct 4 03:55:03 2013
@@ -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 f
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 *
// 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 *
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 *
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++;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h?rev=191943&r1=191942&r2=191943&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h Fri Oct 4 03:55:03 2013
@@ -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);
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc?rev=191943&r1=191942&r2=191943&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc Fri Oct 4 03:55:03 2013
@@ -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
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc?rev=191943&r1=191942&r2=191943&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc Fri Oct 4 03:55:03 2013
@@ -119,6 +119,7 @@ void InitializeFlags(Flags *f, const cha
}
common_flags()->allocator_may_return_null = f->allocator_may_return_null;
+ common_flags()->strip_path_prefix = f->strip_path_prefix;
}
} // namespace __tsan
Modified: compiler-rt/trunk/lib/ubsan/lit_tests/TypeCheck/misaligned.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/lit_tests/TypeCheck/misaligned.cpp?rev=191943&r1=191942&r2=191943&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/lit_tests/TypeCheck/misaligned.cpp (original)
+++ compiler-rt/trunk/lib/ubsan/lit_tests/TypeCheck/misaligned.cpp Fri Oct 4 03:55:03 2013
@@ -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: {{^ \^}}
Modified: compiler-rt/trunk/lib/ubsan/ubsan_diag.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag.cc?rev=191943&r1=191942&r2=191943&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_diag.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_diag.cc Fri Oct 4 03:55:03 2013
@@ -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) {
More information about the llvm-commits
mailing list