Skip to content

Conversation

@bjorn3
Copy link
Contributor

@bjorn3 bjorn3 commented Aug 31, 2023

These are all necessary to demangle symbols for rustc profiles.

Comment on lines 823 to 847
case 'b': {
uint64_t value = 0;
size_t hex_len = 0;
while (!eat(rdm, '_')) {
value <<= 4;

char c = next(rdm);
if (IS_DIGIT(c))
value |= c - '0';
else if (c >= 'a' && c <= 'f')
value |= 10 + (c - 'a');
else
ERROR_AND(return );
hex_len++;
}

if (value == 0) {
PRINT("false");
} else if (value == 1) {
PRINT("true");
} else {
ERROR_AND(return );
}
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we require b0_ and b1_? Oh, no, we don't, that got changed with try_parse_uint.
And demangle_const_uint doesn't have a try_parse_uint because of how it handles hex fallback, ugh.

rust-demangle.c Outdated

PRINT("\"");

// FIXME(bjorn3) actually decode UTF-8 strings into individual characters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's kind of funny is that 1. try_parse_str_chars in the Rust version barely and 2. there's a UTF-8 encoder somewhere in this file, for punycode, so I feel like combining the two (the encoder giving you the mapping of the bits to bytes) might not even be that hard. And we have test data, so I can golf it if you want.

* this arguably also includes `p` as an *untyped* placeholder constant
* **(UNPORTED)** [`str` and structural constants](https://github.com/rust-lang/rfcs/pull/3161)
(only usable in `const` generics on unstable Rust)
* symbol prefix flexibility (`__R` and `R`, instead of `_R`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one has been allowed since the first commit of rustc-demangle adding the v0 demangler.

@eddyb
Copy link
Contributor

eddyb commented Sep 26, 2023

Added UTF-8 decoding, but no "is printable" heuristic, a lot of that data is somewhat uniform but being 100% exact is very annoying (and would require trying various "compressed lookup" tricks that I don't have time for).

Thanks for doing all this work, and sorry I didn't see it sooner! (and that I didn't finish this port myself...)

@eddyb eddyb merged commit 4b3529e into LykenSol:main Sep 26, 2023
@bjorn3 bjorn3 deleted the fixes branch September 26, 2023 16:44
gnomesysadmins pushed a commit to GNOME/sysprof that referenced this pull request Sep 26, 2023
LykenSol/rust-demangle.c#2 has been merged.
The main change from the PR as of me vendoring it is new support
for decoding and escaping UTF-8 string literals. In addition
clang-format was used for formatting the file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants