Commit 16452e14 by Chris Mihelich Committed by Copybara-Service

Decoder for Rust-style Punycode encodings of bounded length.

PiperOrigin-RevId: 647093624
Change-Id: Ic76bfa4aa8fb616cb23095ce7bfa30c3812dcb21
parent 63d4b2fe
......@@ -125,6 +125,8 @@ set(ABSL_INTERNAL_DLL_FILES
"debugging/internal/address_is_readable.cc"
"debugging/internal/address_is_readable.h"
"debugging/internal/bounded_utf8_length_sequence.h"
"debugging/internal/decode_rust_punycode.cc"
"debugging/internal/decode_rust_punycode.h"
"debugging/internal/demangle.cc"
"debugging/internal/demangle.h"
"debugging/internal/demangle_rust.cc"
......
......@@ -220,12 +220,14 @@ cc_library(
cc_library(
name = "demangle_internal",
srcs = [
"internal/decode_rust_punycode.cc",
"internal/demangle.cc",
"internal/demangle_rust.cc",
"internal/utf8_for_code_point.cc",
],
hdrs = [
"internal/bounded_utf8_length_sequence.h",
"internal/decode_rust_punycode.h",
"internal/demangle.h",
"internal/demangle_rust.h",
"internal/utf8_for_code_point.h",
......@@ -240,6 +242,7 @@ cc_library(
"//absl/base",
"//absl/base:config",
"//absl/base:core_headers",
"//absl/base:nullability",
"//absl/numeric:bits",
],
)
......@@ -258,6 +261,19 @@ cc_test(
)
cc_test(
name = "decode_rust_punycode_test",
srcs = ["internal/decode_rust_punycode_test.cc"],
copts = ABSL_TEST_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":demangle_internal",
"//absl/base:config",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "demangle_rust_test",
srcs = ["internal/demangle_rust_test.cc"],
copts = ABSL_TEST_COPTS,
......
......@@ -196,10 +196,12 @@ absl_cc_library(
demangle_internal
HDRS
"internal/bounded_utf8_length_sequence.h"
"internal/decode_rust_punycode.h"
"internal/demangle.h"
"internal/demangle_rust.h"
"internal/utf8_for_code_point.h"
SRCS
"internal/decode_rust_punycode.cc"
"internal/demangle.cc"
"internal/demangle_rust.cc"
"internal/utf8_for_code_point.cc"
......@@ -209,6 +211,7 @@ absl_cc_library(
absl::base
absl::bits
absl::core_headers
absl::nullability
PUBLIC
)
......@@ -227,6 +230,19 @@ absl_cc_test(
absl_cc_test(
NAME
decode_rust_punycode_test
SRCS
"internal/decode_rust_punycode_test.cc"
COPTS
${ABSL_TEST_COPTS}
DEPS
absl::demangle_internal
absl::config
GTest::gmock_main
)
absl_cc_test(
NAME
demangle_rust_test
SRCS
"internal/demangle_rust_test.cc"
......
// Copyright 2024 The Abseil Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef ABSL_DEBUGGING_INTERNAL_DECODE_RUST_PUNYCODE_H_
#define ABSL_DEBUGGING_INTERNAL_DECODE_RUST_PUNYCODE_H_
#include "absl/base/config.h"
#include "absl/base/nullability.h"
namespace absl {
ABSL_NAMESPACE_BEGIN
namespace debugging_internal {
struct DecodeRustPunycodeOptions {
const char* punycode_begin;
const char* punycode_end;
char* out_begin;
char* out_end;
};
// Given Rust Punycode in `punycode_begin .. punycode_end`, writes the
// corresponding UTF-8 plaintext into `out_begin .. out_end`, followed by a NUL
// character, and returns a pointer to that final NUL on success. On failure
// returns a null pointer, and the contents of `out_begin .. out_end` are
// unspecified.
//
// Failure occurs in precisely these cases:
// - Any input byte does not match [0-9a-zA-Z_].
// - The first input byte is an underscore, but no other underscore appears in
// the input.
// - The delta sequence does not represent a valid sequence of code-point
// insertions.
// - The plaintext would contain more than 256 code points.
//
// DecodeRustPunycode is async-signal-safe with bounded runtime and a small
// stack footprint, making it suitable for use in demangling Rust symbol names
// from a signal handler.
absl::Nullable<char*> DecodeRustPunycode(DecodeRustPunycodeOptions options);
} // namespace debugging_internal
ABSL_NAMESPACE_END
} // namespace absl
#endif // ABSL_DEBUGGING_INTERNAL_DECODE_RUST_PUNYCODE_H_
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