tools/perf/util/demangle-rust-v0.c
Source file repositories/reference/linux-study-clean/tools/perf/util/demangle-rust-v0.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/demangle-rust-v0.c- Extension
.c- Size
- 60917 bytes
- Lines
- 2043
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdint.hstddef.hstring.hstdbool.hsys/param.hstdio.hdemangle-rust-v0.h
Detected Declarations
struct demangle_v0struct demangle_legacystruct parserstruct printerstruct identstruct buffunction unicode_iscontrolfunction unicode_isprintfunction unicode_isgraphemextendfunction str_isasciifunction try_parse_pathfunction rust_demangle_v0_demanglefunction rust_demangle_v0_display_demanglefunction code_to_utf8function utf8_next_charfunction validate_charfunction punycode_decodefunction display_identfunction try_parse_uintfunction dinibble2intfunction char_to_stringfunction nibbles_to_stringfunction basic_typefunction parser_push_depthfunction parser_pop_depthfunction parser_peekfunction parser_eatfunction parser_nextfunction parser_chfunction parser_hex_nibblesfunction parser_digit_10function parser_digit_62function parser_integer_62function parser_opt_integer_62function parser_disambiguatorfunction parser_namespacefunction parser_backreffunction parser_identfunction printer_eatfunction printer_pop_depthfunction printer_print_buffunction printer_print_strfunction printer_print_chfunction printer_print_u64function printer_print_identfunction printer_print_backreffunction printer_print_lifetime_from_indexfunction printer_in_binder
Annotated Snippet
struct demangle_v0 {
const char *mangled;
size_t mangled_len;
};
struct demangle_legacy {
const char *mangled;
size_t mangled_len;
size_t elements;
};
// private version of memrchr to avoid _GNU_SOURCE
static void *demangle_memrchr(const void *s, int c, size_t n) {
const uint8_t *s_ = s;
for (; n != 0; n--) {
if (s_[n-1] == c) {
return (void*)&s_[n-1];
}
}
return NULL;
}
static bool unicode_iscontrol(uint32_t ch) {
// this is *technically* a unicode table, but
// some unicode properties are simpler than you might think
return ch < 0x20 || (ch >= 0x7f && ch < 0xa0);
}
// "good enough" tables, the only consequence is that when printing
// *constant strings*, some characters are printed as `\u{abcd}` rather than themselves.
//
// I'm leaving these here to allow easily replacing them with actual
// tables if desired.
static bool unicode_isprint(uint32_t ch) {
if (ch < 0x20) {
return false;
}
if (ch < 0x7f) {
return true;
}
return false;
}
static bool unicode_isgraphemextend(uint32_t ch) {
(void)ch;
return false;
}
static bool str_isascii(const char *s, size_t s_len) {
for (size_t i = 0; i < s_len; i++) {
if (s[i] & 0x80) {
return false;
}
}
return true;
}
typedef enum {
PunycodeOk,
PunycodeError
} punycode_status;
struct parser {
// the parser assumes that `sym` has a safe "terminating byte". It might be NUL,
// but it might also be something else if a symbol is "truncated".
const char *sym;
size_t sym_len;
size_t next;
uint32_t depth;
};
struct printer {
demangle_status status; // if status == 0 parser is valid
struct parser parser;
char *out; // NULL for no output [in which case out_len is not decremented]
size_t out_len;
uint32_t bound_lifetime_depth;
bool alternate;
};
static NODISCARD overflow_status printer_print_path(struct printer *printer, bool in_value);
static NODISCARD overflow_status printer_print_type(struct printer *printer);
static NODISCARD overflow_status printer_print_const(struct printer *printer, bool in_value);
static NODISCARD demangle_status try_parse_path(struct parser *parser) {
struct printer printer = {
DemangleOk,
*parser,
Annotation
- Immediate include surface: `stdint.h`, `stddef.h`, `string.h`, `stdbool.h`, `sys/param.h`, `stdio.h`, `demangle-rust-v0.h`.
- Detected declarations: `struct demangle_v0`, `struct demangle_legacy`, `struct parser`, `struct printer`, `struct ident`, `struct buf`, `function unicode_iscontrol`, `function unicode_isprint`, `function unicode_isgraphemextend`, `function str_isascii`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.