summaryrefslogtreecommitdiffstats
path: root/compiler-rt
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2012-08-06 13:00:21 +0000
committerAlexey Samsonov <samsonov@google.com>2012-08-06 13:00:21 +0000
commit0295edbfd556a78c6adb61d31202ebc20f60302b (patch)
treea757d51d72c0ced6128a2b2a50a02f96e73bc56f /compiler-rt
parent8f6dd3537cd42d60f70465ac13ae6841f0af2ac2 (diff)
downloadbcm5719-llvm-0295edbfd556a78c6adb61d31202ebc20f60302b.tar.gz
bcm5719-llvm-0295edbfd556a78c6adb61d31202ebc20f60302b.zip
[ASan] add new ASan option 'strip_path_prefix' to remove useless prefices from filenames in stack traces
llvm-svn: 161321
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/lib/asan/asan_flags.h2
-rw-r--r--compiler-rt/lib/asan/asan_rtl.cc4
-rw-r--r--compiler-rt/lib/asan/asan_stack.cc22
-rwxr-xr-xcompiler-rt/lib/asan/output_tests/test_output.sh7
-rw-r--r--compiler-rt/lib/asan/output_tests/use-after-free.c1
5 files changed, 30 insertions, 6 deletions
diff --git a/compiler-rt/lib/asan/asan_flags.h b/compiler-rt/lib/asan/asan_flags.h
index ca9cf84ba6c..5c18a318174 100644
--- a/compiler-rt/lib/asan/asan_flags.h
+++ b/compiler-rt/lib/asan/asan_flags.h
@@ -87,6 +87,8 @@ struct Flags {
// By default, disable core dumper on 64-bit - it makes little sense
// to dump 16T+ core.
bool disable_core;
+ // Strips this prefix from file paths in error reports.
+ const char *strip_path_prefix;
};
Flags *flags();
diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc
index 34324fa16d0..ad51e01e450 100644
--- a/compiler-rt/lib/asan/asan_rtl.cc
+++ b/compiler-rt/lib/asan/asan_rtl.cc
@@ -35,7 +35,7 @@ void Die() {
while (1) { }
}
if (flags()->sleep_before_dying) {
- Report("Sleeping for %zd second(s)\n", flags()->sleep_before_dying);
+ Report("Sleeping for %d second(s)\n", flags()->sleep_before_dying);
SleepForSeconds(flags()->sleep_before_dying);
}
if (flags()->unmap_shadow_on_exit)
@@ -96,6 +96,7 @@ static void ParseFlagsFromString(Flags *f, const char *str) {
ParseFlag(str, &f->abort_on_error, "abort_on_error");
ParseFlag(str, &f->atexit, "atexit");
ParseFlag(str, &f->disable_core, "disable_core");
+ ParseFlag(str, &f->strip_path_prefix, "strip_path_prefix");
}
extern "C" {
@@ -128,6 +129,7 @@ void InitializeFlags(Flags *f, const char *env) {
f->abort_on_error = false;
f->atexit = false;
f->disable_core = (__WORDSIZE == 64);
+ f->strip_path_prefix = "";
// Override from user-specified string.
ParseFlagsFromString(f, __asan_default_options());
diff --git a/compiler-rt/lib/asan/asan_stack.cc b/compiler-rt/lib/asan/asan_stack.cc
index d6103c2c98f..703cc692bc1 100644
--- a/compiler-rt/lib/asan/asan_stack.cc
+++ b/compiler-rt/lib/asan/asan_stack.cc
@@ -26,6 +26,13 @@ ASAN_USE_EXTERNAL_SYMBOLIZER(const void *pc, char *out, int out_size);
namespace __asan {
+static const char *StripPathPrefix(const char *filepath) {
+ const char *path_prefix = flags()->strip_path_prefix;
+ if (filepath == internal_strstr(filepath, path_prefix))
+ return filepath + internal_strlen(path_prefix);
+ return filepath;
+}
+
// ----------------------- AsanStackTrace ----------------------------- {{{1
// PCs in stack traces are actually the return addresses, that is,
// addresses of the next instructions after the call. That's why we
@@ -46,7 +53,10 @@ void AsanStackTrace::PrintStack(uptr *addr, uptr size) {
pc = patch_pc(pc);
char buff[4096];
ASAN_USE_EXTERNAL_SYMBOLIZER((void*)pc, buff, sizeof(buff));
- AsanPrintf(" #%zu 0x%zx %s\n", i, pc, buff);
+ // 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.
+ AsanPrintf(" #%zu 0x%zx %s\n", i, pc, StripPathPrefix(buff));
}
}
@@ -72,9 +82,11 @@ void AsanStackTrace::PrintStack(uptr *addr, uptr size) {
AsanPrintf(" in %s", info.function);
}
if (info.file) {
- AsanPrintf(" %s:%d:%d", info.file, info.line, info.column);
+ AsanPrintf(" %s:%d:%d", StripPathPrefix(info.file), info.line,
+ info.column);
} else if (info.module) {
- AsanPrintf(" (%s+0x%zx)", info.module, info.module_offset);
+ AsanPrintf(" (%s+0x%zx)", StripPathPrefix(info.module),
+ info.module_offset);
}
AsanPrintf("\n");
info.Clear();
@@ -85,8 +97,8 @@ void AsanStackTrace::PrintStack(uptr *addr, uptr size) {
char filename[4096];
if (proc_maps.GetObjectNameAndOffset(pc, &offset,
filename, sizeof(filename))) {
- AsanPrintf(" #%zu 0x%zx (%s+0x%zx)\n", frame_num, pc, filename,
- offset);
+ AsanPrintf(" #%zu 0x%zx (%s+0x%zx)\n",
+ frame_num, pc, StripPathPrefix(filename), offset);
} else {
AsanPrintf(" #%zu 0x%zx\n", frame_num, pc);
}
diff --git a/compiler-rt/lib/asan/output_tests/test_output.sh b/compiler-rt/lib/asan/output_tests/test_output.sh
index 6510043396e..8dc93eb1e24 100755
--- a/compiler-rt/lib/asan/output_tests/test_output.sh
+++ b/compiler-rt/lib/asan/output_tests/test_output.sh
@@ -39,6 +39,13 @@ check_program a.out $C_TEST.c CHECKSLEEP
export ASAN_OPTIONS=""
rm ./a.out
+echo "Checking strip_path_prefix option"
+$CC -g -faddress-sanitizer -O2 $C_TEST.c
+export ASAN_OPTIONS="strip_path_prefix='/'"
+./a.out 2>&1 | $FILE_CHECK $C_TEST.c --check-prefix=CHECKSTRIP
+export ASAN_OPTIONS=""
+rm ./a.out
+
# FIXME: some tests do not need to be ran for all the combinations of arch
# and optimization mode.
for t in *.cc; do
diff --git a/compiler-rt/lib/asan/output_tests/use-after-free.c b/compiler-rt/lib/asan/output_tests/use-after-free.c
index 801d3f68a46..4ee541a1c7a 100644
--- a/compiler-rt/lib/asan/output_tests/use-after-free.c
+++ b/compiler-rt/lib/asan/output_tests/use-after-free.c
@@ -7,3 +7,4 @@ int main() {
// CHECK: heap-use-after-free
// CHECKSLEEP: Sleeping for 1 second
+// CHECKSTRIP-NOT: #0 0x{{.*}} ({{[/].*}})
OpenPOWER on IntegriCloud