-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Implement C++ symbol demangling on macOS #47486
Conversation
e43fe6b
to
e1b702d
Compare
I think this is a gcc header, so it could be available when building using Windows cross-compile/MSYS2/Cygwin (needs testing). Demangling when using MSVC should be different. |
Match function symbol names by a regular expression designed specifically for the stack trace pattern returned from backtrace_symbols() on macOS, and then try to demangle the symbol by abi::__cxa_demangle(). If demangling succeeds, then output the demangled symbol name, otherwise output the original raw symbol name. References: [1] https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/backtrace_symbols.3.html [2] https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.3/a01696.html
e1b702d
to
53f3a15
Compare
I'll try to implement symbol demangling on macOS, Linux and BSD first (in this and subsequent PRs), and then see if MinGW will also work. I don't have a x86 arch computer right now so I'm unable to code and test MSVC demangling. |
I tried to install Visual Studio 2019 on Windows 10 ARM VM but the debugger doesn't work. |
@@ -791,6 +793,34 @@ static constexpr int bt_cnt = 20; | |||
static void *bt[bt_cnt]; | |||
#endif | |||
|
|||
#if !defined(_WIN32) | |||
static void write_demangled_frame( std::ostream &out, const char *frame ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to hide this function for Android:
20:11:27 [arm64-v8a] Compile++ : main <= debug.cpp
20:11:27 /var/lib/jenkins/workspace/Cataclysm-Android/android/app/jni/src/../../../../src/debug.cpp:831:13: warning: unused function 'write_demangled_frame' [-Wunused-function]
20:11:27 static void write_demangled_frame( std::ostream &out, const char *frame )
20:11:27 ^
20:11:27 1 warning generated.
from: CleverRaven/Cataclysm-DDA#47486 Co-authored-by: Brett Dong <[email protected]>
from: CleverRaven/Cataclysm-DDA#47486 Co-authored-by: Brett Dong <[email protected]>
from: CleverRaven/Cataclysm-DDA#47486 Co-authored-by: Brett Dong <[email protected]>
* chore: unindent common messages was very confusing with `CMAKE_BUILD_TYPE` * fix(port): BSD macro in src/debug.cpp from: CleverRaven/Cataclysm-DDA#47440 Co-authored-by: Brett Dong <[email protected]> * fix(port): Implement C++ symbol demangling on macOS from: CleverRaven/Cataclysm-DDA#47486 Co-authored-by: Brett Dong <[email protected]> * refactor(port): Extract symbol demangling to a separate function from: CleverRaven/Cataclysm-DDA#47517 Co-authored-by: Brett Dong <[email protected]> * feat(port): Demangle symbol names on MinGW from: CleverRaven/Cataclysm-DDA#47517 Co-authored-by: Brett Dong <[email protected]> * feat(port): Implement C++ symbol demangling on Linux from: CleverRaven/Cataclysm-DDA#47621 Co-authored-by: Brett Dong <[email protected]> * feat(port): Implement C++ symbol demangling on FreeBSD and OpenBSD from: CleverRaven/Cataclysm-DDA#48152 Co-authored-by: Brett Dong <[email protected]> * fix(port): C++ symbol demangling on cross-compile MinGW from: CleverRaven/Cataclysm-DDA#48220 Co-authored-by: Brett Dong <[email protected]> * fix(port): memory leak in demangle() from: CleverRaven/Cataclysm-DDA#48230 Co-authored-by: Brett Dong <[email protected]> * feat(port): Backtrace on Android from: CleverRaven/Cataclysm-DDA#48371 Co-authored-by: Brett Dong <[email protected]> * chore(port): hide write_demangled_frame() for Android build from: CleverRaven/Cataclysm-DDA#48414 Co-authored-by: Brett Dong <[email protected]> * feat(port): demangle RTTI type names in debug messages from: CleverRaven/Cataclysm-DDA#52633 Co-authored-by: Brett Dong <[email protected]> * perf(port): optimize null stream in DebugLog from: CleverRaven/Cataclysm-DDA#55156 Co-authored-by: Brett Dong <[email protected]> * fix(port): reported version of newer Windows 10 releases from: CleverRaven/Cataclysm-DDA#55506 Co-authored-by: xuv <[email protected]> * feat(port): include build number in windows version report CleverRaven/Cataclysm-DDA#55646 Co-authored-by: xuv <[email protected]> * feat(port): get the actual static image base of modules from: CleverRaven/Cataclysm-DDA#55782 Co-authored-by: Qrox <[email protected]> * ci: fix version typo * feat(port): support libbacktrace on linux from: CleverRaven/Cataclysm-DDA#59020 Co-authored-by: John Bytheway <[email protected]> * build(cmake): support custom linker context: https://stackoverflow.com//questions/1867745/cmake-use-a-custom-linker#answer-66730019 * docs(cmake): linker, backtrace and libbacktrace --------- Co-authored-by: Brett Dong <[email protected]> Co-authored-by: xuv <[email protected]> Co-authored-by: Qrox <[email protected]> Co-authored-by: John Bytheway <[email protected]>
Summary
Infrastructure "Demangle C++ symbols in crash report on macOS"
Purpose of change
Try to implement C++ symbol demangling on macOS so that crash reports are easier to read.
Describe the solution
Extract symbol names from the output of
backtrace_symbols()
system function by regular expression and then useabi::__cxa_demangle
in<cxxabi.h>
to demangle C++ symbols. The pattern of the output frombacktrace_symbols()
differ across different systems, so in this PR I am only trying to implement the functionality on macOS.Describe the alternative you've considered
abi::__cxa_demangle
in<cxxabi.h>
, establish a pipe and invokec++filt
command in the host system.clang
symbols.Testing
Before:
After:
Additional context
The idea was raised in #46758.
Edit: This should work perfectly if the binary is built natively on the same system. I don't know whether this will work in Jenkins cross-compiled version.
Edit 2: Jenkins also uses clang with libc++ when cross-compiling to macOS so theoretically I guess it will work too.
Edit 3:
<cxxabi.h>
does not exist on Windows, so I moved it to!_WIN32
region.