summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib
diff options
context:
space:
mode:
authorFilipe Cabecinhas <me@filcab.net>2015-06-04 01:20:06 +0000
committerFilipe Cabecinhas <me@filcab.net>2015-06-04 01:20:06 +0000
commit215046bf98ef1dc7a380c35da5ca44166e74ae0b (patch)
treec222c0b97790cc15a9830c2625bf4614a7efb614 /compiler-rt/lib
parent1ba52feb9673f805c5b74cf185e5384f23032522 (diff)
downloadbcm5719-llvm-215046bf98ef1dc7a380c35da5ca44166e74ae0b.tar.gz
bcm5719-llvm-215046bf98ef1dc7a380c35da5ca44166e74ae0b.zip
[sanitizer_common] Added VS-style output for source locations
Summary: With this patch, we have a flag to toggle displaying source locations in the regular style: file:line:column or Visual Studio style: file(line,column) This way, they get picked up on the Visual Studio output window and one can double-click them to get to that file location. Reviewers: samsonov, rnk Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D10113 llvm-svn: 239000
Diffstat (limited to 'compiler-rt/lib')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common.cc3
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_flags.inc3
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc3
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cc23
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.h6
-rw-r--r--compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cc58
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_report.cc1
-rw-r--r--compiler-rt/lib/ubsan/ubsan_diag.cc4
8 files changed, 75 insertions, 26 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc
index 8185c81c254..15eae9d6ebd 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc
@@ -243,7 +243,8 @@ void ReportErrorSummary(const char *error_type, const AddressInfo &info) {
return;
InternalScopedString buff(kMaxSummaryLength);
buff.append("%s ", error_type);
- RenderFrame(&buff, "%L %F", 0, info, common_flags()->strip_path_prefix);
+ RenderFrame(&buff, "%L %F", 0, info, common_flags()->symbolize_vs_style,
+ common_flags()->strip_path_prefix);
ReportErrorSummary(buff.data());
}
#endif
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
index 38de5d7f70c..da908aa3df3 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
@@ -146,6 +146,9 @@ COMMON_FLAG(bool, use_madv_dontdump, true,
"in core file.")
COMMON_FLAG(bool, symbolize_inline_frames, true,
"Print inlined frames in stacktraces. Defaults to true.")
+COMMON_FLAG(bool, symbolize_vs_style, false,
+ "Print file locations in Visual Studio style (e.g: "
+ " file(10,42): ...")
COMMON_FLAG(const char *, stack_trace_format, "DEFAULT",
"Format string used to render stack frames. "
"See sanitizer_stacktrace_printer.h for the format description. "
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc
index 0f98c7d5af4..b55d4dde083 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc
@@ -35,7 +35,8 @@ void StackTrace::Print() const {
for (SymbolizedStack *cur = frames; cur; cur = cur->next) {
frame_desc.clear();
RenderFrame(&frame_desc, common_flags()->stack_trace_format, frame_num++,
- cur->info, common_flags()->strip_path_prefix);
+ cur->info, common_flags()->symbolize_vs_style,
+ common_flags()->strip_path_prefix);
Printf("%s\n", frame_desc.data());
}
frames->ClearAll();
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cc b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cc
index 7b37dbcf386..d56e47e0727 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cc
@@ -26,8 +26,8 @@ static const char *StripFunctionName(const char *function, const char *prefix) {
static const char kDefaultFormat[] = " #%n %p %F %L";
void RenderFrame(InternalScopedString *buffer, const char *format, int frame_no,
- const AddressInfo &info, const char *strip_path_prefix,
- const char *strip_func_prefix) {
+ const AddressInfo &info, bool vs_style,
+ const char *strip_path_prefix, const char *strip_func_prefix) {
if (0 == internal_strcmp(format, "DEFAULT"))
format = kDefaultFormat;
for (const char *p = format; *p != '\0'; p++) {
@@ -82,14 +82,14 @@ void RenderFrame(InternalScopedString *buffer, const char *format, int frame_no,
break;
case 'S':
// File/line information.
- RenderSourceLocation(buffer, info.file, info.line, info.column,
+ RenderSourceLocation(buffer, info.file, info.line, info.column, vs_style,
strip_path_prefix);
break;
case 'L':
// Source location, or module location.
if (info.file) {
RenderSourceLocation(buffer, info.file, info.line, info.column,
- strip_path_prefix);
+ vs_style, strip_path_prefix);
} else if (info.module) {
RenderModuleLocation(buffer, info.module, info.module_offset,
strip_path_prefix);
@@ -106,15 +106,24 @@ void RenderFrame(InternalScopedString *buffer, const char *format, int frame_no,
buffer->append("(%p)", (void *)info.address);
break;
default:
- Report("Unsupported specifier in stack frame format: %c (0x%zx)!\n",
- *p, *p);
+ Report("Unsupported specifier in stack frame format: %c (0x%zx)!\n", *p,
+ *p);
Die();
}
}
}
void RenderSourceLocation(InternalScopedString *buffer, const char *file,
- int line, int column, const char *strip_path_prefix) {
+ int line, int column, bool vs_style,
+ const char *strip_path_prefix) {
+ if (vs_style && line > 0) {
+ buffer->append("%s(%d", StripPathPrefix(file, strip_path_prefix), line);
+ if (column > 0)
+ buffer->append(",%d", column);
+ buffer->append(")");
+ return;
+ }
+
buffer->append("%s", StripPathPrefix(file, strip_path_prefix));
if (line > 0) {
buffer->append(":%d", line);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.h b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.h
index 93569882ba9..7f6c5c73b85 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.h
@@ -48,11 +48,13 @@ namespace __sanitizer {
// module+offset if it is known, or (<unknown module>) string.
// %M - prints module basename and offset, if it is known, or PC.
void RenderFrame(InternalScopedString *buffer, const char *format, int frame_no,
- const AddressInfo &info, const char *strip_path_prefix = "",
+ const AddressInfo &info, bool vs_style,
+ const char *strip_path_prefix = "",
const char *strip_func_prefix = "");
void RenderSourceLocation(InternalScopedString *buffer, const char *file,
- int line, int column, const char *strip_path_prefix);
+ int line, int column, bool vs_style,
+ const char *strip_path_prefix);
void RenderModuleLocation(InternalScopedString *buffer, const char *module,
uptr offset, const char *strip_path_prefix);
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cc
index cc9a9edbbb4..05796fcbff7 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cc
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cc
@@ -18,20 +18,36 @@ namespace __sanitizer {
TEST(SanitizerStacktracePrinter, RenderSourceLocation) {
InternalScopedString str(128);
- RenderSourceLocation(&str, "/dir/file.cc", 10, 5, "");
+ RenderSourceLocation(&str, "/dir/file.cc", 10, 5, false, "");
EXPECT_STREQ("/dir/file.cc:10:5", str.data());
str.clear();
- RenderSourceLocation(&str, "/dir/file.cc", 11, 0, "");
+ RenderSourceLocation(&str, "/dir/file.cc", 11, 0, false, "");
EXPECT_STREQ("/dir/file.cc:11", str.data());
str.clear();
- RenderSourceLocation(&str, "/dir/file.cc", 0, 0, "");
+ RenderSourceLocation(&str, "/dir/file.cc", 0, 0, false, "");
EXPECT_STREQ("/dir/file.cc", str.data());
str.clear();
- RenderSourceLocation(&str, "/dir/file.cc", 10, 5, "/dir/");
+ RenderSourceLocation(&str, "/dir/file.cc", 10, 5, false, "/dir/");
EXPECT_STREQ("file.cc:10:5", str.data());
+
+ str.clear();
+ RenderSourceLocation(&str, "/dir/file.cc", 10, 5, true, "");
+ EXPECT_STREQ("/dir/file.cc(10,5)", str.data());
+
+ str.clear();
+ RenderSourceLocation(&str, "/dir/file.cc", 11, 0, true, "");
+ EXPECT_STREQ("/dir/file.cc(11)", str.data());
+
+ str.clear();
+ RenderSourceLocation(&str, "/dir/file.cc", 0, 0, true, "");
+ EXPECT_STREQ("/dir/file.cc", str.data());
+
+ str.clear();
+ RenderSourceLocation(&str, "/dir/file.cc", 10, 5, true, "/dir/");
+ EXPECT_STREQ("file.cc(10,5)", str.data());
}
TEST(SanitizerStacktracePrinter, RenderModuleLocation) {
@@ -62,7 +78,7 @@ TEST(SanitizerStacktracePrinter, RenderFrame) {
RenderFrame(&str, "%% Frame:%n PC:%p Module:%m ModuleOffset:%o "
"Function:%f FunctionOffset:%q Source:%s Line:%l "
"Column:%c",
- frame_no, info, "/path/to/", "function_");
+ frame_no, info, false, "/path/to/", "function_");
EXPECT_STREQ("% Frame:42 PC:0x400000 Module:my/module ModuleOffset:0x200 "
"Function:foo FunctionOffset:0x100 Source:my/source Line:10 "
"Column:5",
@@ -72,50 +88,64 @@ TEST(SanitizerStacktracePrinter, RenderFrame) {
// Test special format specifiers.
info.address = 0x400000;
- RenderFrame(&str, "%M", frame_no, info);
+ RenderFrame(&str, "%M", frame_no, info, false);
EXPECT_NE(nullptr, internal_strstr(str.data(), "400000"));
str.clear();
- RenderFrame(&str, "%L", frame_no, info);
+ RenderFrame(&str, "%L", frame_no, info, false);
EXPECT_STREQ("(<unknown module>)", str.data());
str.clear();
info.module = internal_strdup("/path/to/module");
info.module_offset = 0x200;
- RenderFrame(&str, "%M", frame_no, info);
+ RenderFrame(&str, "%M", frame_no, info, false);
EXPECT_NE(nullptr, internal_strstr(str.data(), "(module+0x"));
EXPECT_NE(nullptr, internal_strstr(str.data(), "200"));
str.clear();
- RenderFrame(&str, "%L", frame_no, info);
+ RenderFrame(&str, "%L", frame_no, info, false);
EXPECT_STREQ("(/path/to/module+0x200)", str.data());
str.clear();
info.function = internal_strdup("my_function");
- RenderFrame(&str, "%F", frame_no, info);
+ RenderFrame(&str, "%F", frame_no, info, false);
EXPECT_STREQ("in my_function", str.data());
str.clear();
info.function_offset = 0x100;
- RenderFrame(&str, "%F %S", frame_no, info);
+ RenderFrame(&str, "%F %S", frame_no, info, false);
EXPECT_STREQ("in my_function+0x100 <null>", str.data());
str.clear();
info.file = internal_strdup("my_file");
- RenderFrame(&str, "%F %S", frame_no, info);
+ RenderFrame(&str, "%F %S", frame_no, info, false);
EXPECT_STREQ("in my_function my_file", str.data());
str.clear();
info.line = 10;
- RenderFrame(&str, "%F %S", frame_no, info);
+ RenderFrame(&str, "%F %S", frame_no, info, false);
EXPECT_STREQ("in my_function my_file:10", str.data());
str.clear();
info.column = 5;
- RenderFrame(&str, "%S %L", frame_no, info);
+ RenderFrame(&str, "%S %L", frame_no, info, false);
EXPECT_STREQ("my_file:10:5 my_file:10:5", str.data());
str.clear();
+ RenderFrame(&str, "%S %L", frame_no, info, true);
+ EXPECT_STREQ("my_file(10,5) my_file(10,5)", str.data());
+ str.clear();
+
+ info.column = 0;
+ RenderFrame(&str, "%F %S", frame_no, info, true);
+ EXPECT_STREQ("in my_function my_file(10)", str.data());
+ str.clear();
+
+ info.line = 0;
+ RenderFrame(&str, "%F %S", frame_no, info, true);
+ EXPECT_STREQ("in my_function my_file", str.data());
+ str.clear();
+
info.Clear();
}
diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.cc b/compiler-rt/lib/tsan/rtl/tsan_report.cc
index 18bad146b69..f4b06878a58 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_report.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_report.cc
@@ -120,6 +120,7 @@ void PrintStack(const ReportStack *ent) {
for (int i = 0; frame && frame->info.address; frame = frame->next, i++) {
InternalScopedString res(2 * GetPageSizeCached());
RenderFrame(&res, common_flags()->stack_trace_format, i, frame->info,
+ common_flags()->symbolize_vs_style,
common_flags()->strip_path_prefix, "__interceptor_");
Printf("%s\n", res.data());
}
diff --git a/compiler-rt/lib/ubsan/ubsan_diag.cc b/compiler-rt/lib/ubsan/ubsan_diag.cc
index cdcc0e4a791..a4c9e304671 100644
--- a/compiler-rt/lib/ubsan/ubsan_diag.cc
+++ b/compiler-rt/lib/ubsan/ubsan_diag.cc
@@ -121,7 +121,8 @@ static void renderLocation(Location Loc) {
LocBuffer.append("<unknown>");
else
RenderSourceLocation(&LocBuffer, SLoc.getFilename(), SLoc.getLine(),
- SLoc.getColumn(), common_flags()->strip_path_prefix);
+ SLoc.getColumn(), common_flags()->symbolize_vs_style,
+ common_flags()->strip_path_prefix);
break;
}
case Location::LK_Memory:
@@ -131,6 +132,7 @@ static void renderLocation(Location Loc) {
const AddressInfo &Info = Loc.getSymbolizedStack()->info;
if (Info.file) {
RenderSourceLocation(&LocBuffer, Info.file, Info.line, Info.column,
+ common_flags()->symbolize_vs_style,
common_flags()->strip_path_prefix);
} else if (Info.module) {
RenderModuleLocation(&LocBuffer, Info.module, Info.module_offset,
OpenPOWER on IntegriCloud