Skip to content

Add support for demangling C++ frames' symbols #31

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

Merged
merged 1 commit into from
Feb 27, 2017

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Feb 17, 2017

This adds a new optional (but on-by-default) dependency on the cpp_demangle crate. When this feature is enabled, if demangling a frame's symbol as a Rust symbol fails, then we attempt to demangle it as a C++ symbol.

r? @alexcrichton

I didn't add any tests because I am lazy. Don't hesitate to push back on this if you feel it needs testing.

@fitzgen
Copy link
Member Author

fitzgen commented Feb 18, 2017

Woops, ok force pushed a fix for building without the cpp_demangle feature. Should be all good now.

pub fn as_str(&self) -> Option<&'a str> {
self.demangled.as_ref().map(|s| s.as_str())
/// Returns the raw symbol name as a `str` if the symbols is valid utf-8.
pub fn as_str(&self) -> Option<Cow<'a, str>> {
Copy link
Member

Choose a reason for hiding this comment

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

Could this stay as it was but leave a TODO to fix this on the next major version change?

@alexcrichton
Copy link
Member

Looks great to me, thanks! Perhaps though this could be off by default to start off with? Also, could you add just a smoke test or two that it works?

@fitzgen
Copy link
Member Author

fitzgen commented Feb 24, 2017

Ran into some issues:

  • rustc_demangle::demangle does not return a result or option, so we can't know whether demangling suceeded or not, and therefore can't decide to only try and C++ demangle based on that information.

  • Some Rust symbols parse as C++ symbols, but format differently, so we can't try C++ first and then fall back to Rust symbols either.

Because of those two things, I don't think we can proceed. I think we need to fix the rustc_demangle API first.

@alexcrichton
Copy link
Member

@fitzgen it looks like there may be some println! statements in the published version of cpp_demangle?

@alexcrichton
Copy link
Member

Oh wait that's int he crate, carry on!

@alexcrichton
Copy link
Member

It looks like the tests may also be failing on Linux because there's some inlined functions in libstd?

@fitzgen
Copy link
Member Author

fitzgen commented Feb 26, 2017

Yeah I realized this wasn't ready and I need to rewrite parts of it to leverage rustc_demangle::try_demangle.

@fitzgen
Copy link
Member Author

fitzgen commented Feb 26, 2017

I'll ping you again once I've done that. Thanks!

@fitzgen
Copy link
Member Author

fitzgen commented Feb 26, 2017

@alexcrichton OK, assuming CI passes, I think this is ready.

build.rs Outdated
// > #[cfg(all(test, feature = "demangle_cpp"))]
//
// but it did not work...
#[cfg(feature = "demangle_cpp")]
Copy link
Member Author

Choose a reason for hiding this comment

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

This is unfortunate. Perhaps you know how we can only link the test C++ code when building for tests?

Copy link
Member

Choose a reason for hiding this comment

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

Ah yeah unfortunately this isn't possible right now, to work around it we'll have to move it to a whole separate crate which is cargo test'd.

@fitzgen fitzgen force-pushed the cpp_demangle branch 3 times, most recently from 73decea to 63e76b3 Compare February 27, 2017 20:58
@fitzgen
Copy link
Member Author

fitzgen commented Feb 27, 2017

Ok, moved the C++ smoke test to a sub-crate. Hopefully this did not break CI...

This adds a new optional (but on-by-default) dependency on the `cpp_demangle`
crate. When this feature is enabled, if demangling a frame's symbol as a Rust
symbol fails, then we attempt to demangle it as a C++ symbol.
@alexcrichton alexcrichton merged commit a933fcf into rust-lang:master Feb 27, 2017
@alexcrichton
Copy link
Member

Thanks!

@fitzgen fitzgen deleted the cpp_demangle branch February 27, 2017 21:39
@fitzgen
Copy link
Member Author

fitzgen commented Feb 27, 2017

Thank you!

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.

2 participants