forked from Imagelibrary/binutils-gdb
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.
This commit is contained in:
committed by
Mark Wielaard
parent
ddc5804ebd
commit
535aade664
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user