summaryrefslogtreecommitdiff
path: root/libsanitizer/sanitizer_common
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2014-01-09 18:16:40 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2014-01-09 18:16:40 +0000
commit9071f223bea07fd5b5cec3b5ad48cad8c25bf9db (patch)
tree4891e38742b6dbf0a0be3981a9ba4dcb067d7930 /libsanitizer/sanitizer_common
parentda09c45097c5aa5270015eb6eac1355a102bd75f (diff)
downloadgcc-9071f223bea07fd5b5cec3b5ad48cad8c25bf9db.tar.gz
* sanitizer_common/sanitizer_symbolizer_libbacktrace.h
(LibbacktraceSymbolizer::Demangle): New declaration. * sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc (POSIXSymbolizer::Demangle): Use libbacktrace_symbolizer_'s Demangle method if possible. * sanitizer_common/sanitizer_symbolizer_libbacktrace.cc: Include "demangle.h" if SANITIZE_CP_DEMANGLE is defined. (struct CplusV3DemangleData): New type. (CplusV3DemangleCallback, CplusV3Demangle): New functions. (SymbolizeCodePCInfoCallback, SymbolizeCodeCallback, SymbolizeDataCallback): Use CplusV3Demangle. * sanitizer_common/Makefile.am (AM_CXXFLAGS): Add -DSANITIZE_CP_DEMANGLE and -I $(top_srcdir)/../include. * libbacktrace/backtrace-rename.h (cplus_demangle_builtin_types, cplus_demangle_fill_ctor, cplus_demangle_fill_dtor, cplus_demangle_fill_extended_operator, cplus_demangle_fill_name, cplus_demangle_init_info, cplus_demangle_mangled_name, cplus_demangle_operators, cplus_demangle_print, cplus_demangle_print_callback, cplus_demangle_type, cplus_demangle_v3, cplus_demangle_v3_callback, is_gnu_v3_mangled_ctor, is_gnu_v3_mangled_dtor, java_demangle_v3, java_demangle_v3_callback): Define. (__asan_internal_memcmp, __asan_internal_strncmp): New prototypes. (memcmp, strncmp): Redefine. * libbacktrace/Makefile.am (libsanitizer_libbacktrace_la_SOURCES): Add ../../libiberty/cp-demangle.c. * libbacktrace/bridge.cc (__asan_internal_memcmp, __asan_internal_strncmp): New functions. * sanitizer_common/Makefile.in: Regenerated. * libbacktrace/Makefile.in: Regenerated. * configure: Regenerated. * configure.ac: Regenerated. * config.h.in: Regenerated. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@206477 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libsanitizer/sanitizer_common')
-rw-r--r--libsanitizer/sanitizer_common/Makefile.am4
-rw-r--r--libsanitizer/sanitizer_common/Makefile.in4
-rw-r--r--libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc79
-rw-r--r--libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.h2
-rw-r--r--libsanitizer/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc5
5 files changed, 89 insertions, 5 deletions
diff --git a/libsanitizer/sanitizer_common/Makefile.am b/libsanitizer/sanitizer_common/Makefile.am
index 11af196196c..8e9038dc8cf 100644
--- a/libsanitizer/sanitizer_common/Makefile.am
+++ b/libsanitizer/sanitizer_common/Makefile.am
@@ -7,8 +7,10 @@ DEFS = -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D
AM_CXXFLAGS = -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -fPIC -fno-builtin -fno-exceptions -fno-rtti -fomit-frame-pointer -funwind-tables -fvisibility=hidden -Wno-variadic-macros
AM_CXXFLAGS += $(LIBSTDCXX_RAW_CXX_CXXFLAGS)
if LIBBACKTRACE_SUPPORTED
-AM_CXXFLAGS += -DSANITIZER_LIBBACKTRACE -I $(top_srcdir)/../libbacktrace \
+AM_CXXFLAGS += -DSANITIZER_LIBBACKTRACE -DSANITIZER_CP_DEMANGLE \
+ -I $(top_srcdir)/../libbacktrace \
-I $(top_builddir)/libbacktrace \
+ -I $(top_srcdir)/../include \
-include $(top_srcdir)/libbacktrace/backtrace-rename.h
endif
ACLOCAL_AMFLAGS = -I m4
diff --git a/libsanitizer/sanitizer_common/Makefile.in b/libsanitizer/sanitizer_common/Makefile.in
index e5dc5be3812..e9fd115e976 100644
--- a/libsanitizer/sanitizer_common/Makefile.in
+++ b/libsanitizer/sanitizer_common/Makefile.in
@@ -35,8 +35,10 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
-@LIBBACKTRACE_SUPPORTED_TRUE@am__append_1 = -DSANITIZER_LIBBACKTRACE -I $(top_srcdir)/../libbacktrace \
+@LIBBACKTRACE_SUPPORTED_TRUE@am__append_1 = -DSANITIZER_LIBBACKTRACE -DSANITIZER_CP_DEMANGLE \
+@LIBBACKTRACE_SUPPORTED_TRUE@ -I $(top_srcdir)/../libbacktrace \
@LIBBACKTRACE_SUPPORTED_TRUE@ -I $(top_builddir)/libbacktrace \
+@LIBBACKTRACE_SUPPORTED_TRUE@ -I $(top_srcdir)/../include \
@LIBBACKTRACE_SUPPORTED_TRUE@ -include $(top_srcdir)/libbacktrace/backtrace-rename.h
subdir = sanitizer_common
diff --git a/libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc b/libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc
index 5654d1de7d4..3023002af47 100644
--- a/libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc
+++ b/libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc
@@ -20,6 +20,10 @@
# include "backtrace-supported.h"
# if SANITIZER_POSIX && BACKTRACE_SUPPORTED && !BACKTRACE_USES_MALLOC
# include "backtrace.h"
+# if SANITIZER_CP_DEMANGLE
+# undef ARRAY_SIZE
+# include "demangle.h"
+# endif
# else
# define SANITIZER_LIBBACKTRACE 0
# endif
@@ -31,6 +35,60 @@ namespace __sanitizer {
namespace {
+#if SANITIZER_CP_DEMANGLE
+struct CplusV3DemangleData {
+ char *buf;
+ uptr size, allocated;
+};
+
+extern "C" {
+static void CplusV3DemangleCallback(const char *s, size_t l, void *vdata) {
+ CplusV3DemangleData *data = (CplusV3DemangleData *)vdata;
+ uptr needed = data->size + l + 1;
+ if (needed > data->allocated) {
+ data->allocated *= 2;
+ if (needed > data->allocated)
+ data->allocated = needed;
+ char *buf = (char *)InternalAlloc(data->allocated);
+ if (data->buf) {
+ internal_memcpy(buf, data->buf, data->size);
+ InternalFree(data->buf);
+ }
+ data->buf = buf;
+ }
+ internal_memcpy(data->buf + data->size, s, l);
+ data->buf[data->size + l] = '\0';
+ data->size += l;
+}
+} // extern "C"
+
+char *CplusV3Demangle(const char *name, bool always_alloc) {
+ CplusV3DemangleData data;
+ data.buf = 0;
+ data.size = 0;
+ data.allocated = 0;
+ if (cplus_demangle_v3_callback(name, DMGL_PARAMS | DMGL_ANSI,
+ CplusV3DemangleCallback, &data)) {
+ if (data.size + 64 > data.allocated)
+ return data.buf;
+ char *buf = internal_strdup(data.buf);
+ InternalFree(data.buf);
+ return buf;
+ }
+ if (data.buf)
+ InternalFree(data.buf);
+ if (always_alloc)
+ return internal_strdup(name);
+ return 0;
+}
+#else
+const char *CplusV3Demangle(const char *name, bool always_alloc) {
+ if (always_alloc)
+ return internal_strdup(name);
+ return 0;
+}
+#endif
+
struct SymbolizeCodeData {
AddressInfo *frames;
uptr n_frames;
@@ -49,7 +107,7 @@ static int SymbolizeCodePCInfoCallback(void *vdata, uintptr_t addr,
info->Clear();
info->FillAddressAndModuleInfo(addr, cdata->module_name,
cdata->module_offset);
- info->function = internal_strdup(function);
+ info->function = CplusV3Demangle(function, true);
if (filename)
info->file = internal_strdup(filename);
info->line = lineno;
@@ -67,7 +125,7 @@ static void SymbolizeCodeCallback(void *vdata, uintptr_t addr,
info->Clear();
info->FillAddressAndModuleInfo(addr, cdata->module_name,
cdata->module_offset);
- info->function = internal_strdup(symname);
+ info->function = CplusV3Demangle(symname, true);
cdata->n_frames = 1;
}
}
@@ -76,7 +134,7 @@ static void SymbolizeDataCallback(void *vdata, uintptr_t, const char *symname,
uintptr_t symval, uintptr_t symsize) {
DataInfo *info = (DataInfo *)vdata;
if (symname && symval) {
- info->name = internal_strdup(symname);
+ info->name = CplusV3Demangle(symname, true);
info->start = symval;
info->size = symsize;
}
@@ -121,6 +179,17 @@ bool LibbacktraceSymbolizer::SymbolizeData(DataInfo *info) {
return true;
}
+const char *LibbacktraceSymbolizer::Demangle(const char *name) {
+#if SANITIZER_CP_DEMANGLE
+ const char *demangled = CplusV3Demangle(name, false);
+ if (demangled)
+ return demangled;
+ return name;
+#else
+ return 0;
+#endif
+}
+
#else // SANITIZER_LIBBACKTRACE
LibbacktraceSymbolizer *LibbacktraceSymbolizer::get(LowLevelAllocator *alloc) {
@@ -139,6 +208,10 @@ bool LibbacktraceSymbolizer::SymbolizeData(DataInfo *info) {
return false;
}
+const char *LibbacktraceSymbolizer::Demangle(const char *name) {
+ return 0;
+}
+
#endif // SANITIZER_LIBBACKTRACE
} // namespace __sanitizer
diff --git a/libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.h b/libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.h
index f09cea51268..05f0558c3d8 100644
--- a/libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.h
+++ b/libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.h
@@ -29,6 +29,8 @@ class LibbacktraceSymbolizer {
bool SymbolizeData(DataInfo *info);
+ const char *Demangle(const char *name);
+
private:
explicit LibbacktraceSymbolizer(void *state) : state_(state) {}
diff --git a/libsanitizer/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc b/libsanitizer/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
index 9f34b646217..7aead970382 100644
--- a/libsanitizer/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
+++ b/libsanitizer/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
@@ -513,6 +513,11 @@ class POSIXSymbolizer : public Symbolizer {
SymbolizerScope sym_scope(this);
if (internal_symbolizer_ != 0)
return internal_symbolizer_->Demangle(name);
+ if (libbacktrace_symbolizer_ != 0) {
+ const char *demangled = libbacktrace_symbolizer_->Demangle(name);
+ if (demangled)
+ return demangled;
+ }
return DemangleCXXABI(name);
}