GP-3577 - Demangler - Updated the Gnu Demangler to version 2.41

This commit is contained in:
dragonmacher 2023-11-06 17:05:24 -05:00
parent 0fb2014df1
commit d20ccc377f
29 changed files with 3285 additions and 1344 deletions

View file

@ -17,9 +17,9 @@ apply plugin: 'eclipse'
eclipse.project.name = 'GPL DemanglerGnu'
def v33_1 = "demangler_gnu_v2_33_1"
def v41 = "demangler_gnu_v2_41"
def v24 = "demangler_gnu_v2_24"
def srcVersion33_1 = "src/demangler_gnu_v2_33_1"
def srcVersion41 = "src/demangler_gnu_v2_41"
def srcVersion24 = "src/demangler_gnu_v2_24"
/**
@ -39,21 +39,20 @@ task zipBuildableSource(type:Zip) {
description "Collects the source files needed to build this module."
archiveBaseName = project.name + "-src-for-build"
archiveExtension = 'zip'
//
// Version 2.33.1
// Version 2.41
//
from (project.projectDir.toString() + "/" + srcVersion33_1 + "c") {
into "/" + srcVersion33_1
from (project.projectDir.toString() + "/" + srcVersion41 + "c") {
into "/" + srcVersion41
}
from (project.projectDir.toString() + "/" + srcVersion33_1 + "/headers") {
into "/" + srcVersion33_1
from (project.projectDir.toString() + "/" + srcVersion41 + "/headers") {
into "/" + srcVersion41
}
from (project.projectDir.toString() + "/" + srcVersion33_1 + "/build") {
into "/" + srcVersion33_1
from (project.projectDir.toString() + "/" + srcVersion41 + "/build") {
into "/" + srcVersion41
}
from (project.projectDir.toString() + "/" + srcVersion33_1 + "/README.txt")
from (project.projectDir.toString() + "/" + srcVersion41 + "/README.txt")
//
// Version 2.24
@ -72,11 +71,11 @@ task zipBuildableSource(type:Zip) {
model {
//
// Version 2.33.1
//
components {
demangler_gnu_v2_33_1(NativeExecutableSpec) {
//
// Version 2.41
//
demangler_gnu_v2_41(NativeExecutableSpec) {
targetPlatform "win_x86_64"
targetPlatform "linux_x86_64"
targetPlatform "linux_arm_64"
@ -85,10 +84,10 @@ model {
sources {
c {
source {
srcDir srcVersion33_1 + "/c"
srcDir srcVersion41 + "/c"
}
exportedHeaders {
srcDir srcVersion33_1 + "/headers"
srcDir srcVersion41 + "/headers"
}
}
}
@ -127,8 +126,8 @@ model {
def version = b.getApplication().getName()
if (version.equals(v33_1)) {
if (toolChain in Gcc) {
if (version.equals(v41)) {
if (toolChain in Gcc) {
//cCompiler.args "-DCP_DEMANGLE_DEBUG"
cCompiler.args "-DHAVE_STDLIB_H"
cCompiler.args "-DHAVE_STRING_H"

View file

@ -1,81 +0,0 @@
PURPOSE
This is a readme file to note the changes made to the binutils-2.33.1 source
code in to build its GNU demangler. The files in this directory are used to create a demangling
utility during the full build process.
COPIED SOURCE CODE / BUILDING RESTRICTIONS
Most of the files used to build the Ghidra GNU demangler are copied from binutils and have
not been changed. Further, the files in this directory are a small subset of the files used to
build the binutils suite. By copying specific files we are able to use Make and Visual Studio
to build a stand alone demangler without having to perform the more complicated build needed
to build binutils. Specifically, we do not have to run the configure utility that is
provided by binutils. This is critical, as we are using Visual Studio to build on Windows,
which does not have the configure utility support. If we ever wished to build the entire
binutils suite on Windows, then we would most likely need to use a GNU environment made for
Windows, such as MinGW.
CHANGES TO BINUTILS SOURCE
cp-demangle.c
This file contains a small, one-line change to flush to the standard output stream. Without
this change, the program, when called repeatedly from Java would hang as it attempts to read
characters that are buffered on the native side.
UPDATING
If we ever wish to update to a newer version of binutils, then we will need to re-copy the files
in this directory. That is, unless at least one of the following changes happens:
1) building a stand alone c++filt is simple enough that we can do it on each platform, or
2) we decide to build the entire binutils suite and use the full c++filt binary.
SOURCE FILES
binutils/libiberty/alloca.c
binutils/libiberty/argv.c
binutils/libiberty/cp-demangle.c
binutils/libiberty/cplus-dem.c
binutils/libiberty/d-demangle.c
binutils/libiberty/dyn-string.c
binutils/libiberty/getopt.c
binutils/libiberty/getopt1.c
binutils/libiberty/rust-demangle.c
binutils/libiberty/safe-ctype.c
binutils/libiberty/xexit.c
binutils/libiberty/xstrdup.c
binutils/include/ansidecl.h
binutils/libiberty/cp-demangle.h
binutils/include/demangle.h
binutils/include/dyn-string.h
binutils/include/getopt.h
binutils/include/libiberty.h
binutils/libiberty/rust-demangle.h
binutils/include/safe-ctype.h
This file is created to add minor missing dependencies.
missing.c
LICENSE
The files listed above are licensed by using the file header or the COPYING or COPYING.LIB file
listed in the original source directory of binutils.

View file

@ -1,353 +0,0 @@
/* ###
* IP: LGPL 2.1
* NOTE: See binutils/libiberty/COPYING.LIB
*/
/* Demangler for the Rust programming language
Copyright (C) 2016-2019 Free Software Foundation, Inc.
Written by David Tolnay (dtolnay@gmail.com).
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU Library General Public
License, the Free Software Foundation gives you unlimited permission
to link the compiled version of this file into combinations with other
programs, and to distribute those combinations without any restriction
coming from the use of this file. (The Library Public License
restrictions do apply in other respects; for example, they cover
modification of the file, and distribution when not linked into a
combined executable.)
Libiberty is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with libiberty; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "safe-ctype.h"
#include <sys/types.h>
#include <string.h>
#include <stdio.h>
#ifdef HAVE_STRING_H
#include <string.h>
#else
extern size_t strlen(const char *s);
extern int strncmp(const char *s1, const char *s2, size_t n);
extern void *memset(void *s, int c, size_t n);
#endif
#include <demangle.h>
#include "libiberty.h"
#include "rust-demangle.h"
/* Mangled Rust symbols look like this:
_$LT$std..sys..fd..FileDesc$u20$as$u20$core..ops..Drop$GT$::drop::hc68340e1baa4987a
The original symbol is:
<std::sys::fd::FileDesc as core::ops::Drop>::drop
The last component of the path is a 64-bit hash in lowercase hex,
prefixed with "h". Rust does not have a global namespace between
crates, an illusion which Rust maintains by using the hash to
distinguish things that would otherwise have the same symbol.
Any path component not starting with a XID_Start character is
prefixed with "_".
The following escape sequences are used:
"," => $C$
"@" => $SP$
"*" => $BP$
"&" => $RF$
"<" => $LT$
">" => $GT$
"(" => $LP$
")" => $RP$
" " => $u20$
"\"" => $u22$
"'" => $u27$
"+" => $u2b$
";" => $u3b$
"[" => $u5b$
"]" => $u5d$
"{" => $u7b$
"}" => $u7d$
"~" => $u7e$
A double ".." means "::" and a single "." means "-".
The only characters allowed in the mangled symbol are a-zA-Z0-9 and _.:$ */
static const char *hash_prefix = "::h";
static const size_t hash_prefix_len = 3;
static const size_t hash_len = 16;
static int is_prefixed_hash (const char *start);
static int looks_like_rust (const char *sym, size_t len);
static int unescape (const char **in, char **out, const char *seq, char value);
/* INPUT: sym: symbol that has been through C++ (gnu v3) demangling
This function looks for the following indicators:
1. The hash must consist of "h" followed by 16 lowercase hex digits.
2. As a sanity check, the hash must use between 5 and 15 of the 16
possible hex digits. This is true of 99.9998% of hashes so once
in your life you may see a false negative. The point is to
notice path components that could be Rust hashes but are
probably not, like "haaaaaaaaaaaaaaaa". In this case a false
positive (non-Rust symbol has an important path component
removed because it looks like a Rust hash) is worse than a false
negative (the rare Rust symbol is not demangled) so this sets
the balance in favor of false negatives.
3. There must be no characters other than a-zA-Z0-9 and _.:$
4. There must be no unrecognized $-sign sequences.
5. There must be no sequence of three or more dots in a row ("..."). */
int
rust_is_mangled (const char *sym)
{
size_t len, len_without_hash;
if (!sym)
return 0;
len = strlen (sym);
if (len <= hash_prefix_len + hash_len)
/* Not long enough to contain "::h" + hash + something else */
return 0;
len_without_hash = len - (hash_prefix_len + hash_len);
if (!is_prefixed_hash (sym + len_without_hash))
return 0;
return looks_like_rust (sym, len_without_hash);
}
/* A hash is the prefix "::h" followed by 16 lowercase hex digits. The
hex digits must comprise between 5 and 15 (inclusive) distinct
digits. */
static int
is_prefixed_hash (const char *str)
{
const char *end;
char seen[16];
size_t i;
int count;
if (strncmp (str, hash_prefix, hash_prefix_len))
return 0;
str += hash_prefix_len;
memset (seen, 0, sizeof(seen));
for (end = str + hash_len; str < end; str++)
if (*str >= '0' && *str <= '9')
seen[*str - '0'] = 1;
else if (*str >= 'a' && *str <= 'f')
seen[*str - 'a' + 10] = 1;
else
return 0;
/* Count how many distinct digits seen */
count = 0;
for (i = 0; i < 16; i++)
if (seen[i])
count++;
return count >= 5 && count <= 15;
}
static int
looks_like_rust (const char *str, size_t len)
{
const char *end = str + len;
while (str < end)
switch (*str)
{
case '$':
if (!strncmp (str, "$C$", 3))
str += 3;
else if (!strncmp (str, "$SP$", 4)
|| !strncmp (str, "$BP$", 4)
|| !strncmp (str, "$RF$", 4)
|| !strncmp (str, "$LT$", 4)
|| !strncmp (str, "$GT$", 4)
|| !strncmp (str, "$LP$", 4)
|| !strncmp (str, "$RP$", 4))
str += 4;
else if (!strncmp (str, "$u20$", 5)
|| !strncmp (str, "$u22$", 5)
|| !strncmp (str, "$u27$", 5)
|| !strncmp (str, "$u2b$", 5)
|| !strncmp (str, "$u3b$", 5)
|| !strncmp (str, "$u5b$", 5)
|| !strncmp (str, "$u5d$", 5)
|| !strncmp (str, "$u7b$", 5)
|| !strncmp (str, "$u7d$", 5)
|| !strncmp (str, "$u7e$", 5))
str += 5;
else
return 0;
break;
case '.':
/* Do not allow three or more consecutive dots */
if (!strncmp (str, "...", 3))
return 0;
/* Fall through */
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
case 'y': case 'z':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
case 'Y': case 'Z':
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
case '_':
case ':':
str++;
break;
default:
return 0;
}
return 1;
}
/*
INPUT: sym: symbol for which rust_is_mangled(sym) returned 1.
The input is demangled in-place because the mangled name is always
longer than the demangled one. */
void
rust_demangle_sym (char *sym)
{
const char *in;
char *out;
const char *end;
if (!sym)
return;
in = sym;
out = sym;
end = sym + strlen (sym) - (hash_prefix_len + hash_len);
while (in < end)
switch (*in)
{
case '$':
if (!(unescape (&in, &out, "$C$", ',')
|| unescape (&in, &out, "$SP$", '@')
|| unescape (&in, &out, "$BP$", '*')
|| unescape (&in, &out, "$RF$", '&')
|| unescape (&in, &out, "$LT$", '<')
|| unescape (&in, &out, "$GT$", '>')
|| unescape (&in, &out, "$LP$", '(')
|| unescape (&in, &out, "$RP$", ')')
|| unescape (&in, &out, "$u20$", ' ')
|| unescape (&in, &out, "$u22$", '\"')
|| unescape (&in, &out, "$u27$", '\'')
|| unescape (&in, &out, "$u2b$", '+')
|| unescape (&in, &out, "$u3b$", ';')
|| unescape (&in, &out, "$u5b$", '[')
|| unescape (&in, &out, "$u5d$", ']')
|| unescape (&in, &out, "$u7b$", '{')
|| unescape (&in, &out, "$u7d$", '}')
|| unescape (&in, &out, "$u7e$", '~'))) {
/* unexpected escape sequence, not looks_like_rust. */
goto fail;
}
break;
case '_':
/* If this is the start of a path component and the next
character is an escape sequence, ignore the underscore. The
mangler inserts an underscore to make sure the path
component begins with a XID_Start character. */
if ((in == sym || in[-1] == ':') && in[1] == '$')
in++;
else
*out++ = *in++;
break;
case '.':
if (in[1] == '.')
{
/* ".." becomes "::" */
*out++ = ':';
*out++ = ':';
in += 2;
}
else
{
/* "." becomes "-" */
*out++ = '-';
in++;
}
break;
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
case 'y': case 'z':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
case 'Y': case 'Z':
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
case ':':
*out++ = *in++;
break;
default:
/* unexpected character in symbol, not looks_like_rust. */
goto fail;
}
goto done;
fail:
*out++ = '?'; /* This is pretty lame, but it's hard to do better. */
done:
*out = '\0';
}
static int
unescape (const char **in, char **out, const char *seq, char value)
{
size_t len = strlen (seq);
if (strncmp (*in, seq, len))
return 0;
**out = value;
*in += len;
*out += 1;
return 1;
}

View file

@ -1,49 +0,0 @@
/* ###
* IP: LGPL 2.1
* NOTE: See binutils/libiberty/COPYING.LIB
*/
/* Internal demangler interface for the Rust programming language.
Copyright (C) 2016-2019 Free Software Foundation, Inc.
Written by David Tolnay (dtolnay@gmail.com).
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU Library General Public
License, the Free Software Foundation gives you unlimited permission
to link the compiled version of this file into combinations with other
programs, and to distribute those combinations without any restriction
coming from the use of this file. (The Library Public License
restrictions do apply in other respects; for example, they cover
modification of the file, and distribution when not linked into a
combined executable.)
Libiberty is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with libiberty; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/>. */
/* This file provides some definitions shared by cplus-dem.c and
rust-demangle.c. It should not be included by any other files. */
/* 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);

View file

@ -1,6 +1,6 @@
/* ###
* IP: LGPL 2.1
* NOTE: license is not in file, but in the directory from whence it came: binutils-2.24/libiberty/COPYING.LIB
* NOTE: See binutils/libiberty/COPYING.LIB
*/
/* alloca.c -- allocate automatically reclaimed memory
(Mostly) portable public-domain implementation -- D A Gwyn
@ -162,7 +162,7 @@ static header *last_alloca_header = NULL; /* -> last alloca header. */
/* @undocumented C_alloca */
PTR
void *
C_alloca (size_t size)
{
auto char probe; /* Probes stack depth: */
@ -185,7 +185,7 @@ C_alloca (size_t size)
{
register header *np = hp->h.next;
free ((PTR) hp); /* Collect garbage. */
free ((void *) hp); /* Collect garbage. */
hp = np; /* -> next header. */
}
@ -214,7 +214,7 @@ C_alloca (size_t size)
/* User storage begins just after header. */
return (PTR) ((char *) new_storage + sizeof (header));
return (void *) ((char *) new_storage + sizeof (header));
}
}

View file

@ -3,7 +3,7 @@
* NOTE: See binutils/libiberty/COPYING.LIB
*/
/* Create and destroy argument vectors (argv's)
Copyright (C) 1992-2019 Free Software Foundation, Inc.
Copyright (C) 1992-2023 Free Software Foundation, Inc.
Written by Fred Fish @ Cygnus Support
This file is part of the libiberty library.
@ -293,8 +293,8 @@ char **buildargv (const char *input)
@deftypefn Extension int writeargv (char * const *@var{argv}, FILE *@var{file})
Write each member of ARGV, handling all necessary quoting, to the file
named by FILE, separated by whitespace. Return 0 on success, non-zero
if an error occurred while writing to FILE.
associated with FILE, separated by whitespace. Return 0 on success,
non-zero if an error occurred while writing to FILE.
@end deftypefn
@ -303,8 +303,6 @@ if an error occurred while writing to FILE.
int
writeargv (char * const *argv, FILE *f)
{
int status = 0;
if (f == NULL)
return 1;
@ -318,29 +316,26 @@ writeargv (char * const *argv, FILE *f)
if (ISSPACE(c) || c == '\\' || c == '\'' || c == '"')
if (EOF == fputc ('\\', f))
{
status = 1;
goto done;
}
return 1;
if (EOF == fputc (c, f))
{
status = 1;
goto done;
}
return 1;
arg++;
}
/* Write out a pair of quotes for an empty argument. */
if (arg == *argv)
if (EOF == fputs ("\"\"", f))
return 1;
if (EOF == fputc ('\n', f))
{
status = 1;
goto done;
}
return 1;
argv++;
}
done:
return status;
return 0;
}
/*
@ -438,7 +433,10 @@ expandargv (int *argcp, char ***argvp)
due to CR/LF->CR translation when reading text files.
That does not in-and-of itself indicate failure. */
&& ferror (f))
goto error;
{
free (buffer);
goto error;
}
/* Add a NUL terminator. */
buffer[len] = '\0';
/* If the file is empty or contains only whitespace, buildargv would

View file

@ -3,7 +3,7 @@
* NOTE: See binutils/libiberty/COPYING.LIB
*/
/* Demangler for GNU C++
Copyright (C) 1989-2019 Free Software Foundation, Inc.
Copyright (C) 1989-2023 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.uucp)
Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling
Modified by Satish Pai (pai@apollo.hp.com) for HP demangling
@ -56,7 +56,6 @@ void * realloc ();
#define CURRENT_DEMANGLING_STYLE options
#include "libiberty.h"
#include "rust-demangle.h"
enum demangling_styles current_demangling_style = auto_demangling;
@ -164,27 +163,20 @@ cplus_demangle (const char *mangled, int options)
if ((options & DMGL_STYLE_MASK) == 0)
options |= (int) current_demangling_style & DMGL_STYLE_MASK;
/* The Rust demangling is implemented elsewhere.
Legacy Rust symbols overlap with GNU_V3, so try Rust first. */
if (RUST_DEMANGLING || AUTO_DEMANGLING)
{
ret = rust_demangle (mangled, options);
if (ret || RUST_DEMANGLING)
return ret;
}
/* The V3 ABI demangling is implemented elsewhere. */
if (GNU_V3_DEMANGLING || RUST_DEMANGLING || AUTO_DEMANGLING)
if (GNU_V3_DEMANGLING || AUTO_DEMANGLING)
{
ret = cplus_demangle_v3 (mangled, options);
if (GNU_V3_DEMANGLING)
return ret;
if (ret)
{
/* Rust symbols are GNU_V3 mangled plus some extra subtitutions.
The subtitutions are always smaller, so do in place changes. */
if (rust_is_mangled (ret))
rust_demangle_sym (ret);
else if (RUST_DEMANGLING)
{
free (ret);
ret = NULL;
}
}
if (ret || RUST_DEMANGLING)
if (ret || GNU_V3_DEMANGLING)
return ret;
}
@ -208,27 +200,6 @@ cplus_demangle (const char *mangled, int options)
return (ret);
}
char *
rust_demangle (const char *mangled, int options)
{
/* Rust symbols are GNU_V3 mangled plus some extra subtitutions. */
char *ret = cplus_demangle_v3 (mangled, options);
/* The Rust subtitutions are always smaller, so do in place changes. */
if (ret != NULL)
{
if (rust_is_mangled (ret))
rust_demangle_sym (ret);
else
{
free (ret);
ret = NULL;
}
}
return ret;
}
/* Demangle ada names. The encoding is documented in gcc/ada/exp_dbug.ads. */
char *

View file

@ -2,7 +2,7 @@
* IP: GPL 3
*/
/* Demangler for GNU C++ - main program
Copyright (C) 1989-2019 Free Software Foundation, Inc.
Copyright (C) 1989-2023 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.uucp)
Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling
Modified by Satish Pai (pai@apollo.hp.com) for HP demangling
@ -23,23 +23,34 @@
along with GCC; see the file COPYING. If not, write to the Free
Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA.
CHANGE NOTICE:
This file was changed on July 22nd, 2020.
*/
CHANGE NOTICE:
This file was changed on October 31st, 2023.
*/
#include <stdlib.h>
#include <string.h>
// #include "sysdep.h" // Changed 10/31/23
// error reporting front end
// #include "bfd.h" // Changed 10/31/23
#include <stdlib.h> // Changed 10/31/23
#include <string.h> // Changed 10/31/23
#include "libiberty.h"
#include "demangle.h"
#include "getopt.h"
#include "safe-ctype.h"
// bfd code
// #include "bucomm.h" // Changed 10/31/23
static int flags = DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE;
static int strip_underscore = 0; // TARGET_PREPENDS_UNDERSCORE; // Changed Jan 22, 2020
static const char *program_name; // Changed Jan 22, 2020
static int strip_underscore = 0; // TARGET_PREPENDS_UNDERSCORE; // Changed 10/31/23
// declared in bucomm.c
static const char *program_name; // Changed 10/31/23
static const struct option long_options[] =
{
@ -108,10 +119,12 @@ Usage: %s [options] [mangled names]\n", program_name);
fprintf (stream, "\
Options are:\n\
[-_|--strip-underscore] Ignore first leading underscore%s\n",
strip_underscore ? " (default)" : ""); // Changed Jan 22, 2020
// TARGET_PREPENDS_UNDERSCORE ? " (default)" : ""); // Changed 10/31/23
strip_underscore ? " (default)" : ""); // Changed 10/31/23
fprintf (stream, "\
[-n|--no-strip-underscore] Do not ignore a leading underscore%s\n",
strip_underscore ? "" : " (default)"); // Changed Jan 22, 2020
// TARGET_PREPENDS_UNDERSCORE ? "" : " (default)"); // Changed 10/31/23
strip_underscore ? "" : " (default)"); // Changed 10/31/23
fprintf (stream, "\
[-p|--no-params] Do not display function arguments\n\
[-i|--no-verbose] Do not show implementation details (if any)\n\
@ -130,11 +143,11 @@ Demangled names are displayed to stdout.\n\
If a name cannot be demangled it is just echoed to stdout.\n\
If no names are provided on the command line, stdin is read.\n");
/* Changed Jan 22, 2020
/* Changed 10/31/23
// defined in version.h
if (REPORT_BUGS_TO[0] && status == 0)
fprintf (stream, _("Report bugs to %s.\n"), REPORT_BUGS_TO);
*/
*/
exit (status);
}
@ -158,8 +171,8 @@ main (int argc, char **argv)
enum demangling_styles style = auto_demangling;
program_name = argv[0];
// xmalloc_set_program_name (program_name); // Changed Jan 22, 2020
// bfd_set_error_program_name (program_name); // Changed Jan 22, 2020
// xmalloc_set_program_name (program_name); // Changed 10/31/23
// bfd_set_error_program_name (program_name); // Changed 10/31/23
expandargv (&argc, &argv);
@ -191,7 +204,8 @@ main (int argc, char **argv)
flags &= ~ DMGL_VERBOSE;
break;
case 'v':
printf ("(GNU Binutils) c++filt 2.33.1\n"); // Changed Jan 22, 2020
// print_version ("c++filt"); // Changed 10/31/23
printf ("c++filt 2.41\n"); // Changed 10/31/23
return 0;
case '_':
strip_underscore = 1;
@ -230,13 +244,14 @@ main (int argc, char **argv)
case rust_demangling:
valid_symbols = standard_symbol_characters ();
break;
default: {
default:
/* Folks should explicitly indicate the appropriate alphabet for
each demangling. Providing a default would allow the
question to go unconsidered. */
fprintf (stderr, "Internal error: no symbol alphabet for current style\n"); // Changed Jan 22, 2020
exit (1); // Changed Jan 22, 2020
}
// fatal ("Internal error: no symbol alphabet for current style"); // Changed 10/31/23
fprintf (stderr, "Internal error: no symbol alphabet for current style\n"); // Changed 10/31/23
exit (1); // Changed 10/31/23
}
for (;;)

View file

@ -3,7 +3,7 @@
* NOTE: See binutils/include/COPYING3
*/
/* An abstract string datatype.
Copyright (C) 1998-2019 Free Software Foundation, Inc.
Copyright (C) 1998-2023 Free Software Foundation, Inc.
Contributed by Mark Mitchell (mark@markmitchell.com).
This file is part of GNU CC.
@ -281,7 +281,7 @@ dyn_string_insert_cstr (dyn_string_t dest, int pos, const char *src)
for (i = dest->length; i >= pos; --i)
dest->s[i + length] = dest->s[i];
/* Splice in the new stuff. */
strncpy (dest->s + pos, src, length);
memcpy (dest->s + pos, src, length);
/* Compute the new length. */
dest->length += length;
return 1;

View file

@ -1,5 +1,5 @@
/* ###
* IP: GPL 3
* IP: GPL 3 Linking Permitted
* NOTE: See binutils/include/COPYING3
*/
/* Getopt for GNU.
@ -7,7 +7,7 @@
"Keep this file name-space clean" means, talk to drepper@gnu.org
before changing it!
Copyright (C) 1987-2019 Free Software Foundation, Inc.
Copyright (C) 1987-2023 Free Software Foundation, Inc.
NOTE: This source is derived from an old version taken from the GNU C
Library (glibc).

View file

@ -1,9 +1,9 @@
/* ###
* IP: GPL 3
* IP: GPL 3 Linking Permitted
* NOTE: See binutils/include/COPYING3
*/
/* getopt_long and getopt_long_only entry points for GNU getopt.
Copyright (C) 1987-2019 Free Software Foundation, Inc.
Copyright (C) 1987-2023 Free Software Foundation, Inc.
NOTE: This source is derived from an old version taken from the GNU C
Library (glibc).

View file

@ -28,7 +28,7 @@
CHANGE NOTICE:
This file was created on January 22nd, 2020:
This file was created on October 31st, 2023:
-This code was copied and modified from a previous version of libiberty
*/

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,10 @@
/* ###
* IP: LGPL 2.1
* NOTE: See binutils/include/COPYING
* NOTE: See binutils/libiberty/COPYING.LIB
*/
/* <ctype.h> replacement macros.
Copyright (C) 2000-2019 Free Software Foundation, Inc.
Copyright (C) 2000-2023 Free Software Foundation, Inc.
Contributed by Zack Weinberg <zackw@stanford.edu>.
This file is part of the libiberty library.

View file

@ -3,7 +3,7 @@
* NOTE: See binutils/libiberty/COPYING.LIB
*/
/* xexit.c -- Run any exit handlers, then exit.
Copyright (C) 1994-2019 Free Software Foundation, Inc.
Copyright (C) 1994-2023 Free Software Foundation, Inc.
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or

View file

@ -2,8 +2,8 @@
* IP: LGPL 2.1
* NOTE: See binutils/include/COPYING
*/
/* ANSI and traditional C compatability macros
Copyright (C) 1991-2019 Free Software Foundation, Inc.
/* Compiler compatibility macros
Copyright (C) 1991-2023 Free Software Foundation, Inc.
This file is part of the GNU C Library.
This program is free software; you can redistribute it and/or modify
@ -20,18 +20,7 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
/* ANSI and traditional C compatibility macros
ANSI C is assumed if __STDC__ is #defined.
Macro ANSI C definition Traditional C definition
----- ---- - ---------- ----------- - ----------
PTR `void *' `char *'
const not defined `'
volatile not defined `'
signed not defined `'
For ease of writing code which uses GCC extensions but needs to be
/* For ease of writing code which uses GCC extensions but needs to be
portable to other compilers, we provide the GCC_VERSION macro that
simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
wrappers around __attribute__. Also, __extension__ will be #defined
@ -66,24 +55,10 @@ So instead we use the macro below and test it against specific values. */
#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
#endif /* GCC_VERSION */
#if defined (__STDC__) || defined(__cplusplus) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32)
/* All known AIX compilers implement these things (but don't always
define __STDC__). The RISC/OS MIPS compiler defines these things
in SVR4 mode, but does not define __STDC__. */
/* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
C++ compilers, does not define __STDC__, though it acts as if this
was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
#define PTR void *
#undef const
#undef volatile
#undef signed
/* inline requires special treatment; it's in C99, and GCC >=2.7 supports
it too, but it's not in C89. */
#undef inline
#if __STDC_VERSION__ >= 199901L || defined(__cplusplus) || (defined(__SUNPRO_C) && defined(__C99FEATURES__))
#if (!defined(__cplusplus) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) || (defined(__SUNPRO_C) && defined(__C99FEATURES__))
/* it's a keyword */
#else
# if GCC_VERSION >= 2007
@ -93,22 +68,6 @@ So instead we use the macro below and test it against specific values. */
# endif
#endif
#else /* Not ANSI C. */
#define PTR char *
/* some systems define these in header files for non-ansi mode */
#undef const
#undef volatile
#undef signed
#undef inline
#define const
#define volatile
#define signed
#define inline
#endif /* ANSI C. */
/* Define macros for some gcc attributes. This permits us to use the
macros freely, and know that they will come into play for the
version of gcc in which they are supported. */
@ -296,6 +255,40 @@ So instead we use the macro below and test it against specific values. */
# endif
#endif
/* Attribute `alloc_size' was valid as of gcc 4.3. */
#ifndef ATTRIBUTE_RESULT_SIZE_1
# if (GCC_VERSION >= 4003)
# define ATTRIBUTE_RESULT_SIZE_1 __attribute__ ((alloc_size (1)))
# else
# define ATTRIBUTE_RESULT_SIZE_1
#endif
#endif
#ifndef ATTRIBUTE_RESULT_SIZE_2
# if (GCC_VERSION >= 4003)
# define ATTRIBUTE_RESULT_SIZE_2 __attribute__ ((alloc_size (2)))
# else
# define ATTRIBUTE_RESULT_SIZE_2
#endif
#endif
#ifndef ATTRIBUTE_RESULT_SIZE_1_2
# if (GCC_VERSION >= 4003)
# define ATTRIBUTE_RESULT_SIZE_1_2 __attribute__ ((alloc_size (1, 2)))
# else
# define ATTRIBUTE_RESULT_SIZE_1_2
#endif
#endif
/* Attribute `warn_unused_result' was valid as of gcc 3.3. */
#ifndef ATTRIBUTE_WARN_UNUSED_RESULT
# if GCC_VERSION >= 3003
# define ATTRIBUTE_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
# else
# define ATTRIBUTE_WARN_UNUSED_RESULT
# endif
#endif
/* We use __extension__ in some places to suppress -pedantic warnings
about GCC extensions. This feature didn't work properly before
gcc 2.8. */
@ -326,53 +319,12 @@ So instead we use the macro below and test it against specific values. */
#define ENUM_BITFIELD(TYPE) unsigned int
#endif
#if __cpp_constexpr >= 200704
#if defined(__cplusplus) && __cpp_constexpr >= 200704
#define CONSTEXPR constexpr
#else
#define CONSTEXPR
#endif
/* C++11 adds the ability to add "override" after an implementation of a
virtual function in a subclass, to:
(A) document that this is an override of a virtual function
(B) allow the compiler to issue a warning if it isn't (e.g. a mismatch
of the type signature).
Similarly, it allows us to add a "final" to indicate that no subclass
may subsequently override the vfunc.
Provide OVERRIDE and FINAL as macros, allowing us to get these benefits
when compiling with C++11 support, but without requiring C++11.
For gcc, use "-std=c++11" to enable C++11 support; gcc 6 onwards enables
this by default (actually GNU++14). */
#if defined __cplusplus
# if __cplusplus >= 201103
/* C++11 claims to be available: use it. Final/override were only
implemented in 4.7, though. */
# if GCC_VERSION < 4007
# define OVERRIDE
# define FINAL
# else
# define OVERRIDE override
# define FINAL final
# endif
# elif GCC_VERSION >= 4007
/* G++ 4.7 supports __final in C++98. */
# define OVERRIDE
# define FINAL __final
# else
/* No C++11 support; leave the macros empty. */
# define OVERRIDE
# define FINAL
# endif
#else
/* No C++11 support; leave the macros empty. */
# define OVERRIDE
# define FINAL
#endif
/* A macro to disable the copy constructor and assignment operator.
When building with C++11 and above, the methods are explicitly
deleted, causing a compile-time error if something tries to copy.
@ -389,7 +341,7 @@ So instead we use the macro below and test it against specific values. */
so that most attempts at copy are caught at compile-time. */
#if __cplusplus >= 201103
#if defined(__cplusplus) && __cplusplus >= 201103
#define DISABLE_COPY_AND_ASSIGN(TYPE) \
TYPE (const TYPE&) = delete; \
void operator= (const TYPE &) = delete

