Commit e1cb00db by Eduard-Mihai Burtescu Committed by Jeff Law

rust-demangle.c (looks_like_rust): Remove.

	* rust-demangle.c (looks_like_rust): Remove.
	(rust_is_mangled): Don't check escapes.
	(is_prefixed_hash): Allow 0-9a-f permutations.
	(rust_demangle_sym): Don't bail on unknown escapes.
	* testsuite/rust-demangle-expected: Update 'main::$99$' test.

From-SVN: r276539
parent e23390d2
2019-10-03 Eduard-Mihai Burtescu <eddyb@lyken.rs>
* rust-demangle.c (looks_like_rust): Remove.
(rust_is_mangled): Don't check escapes.
(is_prefixed_hash): Allow 0-9a-f permutations.
(rust_demangle_sym): Don't bail on unknown escapes.
* testsuite/rust-demangle-expected: Update 'main::$99$' test.
2019-09-03 Eduard-Mihai Burtescu <eddyb@lyken.rs> 2019-09-03 Eduard-Mihai Burtescu <eddyb@lyken.rs>
* rust-demangle.c (unescape): Remove. * rust-demangle.c (unescape): Remove.
......
...@@ -85,7 +85,6 @@ static const size_t hash_prefix_len = 3; ...@@ -85,7 +85,6 @@ static const size_t hash_prefix_len = 3;
static const size_t hash_len = 16; static const size_t hash_len = 16;
static int is_prefixed_hash (const char *start); static int is_prefixed_hash (const char *start);
static int looks_like_rust (const char *sym, size_t len);
static int parse_lower_hex_nibble (char nibble); static int parse_lower_hex_nibble (char nibble);
static char parse_legacy_escape (const char **in); static char parse_legacy_escape (const char **in);
...@@ -105,16 +104,13 @@ static char parse_legacy_escape (const char **in); ...@@ -105,16 +104,13 @@ static char parse_legacy_escape (const char **in);
negative (the rare Rust symbol is not demangled) so this sets negative (the rare Rust symbol is not demangled) so this sets
the balance in favor of false negatives. the balance in favor of false negatives.
3. There must be no characters other than a-zA-Z0-9 and _.:$ 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 int
rust_is_mangled (const char *sym) rust_is_mangled (const char *sym)
{ {
size_t len, len_without_hash; size_t len, len_without_hash;
const char *end;
if (!sym) if (!sym)
return 0; return 0;
...@@ -128,12 +124,22 @@ rust_is_mangled (const char *sym) ...@@ -128,12 +124,22 @@ rust_is_mangled (const char *sym)
if (!is_prefixed_hash (sym + len_without_hash)) if (!is_prefixed_hash (sym + len_without_hash))
return 0; return 0;
return looks_like_rust (sym, len_without_hash); end = sym + len_without_hash;
while (sym < end)
{
if (*sym == '$' || *sym == '.' || *sym == '_' || *sym == ':'
|| ISALNUM (*sym))
sym++;
else
return 0;
}
return 1;
} }
/* A hash is the prefix "::h" followed by 16 lowercase hex digits. The /* A hash is the prefix "::h" followed by 16 lowercase hex digits. The
hex digits must comprise between 5 and 15 (inclusive) distinct hex digits must contain at least 5 distinct digits. */
digits. */
static int static int
is_prefixed_hash (const char *str) is_prefixed_hash (const char *str)
...@@ -162,28 +168,7 @@ is_prefixed_hash (const char *str) ...@@ -162,28 +168,7 @@ is_prefixed_hash (const char *str)
if (seen[i]) if (seen[i])
count++; count++;
return count >= 5 && count <= 15; return count >= 5;
}
static int
looks_like_rust (const char *str, size_t len)
{
const char *end = str + len;
while (str < end)
{
if (*str == '$')
{
if (!parse_legacy_escape (&str))
return 0;
}
else if (*str == '.' || *str == '_' || *str == ':' || ISALNUM (*str))
str++;
else
return 0;
}
return 1;
} }
/* /*
...@@ -215,8 +200,9 @@ rust_demangle_sym (char *sym) ...@@ -215,8 +200,9 @@ rust_demangle_sym (char *sym)
if (unescaped) if (unescaped)
*out++ = unescaped; *out++ = unescaped;
else else
/* unexpected escape sequence, not looks_like_rust. */ /* unexpected escape sequence, skip the rest of this segment. */
goto fail; while (in < end && *in != ':')
*out++ = *in++;
} }
else if (*in == '_') else if (*in == '_')
{ {
...@@ -248,14 +234,14 @@ rust_demangle_sym (char *sym) ...@@ -248,14 +234,14 @@ rust_demangle_sym (char *sym)
else if (*in == ':' || ISALNUM (*in)) else if (*in == ':' || ISALNUM (*in))
*out++ = *in++; *out++ = *in++;
else else
/* unexpected character in symbol, not looks_like_rust. */ {
goto fail; /* unexpected character in symbol, not rust_is_mangled. */
*out++ = '?'; /* This is pretty lame, but it's hard to do better. */
*out = '\0';
return;
}
} }
goto done;
fail:
*out++ = '?'; /* This is pretty lame, but it's hard to do better. */
done:
*out = '\0'; *out = '\0';
} }
......
...@@ -41,7 +41,7 @@ main::main::he714a2e23ed7db2g ...@@ -41,7 +41,7 @@ main::main::he714a2e23ed7db2g
# $XX$ substitutions should not contain just numbers. # $XX$ substitutions should not contain just numbers.
--format=auto --format=auto
_ZN4main4$99$17he714a2e23ed7db23E _ZN4main4$99$17he714a2e23ed7db23E
main::$99$::he714a2e23ed7db23 main::$99$
# _ at start of path should be removed. # _ at start of path should be removed.
# ".." translates to "::" "$GT$" to ">" and "$LT$" to "<". # ".." translates to "::" "$GT$" to ">" and "$LT$" to "<".
--format=rust --format=rust
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment