summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Chris Mihelich <cmihelic@google.com>2024-06-27 09:12:55 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2024-06-27 09:13:53 -0700
commit4b9a55fd27a3edefcd12cf4a7873ee8ddcccc521 (patch)
treea416766de847e72005f162f3d631c704e298b388
parent0ccc51f9ddbb407d579f8158d5421fbf3eea0524 (diff)
Decode Rust Punycode when it's not too long.
PiperOrigin-RevId: 647340145 Change-Id: I4b0076595dbda1f81ffdc32adad2dc1e35cb9e04
-rw-r--r--absl/debugging/internal/demangle_rust.cc41
-rw-r--r--absl/debugging/internal/demangle_rust_test.cc2
2 files changed, 25 insertions, 18 deletions
diff --git a/absl/debugging/internal/demangle_rust.cc b/absl/debugging/internal/demangle_rust.cc
index 6b686ab3..4309bd84 100644
--- a/absl/debugging/internal/demangle_rust.cc
+++ b/absl/debugging/internal/demangle_rust.cc
@@ -21,6 +21,7 @@
#include "absl/base/attributes.h"
#include "absl/base/config.h"
+#include "absl/debugging/internal/decode_rust_punycode.h"
namespace absl {
ABSL_NAMESPACE_BEGIN
@@ -710,13 +711,19 @@ class RustSymbolParser {
int num_bytes = 0;
if (!ParseDecimalNumber(num_bytes)) return false;
(void)Eat('_'); // optional separator, needed if a digit follows
+ if (is_punycoded) {
+ DecodeRustPunycodeOptions options;
+ options.punycode_begin = &encoding_[pos_];
+ options.punycode_end = &encoding_[pos_] + num_bytes;
+ options.out_begin = out_;
+ options.out_end = out_end_;
+ out_ = DecodeRustPunycode(options);
+ if (out_ == nullptr) return false;
+ pos_ += static_cast<size_t>(num_bytes);
+ }
// Emit the beginnings of braced forms like {shim:vtable#0}.
- if (uppercase_namespace == '\0') {
- // Decoding of Punycode is not yet implemented. For now we emit
- // "{Punycode ...}" with the raw encoding inside.
- if (is_punycoded && !Emit("{Punycode ")) return false;
- } else {
+ if (uppercase_namespace != '\0') {
switch (uppercase_namespace) {
case 'C':
if (!Emit("{closure")) return false;
@@ -732,24 +739,24 @@ class RustSymbolParser {
}
// Emit the name itself.
- for (int i = 0; i < num_bytes; ++i) {
- const char c = Take();
- if (!IsIdentifierChar(c) &&
- // The spec gives toolchains the choice of Punycode or raw UTF-8 for
- // identifiers containing code points above 0x7f, so accept bytes with
- // the high bit set if this is not a u... encoding.
- (is_punycoded || (c & 0x80) == 0)) {
- return false;
+ if (!is_punycoded) {
+ for (int i = 0; i < num_bytes; ++i) {
+ const char c = Take();
+ if (!IsIdentifierChar(c) &&
+ // The spec gives toolchains the choice of Punycode or raw UTF-8 for
+ // identifiers containing code points above 0x7f, so accept bytes
+ // with the high bit set.
+ (c & 0x80) == 0) {
+ return false;
+ }
+ if (!EmitChar(c)) return false;
}
- if (!EmitChar(c)) return false;
}
- // Emit the endings of braced forms: "#42}" or "}".
+ // Emit the endings of braced forms, e.g., "#42}".
if (uppercase_namespace != '\0') {
if (!EmitChar('#')) return false;
if (!EmitDisambiguator(disambiguator)) return false;
- }
- if (uppercase_namespace != '\0' || is_punycoded) {
if (!EmitChar('}')) return false;
}
diff --git a/absl/debugging/internal/demangle_rust_test.cc b/absl/debugging/internal/demangle_rust_test.cc
index e6b68ae3..8ceb1fd7 100644
--- a/absl/debugging/internal/demangle_rust_test.cc
+++ b/absl/debugging/internal/demangle_rust_test.cc
@@ -117,7 +117,7 @@ TEST(DemangleRust, UnicodeIdentifiers) {
EXPECT_DEMANGLING("_RNvC7ice_cap17Eyjafjallajökull",
"ice_cap::Eyjafjallajökull");
EXPECT_DEMANGLING("_RNvC7ice_caps_u19Eyjafjallajkull_jtb",
- "ice_cap::{Punycode Eyjafjallajkull_jtb}");
+ "ice_cap::Eyjafjallajökull");
}
TEST(DemangleRust, FunctionInModule) {