summaryrefslogtreecommitdiffstats
path: root/src/debug
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2006-05-08 23:32:44 +0000
committermental <mental@users.sourceforge.net>2006-05-08 23:32:44 +0000
commit87b4552c924bc685a8ea8608a1c22c23fe54d980 (patch)
tree37e936dce89a29b1382f4361be54679d703a41f0 /src/debug
parentuse c++filt for symbol demangling if available (diff)
downloadinkscape-87b4552c924bc685a8ea8608a1c22c23fe54d980.tar.gz
inkscape-87b4552c924bc685a8ea8608a1c22c23fe54d980.zip
add missing files
(bzr r779)
Diffstat (limited to 'src/debug')
-rw-r--r--src/debug/demangle.cpp80
-rw-r--r--src/debug/demangle.h37
2 files changed, 117 insertions, 0 deletions
diff --git a/src/debug/demangle.cpp b/src/debug/demangle.cpp
new file mode 100644
index 000000000..79d0275bf
--- /dev/null
+++ b/src/debug/demangle.cpp
@@ -0,0 +1,80 @@
+/*
+ * Inkscape::Debug::demangle - demangle C++ symbol names
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2006 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <map>
+#include "debug/demangle.h"
+#include "util/format.h"
+#include "gc-alloc.h"
+
+namespace Inkscape {
+
+namespace Debug {
+
+namespace {
+
+char const *demangle_helper(char const *name) {
+ char buffer[1024];
+ char const *result;
+ FILE *stream=popen(Util::format("c++filt %s", name), "r");
+ if (fgets(buffer, sizeof(buffer), stream)) {
+ size_t len=strlen(buffer);
+ if ( buffer[len-1] == '\n' ) {
+ buffer[len-1] = '\000';
+ }
+ result = strdup(buffer);
+ } else {
+ result = name;
+ }
+ pclose(stream);
+ return result;
+}
+
+struct string_less_than {
+ bool operator()(char const *a, char const *b) {
+ return ( strcmp(a, b) < 0 );
+ }
+};
+
+typedef std::map<char const *, char const *, string_less_than> MangleCache;
+MangleCache mangle_cache;
+
+}
+
+Util::ptr_shared<char> demangle(char const *name) {
+ MangleCache::iterator found=mangle_cache.find(name);
+
+ char const *result;
+ if ( found != mangle_cache.end() ) {
+ result = (*found).second;
+ } else {
+ result = demangle_helper(name);
+ mangle_cache[name] = result;
+ }
+
+ return Util::share_unsafe(result);
+}
+
+}
+
+}
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/debug/demangle.h b/src/debug/demangle.h
new file mode 100644
index 000000000..8c0dd6b4e
--- /dev/null
+++ b/src/debug/demangle.h
@@ -0,0 +1,37 @@
+/*
+ * Inkscape::Debug::demangle - demangle C++ symbol names
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2006 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_DEBUG_DEMANGLE_H
+#define SEEN_INKSCAPE_DEBUG_DEMANGLE_H
+
+#include "util/share.h"
+
+namespace Inkscape {
+
+namespace Debug {
+
+Util::ptr_shared<char> demangle(char const *name);
+
+}
+
+}
+
+#endif
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :