mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-08-31 17:55:23 +02:00
C++ homebrew has an unreadable symbol table - everything is _ZN10PxRenderer7DrawImmE... - which makes the disassembly and symbol list nearly useless. Add an Itanium C++ ABI demangler and run ELF symbols through it on load, in both ElfReader::LoadSymbols (unstripped EXECs, which is what a CMake pspdev EBOOT actually contains) and the companion-ELF path. The demangling standard is called Itanium for historical reasons - it was defined for Itanium but ended up being almost universally applicable. Written from scratch rather than using __cxa_demangle, which doesn't exist on MSVC/UWP, or vendoring LLVM's demangler, whose license doesn't fit. Anything unrecognized (arbitrary constant expressions, decltype) aborts the parse and the caller gets the original mangled name back, so a caller never sees a half-parsed result. Recursion is depth-capped since the input comes from a file we didn't write. Checked against c++filt as an oracle: of 1089 mangled symbols in a real C++ homebrew EBOOT, one differs; of 55189 from libstdc++/libLLVM/cc1plus, 22 differ and 413 are declined. Fuzzed with 220k mutated and random inputs under ASan/UBSan. Also adds a right-click menu to the ImDebugger symbol list. Note that SymbolMap stores names in char[128], so the longest STL names get truncated in the UI. Still far more readable than the mangled form. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X3DbkJ8ShYiXU7q5Tv1LZu
36 lines
1.5 KiB
C++
36 lines
1.5 KiB
C++
// Copyright (c) 2026- PPSSPP Project.
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
// Official git repository and contact information can be found at
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
// Demangler for Itanium C++ ABI symbol names ("_Z..."), which is what GCC and Clang
|
|
// produce - and thus what the PSP toolchain produces. Handy for homebrew built from C++,
|
|
// where the ELF symbol table is otherwise unreadable.
|
|
//
|
|
// Handles the constructs that show up in practice, and simply fails on the rest (complex
|
|
// template expressions, mostly) rather than emitting something wrong.
|
|
|
|
// Returns false and leaves *out alone if this isn't a mangled name, or we can't parse it.
|
|
bool DemangleItanium(std::string_view mangled, std::string *out);
|
|
|
|
// Convenience wrapper: returns the demangled name, or a copy of the input if it isn't
|
|
// something we can demangle.
|
|
std::string DemangleSymbolName(std::string_view name);
|