aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2016-11-16 23:09:27 +0000
committerMark Wielaard <mark@klomp.org>2016-11-18 11:06:18 +0100
commit535aade664ac4170fe82e52c9addd686156220a1 (patch)
treef80aadb5735148f6fbf4419a34d5dd74b290eecf /include
parentddc5804ebd4b2be29ad4e3e259f5c6e907f34f26 (diff)
downloadgdb-535aade664ac4170fe82e52c9addd686156220a1.zip
gdb-535aade664ac4170fe82e52c9addd686156220a1.tar.gz
gdb-535aade664ac4170fe82e52c9addd686156220a1.tar.bz2
libiberty: Add Rust symbol demangling.
Adds Rust symbol demangler. Rust mangles symbols using GNU_V3 style, adding a hash and various special character subtitutions. This adds a new rust style to cplus_demangle and adds 3 helper functions rust_demangle, rust_demangle_sym and rust_is_mangled. rust-demangle.c was written by David. Mark did the code formatting to GNU style and integration into the gcc/libiberty build system and testsuite. include/ChangeLog: 2016-11-03 David Tolnay <dtolnay@gmail.com> Mark Wielaard <mark@klomp.org> * demangle.h (DMGL_RUST): New macro. (DMGL_STYLE_MASK): Add DMGL_RUST. (demangling_styles): Add dlang_rust. (RUST_DEMANGLING_STYLE_STRING): New macro. (RUST_DEMANGLING): New macro. (rust_demangle): New prototype. (rust_is_mangled): Likewise. (rust_demangle_sym): Likewise. libiberty/ChangeLog: 2016-11-03 David Tolnay <dtolnay@gmail.com> Mark Wielaard <mark@klomp.org> * Makefile.in (CFILES): Add rust-demangle.c. (REQUIRED_OFILES): Add rust-demangle.o. * cplus-dem.c (libiberty_demanglers): Add rust_demangling case. (cplus_demangle): Handle RUST_DEMANGLING. (rust_demangle): New function. * rust-demangle.c: New file. * testsuite/Makefile.in (really-check): Add check-rust-demangle. (check-rust-demangle): New rule. * testsuite/rust-demangle-expected: New file.
Diffstat (limited to 'include')
-rw-r--r--include/ChangeLog12
-rw-r--r--include/demangle.h29
2 files changed, 39 insertions, 2 deletions
diff --git a/include/ChangeLog b/include/ChangeLog
index 96ddcc7..18fe3ed 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,15 @@
+2016-11-03 David Tolnay <dtolnay@gmail.com>
+ Mark Wielaard <mark@klomp.org>
+
+ * demangle.h (DMGL_RUST): New macro.
+ (DMGL_STYLE_MASK): Add DMGL_RUST.
+ (demangling_styles): Add dlang_rust.
+ (RUST_DEMANGLING_STYLE_STRING): New macro.
+ (RUST_DEMANGLING): New macro.
+ (rust_demangle): New prototype.
+ (rust_is_mangled): Likewise.
+ (rust_demangle_sym): Likewise.
+
2016-11-07 Jason Merrill <jason@redhat.com>
* demangle.h (enum demangle_component_type): Add
diff --git a/include/demangle.h b/include/demangle.h
index 12f51ca..e9551cb 100644
--- a/include/demangle.h
+++ b/include/demangle.h
@@ -63,9 +63,10 @@ extern "C" {
#define DMGL_GNU_V3 (1 << 14)
#define DMGL_GNAT (1 << 15)
#define DMGL_DLANG (1 << 16)
+#define DMGL_RUST (1 << 17) /* Rust wraps GNU_V3 style mangling. */
/* If none of these are set, use 'current_demangling_style' as the default. */
-#define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT|DMGL_DLANG)
+#define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT|DMGL_DLANG|DMGL_RUST)
/* Enumeration of possible demangling styles.
@@ -88,7 +89,8 @@ extern enum demangling_styles
gnu_v3_demangling = DMGL_GNU_V3,
java_demangling = DMGL_JAVA,
gnat_demangling = DMGL_GNAT,
- dlang_demangling = DMGL_DLANG
+ dlang_demangling = DMGL_DLANG,
+ rust_demangling = DMGL_RUST
} current_demangling_style;
/* Define string names for the various demangling styles. */
@@ -104,6 +106,7 @@ extern enum demangling_styles
#define JAVA_DEMANGLING_STYLE_STRING "java"
#define GNAT_DEMANGLING_STYLE_STRING "gnat"
#define DLANG_DEMANGLING_STYLE_STRING "dlang"
+#define RUST_DEMANGLING_STYLE_STRING "rust"
/* Some macros to test what demangling style is active. */
@@ -118,6 +121,7 @@ extern enum demangling_styles
#define JAVA_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA)
#define GNAT_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT)
#define DLANG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_DLANG)
+#define RUST_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_RUST)
/* Provide information about the available demangle styles. This code is
pulled from gdb into libiberty because it is useful to binutils also. */
@@ -175,6 +179,27 @@ ada_demangle (const char *mangled, int options);
extern char *
dlang_demangle (const char *mangled, int options);
+/* Returns non-zero iff MANGLED is a rust mangled symbol. MANGLED must
+ already have been demangled through cplus_demangle_v3. If this function
+ returns non-zero then MANGLED can be demangled (in-place) using
+ RUST_DEMANGLE_SYM. */
+extern int
+rust_is_mangled (const char *mangled);
+
+/* Demangles SYM (in-place) if RUST_IS_MANGLED returned non-zero for SYM.
+ If RUST_IS_MANGLED returned zero for SYM then RUST_DEMANGLE_SYM might
+ replace characters that cannot be demangled with '?' and might truncate
+ SYM. After calling RUST_DEMANGLE_SYM SYM might be shorter, but never
+ larger. */
+extern void
+rust_demangle_sym (char *sym);
+
+/* Demangles MANGLED if it was GNU_V3 and then RUST mangled, otherwise
+ returns NULL. Uses CPLUS_DEMANGLE_V3, RUST_IS_MANGLED and
+ RUST_DEMANGLE_SYM. Returns a new string that is owned by the caller. */
+extern char *
+rust_demangle (const char *mangled, int options);
+
enum gnu_v3_ctor_kinds {
gnu_v3_complete_object_ctor = 1,
gnu_v3_base_object_ctor,