Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding GNU C++ demangler #1834

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@
[submodule "third_party/uriparser"]
path = third_party/uriparser
url = https://github.com/uriparser/uriparser.git
[submodule "third_party/PEGTL"]
path = third_party/PEGTL
url = https://github.com/taocpp/PEGTL.git
1 change: 1 addition & 0 deletions LICENSES.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ find a link to the vendored version itself.
- [nanosvg](https://github.com/memononen/nanosvg) ([vendored](https://github.com/grumpycoders/nanosvg))
- [nanovg](https://github.com/memononen/nanovg) ([vendored](https://github.com/grumpycoders/nanovg))
- [noto](https://fonts.google.com/noto) ([vendored](https://github.com/grumpycoders/pcsx-redux/tree/main/third_party/noto))
- [PEGTL](https://github.com/taocpp/PEGTL)
- [pprint.lua](https://github.com/jagt/pprint.lua) ([vendored](https://github.com/grumpycoders/pcsx-redux/tree/main/third_party/pprint.lua))
- [stb](https://github.com/nothings/stb)
- [tracy](https://github.com/wolfpld/tracy)
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ CPPFLAGS += -Ithird_party/luajit/src
CPPFLAGS += -Ithird_party/luv/src
CPPFLAGS += -Ithird_party/luv/deps/lua-compat-5.3/c-api
CPPFLAGS += -Ithird_party/md4c/src
CPPFLAGS += -Ithird_party/PEGTL/include
CPPFLAGS += -Ithird_party/ucl -Ithird_party/ucl/include
CPPFLAGS += -Ithird_party/uriparser/include
CPPFLAGS += -Ithird_party/zep/extensions
Expand Down
17 changes: 10 additions & 7 deletions compile_flags.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
-std=c++2a
-std=c++2b
-fexceptions
-I.
-Isrc
-Ithird_party
-Ithird_party/ELFIO
-Ithird_party/fmt/include/
-Ithird_party/gl3w
-Ithird_party/googletest/googletest/include
-Ithird_party/imgui
-Ithird_party/imgui/backends
-Ithird_party/imgui/examples
-Ithird_party/imgui/misc/cpp
-Ithird_party/http-parser
-Ithird_party/libelfin
-Ithird_party/luajit/src
-Ithird_party/luv/src
-Ithird_party/luv/deps/lua-compat-5.3/c-api
-Ithird_party/ucl
-Ithird_party/ucl/include
-Ithird_party/libuv/include
-Ithird_party/zlib
-Ithird_party/md4c/src
-Ithird_party/PEGTL/include
-Ithird_party/ucl -Ithird_party/ucl/include
-Ithird_party/uriparser/include
-Ithird_party/zep/extensions
-Ithird_party/zep/include
-Ithird_party/xbyak/xbyak
-DLUAJIT_ENABLE_LUA52COMPAT
-DIMGUI_IMPL_OPENGL_LOADER_GL3W
-DIMGUI_ENABLE_FREETYPE
-DLUAJIT_ENABLE_LUA52COMPAT
-DZEP_FEATURE_CPP_FILE_SYSTEM
-DNVG_NO_STB
-DPB_STATIC_API
1,908 changes: 1,908 additions & 0 deletions src/support/gnu-c++-demangler.cc

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions src/support/gnu-c++-demangler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*

MIT License

Copyright (c) 2025 PCSX-Redux authors
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update the copyright year.

The copyright year is set to 2025, which is in the future. Please update it to the current year (2024).

-Copyright (c) 2025 PCSX-Redux authors
+Copyright (c) 2024 PCSX-Redux authors
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Copyright (c) 2025 PCSX-Redux authors
Copyright (c) 2024 PCSX-Redux authors


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

#pragma once

#include <string>
#include <string_view>

namespace PCSX {

namespace GNUDemangler {

bool internalCheck();
bool trace(std::string_view mangled);
void printDot(std::string_view mangled);
std::string demangle(std::string_view mangled);

} // namespace GNUDemangler

} // namespace PCSX
72 changes: 72 additions & 0 deletions tests/support/gnu-c++-demangler.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/***************************************************************************
* Copyright (C) 2025 PCSX-Redux authors *
* *
* 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; either version 2 of the License, or *
* (at your option) any later version. *
* *
* 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 for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
***************************************************************************/

#include "gtest/gtest.h"
#include "support/gnu-c++-demangler.h"

TEST(GNUDemangler, _Z1fv) { EXPECT_EQ(PCSX::GNUDemangler::demangle("_Z1fv"), "f(void)"); }
TEST(GNUDemangler, _Z1fi) { EXPECT_EQ(PCSX::GNUDemangler::demangle("_Z1fi"), "f(int)"); }
TEST(GNUDemangler, _Z3foo3bar) { EXPECT_EQ(PCSX::GNUDemangler::demangle("_Z3foo3bar"), "foo(bar)"); }
TEST(GNUDemangler, _Zrm1XS_) { EXPECT_EQ(PCSX::GNUDemangler::demangle("_Zrm1XS_"), "operator%(X, X)"); }
TEST(GNUDemangler, _ZplR1XS0_) { EXPECT_EQ(PCSX::GNUDemangler::demangle("_ZplR1XS0_"), "operator+(X&, X&)"); }
TEST(GNUDemangler, _ZlsRK1XS1_) {
EXPECT_EQ(PCSX::GNUDemangler::demangle("_ZlsRK1XS1_"), "operator<< (X const&, X const&)");
}
TEST(GNUDemangler, _ZN3FooIA4_iE3barE) {
EXPECT_EQ(PCSX::GNUDemangler::demangle("_ZN3FooIA4_iE3barE"), "Foo<int[4]>::bar");
}
TEST(GNUDemangler, _Z1fIiEvi) { EXPECT_EQ(PCSX::GNUDemangler::demangle("_Z1fIiEvi"), "void f<int>(int)"); }
TEST(GNUDemangler, _Z5firstI3DuoEvS0_) {
EXPECT_EQ(PCSX::GNUDemangler::demangle("_Z5firstI3DuoEvS0_"), "void first<Duo>(Duo)");
}
TEST(GNUDemangler, _Z5firstI3DuoEvT_) {
EXPECT_EQ(PCSX::GNUDemangler::demangle("_Z5firstI3DuoEvT_"), "void first<Duo>(Duo)");
}
TEST(GNUDemangler, _Z3fooIiPFidEiEvv) {
EXPECT_EQ(PCSX::GNUDemangler::demangle("_Z3fooIiPFidEiEvv"), "void foo<int,int(*)(double),int>()");
}
TEST(GNUDemangler, _ZN1N1fE) { EXPECT_EQ(PCSX::GNUDemangler::demangle("_ZN1N1fE"), "N::f"); }
TEST(GNUDemangler, _ZN6System5Sound4beepEv) {
EXPECT_EQ(PCSX::GNUDemangler::demangle("_ZN6System5Sound4beepEv"), "System::Sound::beep()");
}
TEST(GNUDemangler, _ZN5Arena5levelE) { EXPECT_EQ(PCSX::GNUDemangler::demangle("_ZN5Arena5levelE"), "Arena::level"); }
TEST(GNUDemangler, _ZN5StackIiiE5levelE) {
EXPECT_EQ(PCSX::GNUDemangler::demangle("_ZN5StackIiiE5levelE"), "Stack<int, int>::level");
}
TEST(GNUDemangler, _Z1fI1XEvPVN1AIT_E1TE) {
EXPECT_EQ(PCSX::GNUDemangler::demangle("_Z1fI1XEvPVN1AIT_E1TE"), "void f<X>(A<X>::T volatile*)");
}
TEST(GNUDemangler, _ZngILi42EEvN1AIXplT_Li2EEE1TE) {
EXPECT_EQ(PCSX::GNUDemangler::demangle("_ZngILi42EEvN1AIXplT_Li2EEE1TE"), "void operator-<42>(A<(42)+(2)>::T)");
}
TEST(GNUDemangler, _Z4makeI7FactoryiET_IT0_Ev) {
EXPECT_EQ(PCSX::GNUDemangler::demangle("_Z4makeI7FactoryiET_IT0_Ev"), "Factory<int> make<Factory, int>()");
}
TEST(GNUDemangler, _Z3foo5Hello5WorldS0_S_) {
EXPECT_EQ(PCSX::GNUDemangler::demangle("_Z3foo5Hello5WorldS0_S_"), "foo(Hello, World, World, Hello)");
}
TEST(GNUDemangler, _Z3fooPM2ABi) { EXPECT_EQ(PCSX::GNUDemangler::demangle("_Z3fooPM2ABi"), "foo(int AB::**)"); }
TEST(GNUDemangler, _ZlsRSoRKSs) {
EXPECT_EQ(PCSX::GNUDemangler::demangle("_ZlsRSoRKSs"), "operator<<(std::ostream&,std::string const&)");
}
TEST(GNUDemangler, _ZTI7a_class) { EXPECT_EQ(PCSX::GNUDemangler::demangle("_ZTI7a_class"), "typeid(class a_class)"); }
TEST(GNUDemangler, _ZN4PCSX10SystemImplC2ERKNS_9ArgumentsE) {
EXPECT_EQ(PCSX::GNUDemangler::demangle("_ZN4PCSX10SystemImplC2ERKNS_9ArgumentsE"),
"PCSX::SystemImpl::SystemImpl(PCSX::Arguments const&)");
}
1 change: 1 addition & 0 deletions third_party/PEGTL
Submodule PEGTL added at be5273
2 changes: 1 addition & 1 deletion vsprojects/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ItemDefinitionGroup>
<ClCompile>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalIncludeDirectories>$(SolutionDir)..\;$(SolutionDir)..\src;$(SolutionDir)..\third_party;$(SolutionDir)..\third_party\curl\include;$(SolutionDir)..\third_party\ConcurrentQueue;$(SolutionDir)..\third_party\capstone\include\capstone;$(SolutionDir)..\third_party\googletest\googletest\include;$(SolutionDir)..\third_party\ELFIO;$(SolutionDir)..\third_party\expected\include;$(SolutionDir)..\third_party\fmt\include;$(SolutionDir)..\third_party\freetype\include;$(SolutionDir)..\third_party\gl3w;$(SolutionDir)..\third_party\imgui;$(SolutionDir)..\third_party\imgui\backends;$(SolutionDir)..\third_party\imgui\misc\cpp;$(SolutionDir)..\third_party\libuv\include;$(SolutionDir)..\third_party\libuv\src;$(SolutionDir)..\third_party\md4c\src;$(SolutionDir)..\third_party\SDL\include;$(SolutionDir)..\third_party\uriparser\include;$(SolutionDir)..\third_party\uvw\src;$(SolutionDir)..\third_party\xbyak\xbyak;$(SolutionDir)..\third_party\zep\extensions;$(SolutionDir)..\third_party\zep\include;$(SolutionDir)..\third_party\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)..\;$(SolutionDir)..\src;$(SolutionDir)..\third_party;$(SolutionDir)..\third_party\curl\include;$(SolutionDir)..\third_party\ConcurrentQueue;$(SolutionDir)..\third_party\capstone\include\capstone;$(SolutionDir)..\third_party\googletest\googletest\include;$(SolutionDir)..\third_party\ELFIO;$(SolutionDir)..\third_party\expected\include;$(SolutionDir)..\third_party\fmt\include;$(SolutionDir)..\third_party\freetype\include;$(SolutionDir)..\third_party\gl3w;$(SolutionDir)..\third_party\imgui;$(SolutionDir)..\third_party\imgui\backends;$(SolutionDir)..\third_party\imgui\misc\cpp;$(SolutionDir)..\third_party\libuv\include;$(SolutionDir)..\third_party\libuv\src;$(SolutionDir)..\third_party\md4c\src;$(SolutionDir)..\third_party\PEGTL\include;$(SolutionDir)..\third_party\SDL\include;$(SolutionDir)..\third_party\uriparser\include;$(SolutionDir)..\third_party\uvw\src;$(SolutionDir)..\third_party\xbyak\xbyak;$(SolutionDir)..\third_party\zep\extensions;$(SolutionDir)..\third_party\zep\include;$(SolutionDir)..\third_party\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpplatest</LanguageStandard>
<PreprocessorDefinitions>IMGUI_ENABLE_FREETYPE;IMGUI_DISABLE_OBSOLETE_KEYIO;HAVE_STDINT_H;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_GNU_SOURCE;NOMINMAX;WIN32;_WINDOWS;_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING;ZEP_FEATURE_CPP_FILE_SYSTEM;CURL_STATICLIB;BUILDING_LIBCURL;USE_WIN32_IDN;WANT_IDN_PROTOTYPES;USE_IPV6;USE_WINDOWS_SSPI;USE_SCHANNEL;PB_STATIC_API;WINVER=0x0602;_WIN32_WINNT=0x0602;URI_STATIC_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BufferSecurityCheck>false</BufferSecurityCheck>
Expand Down
Loading
Loading