View file

@ -1,9 +1,9 @@
/* ###
* IP: GPL 3 Linking Permitted
* NOTE: See binutils/libiberty/COPYING.LIB; Used GPL 3 from this file's header
* IP: LGPL 2.1
* NOTE: See binutils/include/COPYING
*/
/* Internal demangler interface for g++ V3 ABI.
Copyright (C) 2003-2019 Free Software Foundation, Inc.
Copyright (C) 2003-2023 Free Software Foundation, Inc.
Written by Ian Lance Taylor <ian@wasabisystems.com>.
This file is part of the libiberty library, which is part of GCC.
@ -126,6 +126,10 @@ struct d_info
/* Non-zero if we are parsing the type operand of a conversion
operator, but not when in an expression. */
int is_conversion;
/* 1: using new unresolved-name grammar.
-1: using new unresolved-name grammar and saw an unresolved-name.
0: using old unresolved-name grammar. */
int unresolved_name_state;
/* If DMGL_NO_RECURSE_LIMIT is not active then this is set to
the current recursion level. */
unsigned int recursion_level;
@ -180,7 +184,7 @@ d_advance (struct d_info *di, int i)
extern const struct demangle_operator_info cplus_demangle_operators[];
#endif
#define D_BUILTIN_TYPE_COUNT (34)
#define D_BUILTIN_TYPE_COUNT (36)
CP_STATIC_IF_GLIBCPP_V3
const struct demangle_builtin_type_info

View file

@ -3,7 +3,7 @@
* NOTE: See binutils/include/COPYING
*/
/* Defs for interface to demanglers.
Copyright (C) 1992-2019 Free Software Foundation, Inc.
Copyright (C) 1992-2023 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License
@ -163,24 +163,11 @@ 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);
rust_demangle_callback (const char *mangled, int options,
demangle_callbackref callback, void *opaque);
/* 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);
@ -425,6 +412,9 @@ enum demangle_component_type
number which involves neither modifying the mangled string nor
allocating a new copy of the literal in memory. */
DEMANGLE_COMPONENT_LITERAL_NEG,
/* A vendor's builtin expression. The left subtree holds the
expression's name, and the right subtree is a argument list. */
DEMANGLE_COMPONENT_VENDOR_EXPR,
/* A libgcj compiled resource. The left subtree is the name of the
resource. */
DEMANGLE_COMPONENT_JAVA_RESOURCE,
@ -463,7 +453,25 @@ enum demangle_component_type
/* A cloned function. */
DEMANGLE_COMPONENT_CLONE,
DEMANGLE_COMPONENT_NOEXCEPT,
DEMANGLE_COMPONENT_THROW_SPEC
DEMANGLE_COMPONENT_THROW_SPEC,
DEMANGLE_COMPONENT_STRUCTURED_BINDING,
DEMANGLE_COMPONENT_MODULE_NAME,
DEMANGLE_COMPONENT_MODULE_PARTITION,
DEMANGLE_COMPONENT_MODULE_ENTITY,
DEMANGLE_COMPONENT_MODULE_INIT,
DEMANGLE_COMPONENT_TEMPLATE_HEAD,
DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM,
DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM,
DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM,
DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM,
/* A builtin type with argument. This holds the builtin type
information. */
DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE
};
/* Types which are only used internally. */
@ -485,6 +493,7 @@ struct demangle_component
Initialize to zero. Private to d_print_comp.
All other fields are final after initialization. */
int d_printing;
int d_counting;
union
{
@ -549,6 +558,15 @@ struct demangle_component
const struct demangle_builtin_type_info *type;
} s_builtin;
/* For DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE. */
struct
{
/* Builtin type. */
const struct demangle_builtin_type_info *type;
short arg;
char suffix;
} s_extended_builtin;
/* For DEMANGLE_COMPONENT_SUB_STD. */
struct
{

View file

@ -3,7 +3,7 @@
* NOTE: See binutils/include/COPYING3
*/
/* An abstract string datatype.
Copyright (C) 1998-2019 Free Software Foundation, Inc.
Copyright (C) 1998-2023 Free Software Foundation, Inc.
Contributed by Mark Mitchell (mark@markmitchell.com).
This file is part of GCC.

View file

@ -3,7 +3,7 @@
* NOTE: See binutils/include/COPYING3
*/
/* Declarations for getopt.
Copyright (C) 1989-2019 Free Software Foundation, Inc.
Copyright (C) 1989-2023 Free Software Foundation, Inc.
NOTE: The canonical source of this file is maintained with the GNU C Library.
Bugs can be reported to bug-glibc@gnu.org.

View file

@ -4,7 +4,7 @@
*/
/* Function declarations for libiberty.
Copyright (C) 1997-2019 Free Software Foundation, Inc.
Copyright (C) 1997-2023 Free Software Foundation, Inc.
Note - certain prototypes declared in this header file are for
functions whoes implementation copyright does not belong to the
@ -141,6 +141,10 @@ extern const char *unix_lbasename (const char *) ATTRIBUTE_RETURNS_NONNULL ATTRI
extern char *lrealpath (const char *);
/* Return true when FD file descriptor exists. */
extern int is_valid_fd (int fd);
/* Concatenate an arbitrary number of strings. You must pass NULL as
the last argument of this function, to terminate the list of
strings. Allocates memory using xmalloc. */
@ -314,30 +318,30 @@ extern void xmalloc_failed (size_t) ATTRIBUTE_NORETURN;
message to stderr (using the name set by xmalloc_set_program_name,
if any) and then call xexit. */
extern void *xmalloc (size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
extern void *xmalloc (size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_1 ATTRIBUTE_WARN_UNUSED_RESULT;
/* Reallocate memory without fail. This works like xmalloc. Note,
realloc type functions are not suitable for attribute malloc since
they may return the same address across multiple calls. */
extern void *xrealloc (void *, size_t) ATTRIBUTE_RETURNS_NONNULL;
extern void *xrealloc (void *, size_t) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_2 ATTRIBUTE_WARN_UNUSED_RESULT;
/* Allocate memory without fail and set it to zero. This works like
xmalloc. */
extern void *xcalloc (size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
extern void *xcalloc (size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_1_2 ATTRIBUTE_WARN_UNUSED_RESULT;
/* Copy a string into a memory buffer without fail. */
extern char *xstrdup (const char *) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
extern char *xstrdup (const char *) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_WARN_UNUSED_RESULT;
/* Copy at most N characters from string into a buffer without fail. */
extern char *xstrndup (const char *, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
extern char *xstrndup (const char *, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_WARN_UNUSED_RESULT;
/* Copy an existing memory buffer to a new memory buffer without fail. */
extern void *xmemdup (const void *, size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
extern void *xmemdup (const void *, size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_WARN_UNUSED_RESULT;
/* Physical memory routines. Return values are in BYTES. */
extern double physmem_total (void);
@ -641,6 +645,13 @@ extern int pexecute (const char *, char * const *, const char *,
extern int pwait (int, int *, int);
/* Like bsearch, but takes and passes on an argument like qsort_r. */
extern void *bsearch_r (const void *, const void *,
size_t, size_t,
int (*)(const void *, const void *, void *),
void *);
#if defined(HAVE_DECL_ASPRINTF) && !HAVE_DECL_ASPRINTF
/* Like sprintf but provides a pointer to malloc'd storage, which must
be freed by the caller. */
@ -653,7 +664,7 @@ extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2;
extern char *xasprintf (const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_PRINTF_1;
#if !HAVE_DECL_VASPRINTF
#if defined(HAVE_DECL_VASPRINTF) && !HAVE_DECL_VASPRINTF
/* Like vsprintf but provides a pointer to malloc'd storage, which
must be freed by the caller. */
@ -706,11 +717,6 @@ extern unsigned long long int strtoull (const char *nptr,
char **endptr, int base);
#endif
#if defined(HAVE_DECL_STRVERSCMP) && !HAVE_DECL_STRVERSCMP
/* Compare version strings. */
extern int strverscmp (const char *, const char *);
#endif
/* Set the title of a process */
extern void setproctitle (const char *name, ...);

View file

@ -4,7 +4,7 @@
*/
/* <ctype.h> replacement macros.
Copyright (C) 2000-2019 Free Software Foundation, Inc.
Copyright (C) 2000-2023 Free Software Foundation, Inc.
Contributed by Zack Weinberg <zackw@stanford.edu>.
This file is part of the libiberty library.

View file

@ -441,7 +441,7 @@
<P>
<U><B>Use Deprecated Demangler</B></U> -
By default, GCC symbols will be demangled using the most up-to-date demangler
that Ghidra contains (<B>version 2.33.1</B> as of this writing). Turning this
that Ghidra contains (<B>version 2.41</B> as of this writing). Turning this
option on will invoke the now deprecated version of the demangler (<B>version 2.24</B>).
</P>
<P>
@ -457,7 +457,7 @@
<UL>
<LI><CODE CLASS="path">
&lt;GHIDRA_INSTALL_DIR&gt;/GPL/DemanglerGnu/os/&lt;OS&gt;/
</CODE><CODE>demangler_gnu_v2_33_1</CODE></LI>
</CODE><CODE>demangler_gnu_v2_41</CODE></LI>
<LI><CODE CLASS="path">
&lt;GHIDRA_INSTALL_DIR&gt;/GPL/DemanglerGnu/os/&lt;OS&gt;/
</CODE><CODE>demangler_gnu_v2_24</CODE></LI>

View file

@ -34,14 +34,15 @@ public class GnuDemanglerOptions extends DemanglerOptions {
public static final String GNU_DEMANGLER_V2_24 = "demangler_gnu_v2_24";
/**
* Version 2.33.1 of the GNU demangler. This version supports less formats than older versions.
* Version 2.41 of the GNU demangler. This version supports less formats than
* {@link #GNU_DEMANGLER_V2_24}.
*/
public static final String GNU_DEMANGLER_V2_33_1 = "demangler_gnu_v2_33_1";
public static final String GNU_DEMANGLER_V2_41 = "demangler_gnu_v2_41";
/**
* The default version to use of the GNU demangler
*/
public static final String GNU_DEMANGLER_DEFAULT = GNU_DEMANGLER_V2_33_1;
public static final String GNU_DEMANGLER_DEFAULT = GNU_DEMANGLER_V2_41;
private final GnuDemanglerFormat format;
private final boolean isDeprecated;
@ -112,7 +113,7 @@ public class GnuDemanglerOptions extends DemanglerOptions {
* @return the name
*/
public String getDemanglerName() {
return isDeprecated ? GNU_DEMANGLER_V2_24 : GNU_DEMANGLER_V2_33_1;
return isDeprecated ? GNU_DEMANGLER_V2_24 : GNU_DEMANGLER_V2_41;
}
/**

View file

@ -320,6 +320,22 @@ public class GnuDemanglerParser {
*/
private static final Pattern LITERAL_NUMBER_PATTERN = Pattern.compile("-*\\d+[ul]{0,1}");
/**
* Pattern to identify a legacy rust string that contains its hash id suffix and capture the
* non-hash portion.
*
* Legacy mangled rust symbols:
* - start with _ZN
* - end withe E or E.
* - have a 16 digit hash that starts with 17h
*
* The demangled string has the leading '17' and trailing 'E|E.' removed.
*
* Sample: std::io::Read::read_to_end::hb85a0f6802e14499
*/
private static final Pattern RUST_LEGACY_SUFFIX_PATTERN =
Pattern.compile("(.*)::h[0-9a-f]{16}");
private String mangledSource;
private String demangledSource;
@ -333,6 +349,8 @@ public class GnuDemanglerParser {
*/
public DemangledObject parse(String mangled, String demangled) throws DemanglerParseException {
demangled = cleanupRustLegacySymbol(demangled);
this.mangledSource = mangled;
this.demangledSource = demangled;
@ -465,6 +483,14 @@ public class GnuDemanglerParser {
return function;
}
private String cleanupRustLegacySymbol(String demangled) {
Matcher m = RUST_LEGACY_SUFFIX_PATTERN.matcher(demangled);
if (m.matches()) {
return m.group(1);
}
return demangled;
}
private void setReturnType(String demangled, DemangledFunction function, String returnType) {
String updatedReturnType = returnType;

View file

@ -33,7 +33,7 @@ public class GnuDemanglerParserTest extends AbstractGenericTest {
@Before
public void setUp() throws Exception {
process = GnuDemanglerNativeProcess
.getDemanglerNativeProcess(GnuDemanglerOptions.GNU_DEMANGLER_V2_33_1);
.getDemanglerNativeProcess(GnuDemanglerOptions.GNU_DEMANGLER_V2_41);
parser = new GnuDemanglerParser();
}
@ -1025,12 +1025,11 @@ public class GnuDemanglerParserTest extends AbstractGenericTest {
String demangled = process.demangle(mangled);
/*
typeinfo for
std::__ndk1::__function::__func<
dummy::it::other::Namespace::function(float)::$_2::operator()(dummy::it::other::Namespace*) const::{lambda(dummy::it::other::Namespace*)#1},
std::__ndk1::allocator<{lambda(dummy::it::other::Namespace*)#1}>,
int (dummy::it::other::Namespace*)
>
typeinfo for
std::__ndk1::__function::__func<
dummy::it::other::Namespace::function(float)::$_2::operator()(dummy::it::other::Namespace*) const::{lambda(dummy::it::other::Namespace*)#1},
std::__ndk1::allocator<dummy::it::other::Namespace::function(float)::$_2::operator()(dummy::it::other::Namespace*) const::{lambda(dummy::it::other::Namespace*)#1}>,
int (dummy::it::other::Namespace*)>
'__func' has 3 template parameters, the operator and the allocator
@ -1042,7 +1041,7 @@ public class GnuDemanglerParserTest extends AbstractGenericTest {
String lambdaOperator =
dummyNs + "::function(float)::$_2::operator()(" + dummyNsP + ")const::" + lambda;
String lambdaAllocator = "std::__ndk1::allocator<" + lambda + ">";
String lambdaAllocator = "std::__ndk1::allocator<" + lambdaOperator + ">";
String thirdParam = "int(" + dummyNsP + ")";
String infoNs = "std::__ndk1::__function::";
@ -1092,7 +1091,7 @@ public class GnuDemanglerParserTest extends AbstractGenericTest {
String signature = object.getSignature(false);
assertEquals(
"undefined std::__array_traits<LayerDetails::RandomProviderT<LayerDetails::LayerBase::initRandom(long,long)const::{lambda(long&,unsigned_int)#1}>,4ul>::_S_ref(LayerDetails::LayerBase::initRandom(long,long) const::{lambda(long&, unsigned int)#1} const &[],unsigned long)",
"undefined std::__array_traits<LayerDetails::RandomProviderT<LayerDetails::LayerBase::initRandom(long,long)const::{lambda(long&,unsigned_int)#1}>,4ul>::_S_ref(LayerDetails::RandomProviderT<LayerDetails::LayerBase::initRandom(long, long) const::{lambda(long&, unsigned int)#1}> const &[],unsigned long)",
signature);
}
@ -1163,6 +1162,8 @@ public class GnuDemanglerParserTest extends AbstractGenericTest {
lambda contents - lambdas in templates and as a parameter
Note: the demangled string makes use of the 'auto' parameter keyword
bool (***
const* std::
__addressof<
@ -1196,7 +1197,7 @@ public class GnuDemanglerParserTest extends AbstractGenericTest {
String signature = object.getSignature(false);
assertEquals(
"undefined Bedrock::Threading::TLSDetail::DefaultConstructor<bool(**)(AssertHandlerContext_const&),void>::create()::{lambda(bool(***const*std::__addressof<Bedrock::Threading::TLSDetail::DefaultConstructor<bool(**)(AssertHandlerContext_const&),void>::create()::{lambda(bool(***const)(AssertHandlerContext_const&))#1}>(Bedrock::Threading::TLSDetail::DefaultConstructor<bool(**)(AssertHandlerContext_const&),void>::create()::{lambda(bool(***const&)(AssertHandlerContext_const&))#1}))(AssertHandlerContext_const&))#1}",
"undefined Bedrock::Threading::TLSDetail::DefaultConstructor<bool(**)(AssertHandlerContext_const&),void>::create()::{lambda(bool(***const*std::__addressof<Bedrock::Threading::TLSDetail::DefaultConstructor<bool(**)(AssertHandlerContext_const&),void>::create()::{lambda(bool(***const)(AssertHandlerContext_const&))#1}>(auto:1&))(AssertHandlerContext_const&))#1}",
signature);
}
@ -1997,7 +1998,7 @@ public class GnuDemanglerParserTest extends AbstractGenericTest {
String signature = object.getSignature(false);
assertEquals(
"int LayerDetails::RandomProviderT<LayerDetails::LayerBase::initRandom(long,long)const::{lambda(long&,unsigned_int)#1}>::operator()<int,2ul>(LayerDetails::RandomProviderT<LayerDetails::LayerBase::initRandom(long,long)const::{lambda(long&,unsigned_int)#1}>::operator() const &[])",
"int LayerDetails::RandomProviderT<LayerDetails::LayerBase::initRandom(long,long)const::{lambda(long&,unsigned_int)#1}>::operator()<int,2ul>(int const &[])",
signature);
}
@ -2140,6 +2141,34 @@ public class GnuDemanglerParserTest extends AbstractGenericTest {
new DemangledDataType("fake", "fake", DemangledDataType.LONG_LONG).getDataType(null));
}
@Test
public void testRustLegacyHashIsIgnored() throws Exception {
//
// Mangled: _ZN3std2io4Read11read_to_end17hb85a0f6802e14499E
//
// Demangled: std::io::Read::read_to_end::hb85a0f6802e14499
//
// Parsed: std::io::Read::read_to_end
//
// Legacy mangled rust symbols:
// - start with _ZN
// - end withe E or E.
// - have a 16 digit hash that starts with 17h
//
String mangled = "_ZN3std2io4Read11read_to_end17hb85a0f6802e14499E";
String demangled = process.demangle(mangled);
assertEquals(demangled, "std::io::Read::read_to_end::hb85a0f6802e14499");
DemangledObject object = parser.parse(mangled, demangled);
assertNotNull(object);
assertType(object, DemangledVariable.class);
String signature = object.getSignature(false);
assertEquals("std::io::Read::read_to_end", signature);
}
private void assertType(Demangled o, Class<?> c) {
assertTrue("Wrong demangled type. " + "\nExpected " + c + "; " + "\nfound " + o.getClass(),
c.isInstance(o));