[compiler-rt] r279780 - [sanitizer] add __sanitizer_symbolize_pc. https://github.com/google/sanitizers/issues/322
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 25 14:35:29 PDT 2016
Author: kcc
Date: Thu Aug 25 16:35:29 2016
New Revision: 279780
URL: http://llvm.org/viewvc/llvm-project?rev=279780&view=rev
Log:
[sanitizer] add __sanitizer_symbolize_pc. https://github.com/google/sanitizers/issues/322
Added:
compiler-rt/trunk/test/sanitizer_common/TestCases/symbolize_pc.cc
Modified:
compiler-rt/trunk/include/sanitizer/common_interface_defs.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc
Modified: compiler-rt/trunk/include/sanitizer/common_interface_defs.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/common_interface_defs.h?rev=279780&r1=279779&r2=279780&view=diff
==============================================================================
--- compiler-rt/trunk/include/sanitizer/common_interface_defs.h (original)
+++ compiler-rt/trunk/include/sanitizer/common_interface_defs.h Thu Aug 25 16:35:29 2016
@@ -117,6 +117,13 @@ extern "C" {
// Print the stack trace leading to this call. Useful for debugging user code.
void __sanitizer_print_stack_trace();
+ // Symbolizes the supplied 'pc' using the format string 'fmt'.
+ // Outputs at most 'out_buf_size' bytes into 'out_buf'.
+ // The format syntax is described in
+ // lib/sanitizer_common/sanitizer_stacktrace_printer.h.
+ void __sanitizer_symbolize_pc(void *pc, const char *fmt, char *out_buf,
+ size_t out_buf_size);
+
// Sets the callback to be called right before death on error.
// Passing 0 will unset the callback.
void __sanitizer_set_death_callback(void (*callback)(void));
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc?rev=279780&r1=279779&r2=279780&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc Thu Aug 25 16:35:29 2016
@@ -83,3 +83,22 @@ void BufferedStackTrace::Unwind(u32 max_
}
} // namespace __sanitizer
+
+extern "C" {
+SANITIZER_INTERFACE_ATTRIBUTE
+void __sanitizer_symbolize_pc(uptr pc, const char *fmt, char *out_buf,
+ uptr out_buf_size) {
+ using namespace __sanitizer;
+ pc = StackTrace::GetPreviousInstructionPc(pc);
+ SymbolizedStack *frame = Symbolizer::GetOrInit()->SymbolizePC(pc);
+ if (!frame) {
+ internal_strncpy(out_buf, "<can't symbolize>", out_buf_size);
+ return;
+ }
+ InternalScopedString frame_desc(GetPageSizeCached());
+ RenderFrame(&frame_desc, fmt, 0, frame->info,
+ common_flags()->symbolize_vs_style,
+ common_flags()->strip_path_prefix);
+ internal_strncpy(out_buf, frame_desc.data(), out_buf_size);
+}
+} // extern "C"
Added: compiler-rt/trunk/test/sanitizer_common/TestCases/symbolize_pc.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/symbolize_pc.cc?rev=279780&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/symbolize_pc.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/symbolize_pc.cc Thu Aug 25 16:35:29 2016
@@ -0,0 +1,21 @@
+// RUN: %clangxx -O0 %s -o %t
+// RUN: %env_tool_opts=strip_path_prefix=/TestCases/ %run %t 2>&1 | FileCheck %s
+//
+// Tests __sanitizer_symbolize_pc.
+#include <stdio.h>
+#include <sanitizer/common_interface_defs.h>
+void SymbolizeCaller() {
+ char data[1000];
+ __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", data,
+ sizeof(data));
+ printf("FIRST_FORMAT %s\n", data);
+ __sanitizer_symbolize_pc(__builtin_return_address(0),
+ "FUNC:%f LINE:%l FILE:%s", data, sizeof(data));
+ printf("SECOND_FORMAT %s\n", data);
+}
+
+// CHECK: FIRST_FORMAT 0x{{.*}} in main symbolize_pc.cc:[[@LINE+3]]
+// CHECK: SECOND_FORMAT FUNC:main LINE:[[@LINE+2]] FILE:symbolize_pc.cc
+int main() {
+ SymbolizeCaller();
+}
More information about the llvm-commits
mailing list