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

Linux: Print demangled symbols on backtrace #312

Merged
merged 4 commits into from
Oct 10, 2022

Conversation

goeiecool9999
Copy link
Collaborator

@goeiecool9999 goeiecool9999 commented Sep 28, 2022

This PR does the following:
Crash backtraces go from looking like this:
image
To looking like this:
image

The PR also increases the amount of lines cemu tries to retrieve because I've encountered a situation where the backtrace was incomplete.

Caveats:

  • For a process to be able to get symbol information from linux's backtrace functions the linker flag -rdynamic needs to be enabled. This increases Release executable size by 4.4 MiB.
  • Symbols are exported implicitly.
  • I'm not sure the addr2line tool supports de-mangled symbol names so people using it may run into trouble. This could be a problem if a bug is hard to reproduce and all they have is a stacktrace, though AFAIK that tool requires a debug build to function anyway and I don't think it'll be common for people to find hard to reproduce bugs while using a debug build because I expect most people to play games using release builds. Of course they'll still have some indication of the general area where the crash happens.


std::string symbolName = traceLine.substr(parenthesesOpen+1,offsetPlus-parenthesesOpen-1);
int status = -1;
char* demangled = abi::__cxa_demangle(symbolName.c_str(), nullptr, nullptr, &status);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is GNU libstdc++ specific, shouldn't it be ifdefd? I believe macOS users use LLVM libc++

Copy link
Collaborator Author

@goeiecool9999 goeiecool9999 Sep 29, 2022

Choose a reason for hiding this comment

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

Clang implements the same function so it should be okay. GitHub CI does builds for MacOS and they seem to have passed so I don't expect any issues.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this still work when compiling with -stdlib=libc++?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried to compile with that option but a vcpkg library is compiled without it causing linker errors. I don't know how to change the compiler options for vcpkg dependencies.

Copy link
Collaborator Author

@goeiecool9999 goeiecool9999 Sep 29, 2022

Choose a reason for hiding this comment

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

I found out how to change the compiler option for vcpkg libraries but I can't use clang to compile them and my GCC installation is not compiled with -stdlib support. So I can't test this. However a bigger problem for this code on Mac OS is problably the format of the output of backtrace_symbols. Best case scenario if it's different the sanity checks will fail and it will just print the raw output.

@goeiecool9999 goeiecool9999 marked this pull request as draft September 29, 2022 10:45
@goeiecool9999
Copy link
Collaborator Author

-rdynamic breaks vulkan loading.

@goeiecool9999 goeiecool9999 marked this pull request as ready for review September 29, 2022 11:26
@Exzap
Copy link
Member

Exzap commented Oct 8, 2022

As discussed on Discord, we'd prefer a solution that would read the debug info from the ELF symbol table rather than force the export of every function. But since this would require using a more sophisticated back-trace library I think this PR is an acceptable intermediate solution.

The only request I have is that -rdynamic should not be emitted for Apple platforms since it is not necessary there.

@Exzap Exzap merged commit 431c5a1 into cemu-project:main Oct 10, 2022
@goeiecool9999 goeiecool9999 deleted the pretty-backtrace branch November 4, 2022 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants