Bug 1474871 - Link dump_syms against rustc-demangle. r=ted

The new version of breakpad imported in bug 1309172 doesn't demangle
rust symbols at all, contrary to before, where it tried to C++ demangle
them, which worked for many, although far from all. It however has
rust-demangle support as long as it's linked against a copy of the
rust-demangle-capi crate from https://github.com/luser/rust-demangle-capi/

This imports the code from the rust-demangle-capi crate but because of
some build system complications it's not taken as-is:
- it uses rusty-cheddar, which is deprecated, to generate a C header.
- rusty-cheddar depends on syntex_syntax, which now fails to build.
- rust-demangle-capi has crate-type staticlib, which can't be used
  as a dependency in a Cargo.toml. For that reason, we can't create
  a fake crate that depends on it to have it vendored.

Overall, it's only a few lines of rust, and the C header can be written
manually, so this is what we do here. The created crate is named in a way
specific to dump_syms.

The build system doesn't know how to figure out what system libraries
are required to link rust static libraries, although the rust compiler
has /some/ support to get the information, so we handle that manually.

--HG--
extra : rebase_source : 9f5a9bfe2148d3040e11c7121a88e85a7f2d5c53
This commit is contained in:
Mike Hommey 2018-07-12 10:23:12 +09:00
Родитель 4746abbb8a
Коммит 1ad733c5c4
18 изменённых файлов: 815 добавлений и 0 удалений

13
Cargo.lock сгенерированный
Просмотреть файл

@ -602,6 +602,13 @@ dependencies = [
"dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dump_syms_rust_demangle"
version = "0.1.0"
dependencies = [
"rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dwrote"
version = "0.4.2"
@ -1765,6 +1772,11 @@ name = "rust-ini"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc-demangle"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc-serialize"
version = "0.3.24"
@ -2701,6 +2713,7 @@ dependencies = [
"checksum ron 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "da06feaa07f69125ab9ddc769b11de29090122170b402547f64b86fe16ebc399"
"checksum runloop 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d79b4b604167921892e84afbbaad9d5ad74e091bf6c511d9dbfb0593f09fabd"
"checksum rust-ini 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8a654c5bda722c699be6b0fe4c0d90de218928da5b724c3e467fc48865c37263"
"checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649"
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
"checksum rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9743a7670d88d5d52950408ecdb7c71d8986251ab604d4689dd2ca25c9bca69"
"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f"

Просмотреть файл

@ -9,6 +9,7 @@ members = [
"js/rust",
"js/src/frontend/binsource", # Code generator.
"testing/geckodriver",
"toolkit/crashreporter/rust",
"toolkit/library/gtest/rust",
"toolkit/library/rust/",
]

1
third_party/rust/rustc-demangle/.cargo-checksum.json поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"files":{".travis.yml":"ff608da9edb53d86860db37ca32b87abb9423785544d763b0776eb654e1896c0","Cargo.toml":"8ceaf60013499028a9d0ec93e4b0c5cef763c1bc31dfa117e5ab6989b3ebda6a","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"7bb7dbc6378a31b5b925a0cff628a69006c77a4cdf3533f7507b7c8fbe3492b0","src/lib.rs":"2a6aaafcc0c6e398321b33187b47b3ee70ad35f44a22e9d4e1e1d24c5c223f3f","src/main.rs":"b84cf381d0ac832be4fb13f6bbec2fd0a0d0c12d1d68aaa84db7a6d76b1466cb"},"package":"76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649"}

20
third_party/rust/rustc-demangle/.travis.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,20 @@
language: rust
rust:
- stable
- beta
- nightly
sudo: false
before_script:
- pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
script:
- cargo build
- cargo test
- cargo doc
after_success:
- travis-cargo --only nightly doc-upload
notifications:
email:
on_success: never
env:
global:
secure: "VWE8DaftZLOj34USRPiq2jyFV1xWrPJP0lgMVWPGF52soyWV6L5FyMlbk00GvKH8y5h0urtuVFmInsLKz1E96eTLbD7Efa2snjSlOWMsTaWy3yq0NNuPraMWiXUkjDBxW3DTV47HN9thYA7TbrM35A0XGr7fXKl4CPT/UKEo2nNZPb2Y2XYaD6RID1sXMOvemOERGu7Lnq8dQ/PdGWWkpTV4FVsmq2wTyyZnzsEFsK0r/wqEPPHSl8r3NH6Rid9kCMw3h1d9s1eYSqzP09/fYfjy+X/6iGV9dL5WUQFL7xG7WjfZZG/e87lAxbXx+jXTlncdvXjm4BmIOYHeEMK9N5D3qE5C1gIIU+tk6ZuVKBLWMQJnAIDJKCsVdUhAXtWqbFK4djvNJUml1rIOF/CVUeynBVtacJ8nlxyh61XvDHbZGSBFBR2odEkhUaLzw/t/zqOIYd0u+mjtM4pX1nZ+ZFIMqVFsNTfVWWMDLyRVBNiAoHCdn/ug+mJJaYE3mZ2q1wPPqJVFffyaZVyg97zFO0y9v5ASHjb/7nYlIPoDGDPDUuoscuw5IYf+6CoCi7EgGqg5v7X1BsBXSYK+XfzOvrAqP31ixNGyVJEcBjAaJXwopx6KVIqWe71eHJDX68VeI0ncfCPDDQIReKA7MBhq5PzRDzr4iRHZAhNyuKgo+Fo="

22
third_party/rust/rustc-demangle/Cargo.toml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,22 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g. crates.io) dependencies
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
# editing this file be aware that the upstream Cargo.toml
# will likely look very different (and much more reasonable)
[package]
name = "rustc-demangle"
version = "0.1.8"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
description = "Rust compiler symbol demangling.\n"
homepage = "https://github.com/alexcrichton/rustc-demangle"
documentation = "https://docs.rs/rustc-demangle"
readme = "README.md"
license = "MIT/Apache-2.0"
repository = "https://github.com/alexcrichton/rustc-demangle"

201
third_party/rust/rustc-demangle/LICENSE-APACHE поставляемый Normal file
Просмотреть файл

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

25
third_party/rust/rustc-demangle/LICENSE-MIT поставляемый Normal file
Просмотреть файл

@ -0,0 +1,25 @@
Copyright (c) 2014 Alex Crichton
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.

24
third_party/rust/rustc-demangle/README.md поставляемый Normal file
Просмотреть файл

@ -0,0 +1,24 @@
# rustc-demangle
Symbol demangling for Rust
[![Build Status](https://travis-ci.org/alexcrichton/rustc-demangle.svg?branch=master)](https://travis-ci.org/alexcrichton/rustc-demangle)
[Documentation](https://docs.rs/rustc-demangle)
# License
This project is licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
http://opensource.org/licenses/MIT)
at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in rustc-demangle you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.

413
third_party/rust/rustc-demangle/src/lib.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,413 @@
//! Demangle Rust compiler symbol names.
//!
//! This crate provides a `demangle` function which will return a `Demangle`
//! sentinel value that can be used to learn about the demangled version of a
//! symbol name. The demangled representation will be the same as the original
//! if it doesn't look like a mangled symbol name.
//!
//! `Demangle` can be formatted with the `Display` trait. The alternate
//! modifier (`#`) can be used to format the symbol name without the
//! trailing hash value.
//!
//! # Examples
//!
//! ```
//! use rustc_demangle::demangle;
//!
//! assert_eq!(demangle("_ZN4testE").to_string(), "test");
//! assert_eq!(demangle("_ZN3foo3barE").to_string(), "foo::bar");
//! assert_eq!(demangle("foo").to_string(), "foo");
//! // With hash
//! assert_eq!(format!("{}", demangle("_ZN3foo17h05af221e174051e9E")), "foo::h05af221e174051e9");
//! // Without hash
//! assert_eq!(format!("{:#}", demangle("_ZN3foo17h05af221e174051e9E")), "foo");
//! ```
#![no_std]
#![deny(missing_docs)]
#[cfg(test)]
#[macro_use]
extern crate std;
use core::fmt;
/// Representation of a demangled symbol name.
pub struct Demangle<'a> {
original: &'a str,
inner: &'a str,
valid: bool,
/// The number of ::-separated elements in the original name.
elements: usize,
}
/// De-mangles a Rust symbol into a more readable version
///
/// All rust symbols by default are mangled as they contain characters that
/// cannot be represented in all object files. The mangling mechanism is similar
/// to C++'s, but Rust has a few specifics to handle items like lifetimes in
/// symbols.
///
/// This function will take a **mangled** symbol (typically acquired from a
/// `Symbol` which is in turn resolved from a `Frame`) and then writes the
/// de-mangled version into the given `writer`. If the symbol does not look like
/// a mangled symbol, it is still written to `writer`.
///
/// # Examples
///
/// ```
/// use rustc_demangle::demangle;
///
/// assert_eq!(demangle("_ZN4testE").to_string(), "test");
/// assert_eq!(demangle("_ZN3foo3barE").to_string(), "foo::bar");
/// assert_eq!(demangle("foo").to_string(), "foo");
/// ```
// All rust symbols are in theory lists of "::"-separated identifiers. Some
// assemblers, however, can't handle these characters in symbol names. To get
// around this, we use C++-style mangling. The mangling method is:
//
// 1. Prefix the symbol with "_ZN"
// 2. For each element of the path, emit the length plus the element
// 3. End the path with "E"
//
// For example, "_ZN4testE" => "test" and "_ZN3foo3barE" => "foo::bar".
//
// We're the ones printing our backtraces, so we can't rely on anything else to
// demangle our symbols. It's *much* nicer to look at demangled symbols, so
// this function is implemented to give us nice pretty output.
//
// Note that this demangler isn't quite as fancy as it could be. We have lots
// of other information in our symbols like hashes, version, type information,
// etc. Additionally, this doesn't handle glue symbols at all.
pub fn demangle(mut s: &str) -> Demangle {
// During ThinLTO LLVM may import and rename internal symbols, so strip out
// those endings first as they're on of the last manglings applied to symbol
// names.
let llvm = ".llvm.";
if let Some(i) = s.find(llvm) {
let candidate = &s[i + llvm.len()..];
let all_hex = candidate.chars().all(|c| {
match c {
'A' ... 'F' | '0' ... '9' | '@' => true,
_ => false,
}
});
if all_hex {
s = &s[..i];
}
}
// First validate the symbol. If it doesn't look like anything we're
// expecting, we just print it literally. Note that we must handle non-rust
// symbols because we could have any function in the backtrace.
let mut valid = true;
let mut inner = s;
if s.len() > 4 && s.starts_with("_ZN") && s.ends_with('E') {
inner = &s[3..s.len() - 1];
} else if s.len() > 3 && s.starts_with("ZN") && s.ends_with('E') {
// On Windows, dbghelp strips leading underscores, so we accept "ZN...E"
// form too.
inner = &s[2..s.len() - 1];
} else if s.len() > 5 && s.starts_with("__ZN") && s.ends_with('E') {
// On OSX, symbols are prefixed with an extra _
inner = &s[4..s.len() - 1];
} else {
valid = false;
}
// only work with ascii text
if inner.bytes().any(|c| c & 0x80 != 0) {
valid = false;
}
let mut elements = 0;
if valid {
let mut chars = inner.chars().peekable();
while valid {
let mut i = 0usize;
while let Some(&c) = chars.peek() {
if !c.is_digit(10) {
break
}
chars.next();
let next = i.checked_mul(10)
.and_then(|i| i.checked_add(c as usize - '0' as usize));
i = match next {
Some(i) => i,
None => {
valid = false;
break
}
};
}
if i == 0 {
valid = chars.next().is_none();
break;
} else if chars.by_ref().take(i).count() != i {
valid = false;
} else {
elements += 1;
}
}
}
Demangle {
inner: inner,
valid: valid,
elements: elements,
original: s,
}
}
/// Error returned from the `try_demangle` function below when demangling fails.
#[derive(Debug, Clone)]
pub struct TryDemangleError {
_priv: (),
}
/// The same as `demangle`, except return an `Err` if the string does not appear
/// to be a Rust symbol, rather than "demangling" the given string as a no-op.
///
/// ```
/// extern crate rustc_demangle;
///
/// let not_a_rust_symbol = "la la la";
///
/// // The `try_demangle` function will reject strings which are not Rust symbols.
/// assert!(rustc_demangle::try_demangle(not_a_rust_symbol).is_err());
///
/// // While `demangle` will just pass the non-symbol through as a no-op.
/// assert_eq!(rustc_demangle::demangle(not_a_rust_symbol).as_str(), not_a_rust_symbol);
/// ```
pub fn try_demangle(s: &str) -> Result<Demangle, TryDemangleError> {
let sym = demangle(s);
if sym.valid {
Ok(sym)
} else {
Err(TryDemangleError { _priv: () })
}
}
impl<'a> Demangle<'a> {
/// Returns the underlying string that's being demangled.
pub fn as_str(&self) -> &'a str {
self.original
}
}
// Rust hashes are hex digits with an `h` prepended.
fn is_rust_hash(s: &str) -> bool {
s.starts_with('h') && s[1..].chars().all(|c| c.is_digit(16))
}
impl<'a> fmt::Display for Demangle<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Alright, let's do this.
if !self.valid {
return f.write_str(self.inner);
}
let mut inner = self.inner;
for element in 0..self.elements {
let mut rest = inner;
while rest.chars().next().unwrap().is_digit(10) {
rest = &rest[1..];
}
let i: usize = inner[..(inner.len() - rest.len())].parse().unwrap();
inner = &rest[i..];
rest = &rest[..i];
// Skip printing the hash if alternate formatting
// was requested.
if f.alternate() && element+1 == self.elements && is_rust_hash(&rest) {
break;
}
if element != 0 {
try!(f.write_str("::"));
}
if rest.starts_with("_$") {
rest = &rest[1..];
}
while !rest.is_empty() {
if rest.starts_with('.') {
if let Some('.') = rest[1..].chars().next() {
try!(f.write_str("::"));
rest = &rest[2..];
} else {
try!(f.write_str("."));
rest = &rest[1..];
}
} else if rest.starts_with('$') {
macro_rules! demangle {
($($pat:expr => $demangled:expr),*) => ({
$(if rest.starts_with($pat) {
try!(f.write_str($demangled));
rest = &rest[$pat.len()..];
} else)*
{
try!(f.write_str(rest));
break;
}
})
}
// see src/librustc/back/link.rs for these mappings
demangle! {
"$SP$" => "@",
"$BP$" => "*",
"$RF$" => "&",
"$LT$" => "<",
"$GT$" => ">",
"$LP$" => "(",
"$RP$" => ")",
"$C$" => ",",
// in theory we can demangle any Unicode code point, but
// for simplicity we just catch the common ones.
"$u7e$" => "~",
"$u20$" => " ",
"$u27$" => "'",
"$u5b$" => "[",
"$u5d$" => "]",
"$u7b$" => "{",
"$u7d$" => "}",
"$u3b$" => ";",
"$u2b$" => "+",
"$u22$" => "\""
}
} else {
let idx = match rest.char_indices().find(|&(_, c)| c == '$' || c == '.') {
None => rest.len(),
Some((i, _)) => i,
};
try!(f.write_str(&rest[..idx]));
rest = &rest[idx..];
}
}
}
Ok(())
}
}
impl<'a> fmt::Debug for Demangle<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
#[cfg(test)]
mod tests {
use std::prelude::v1::*;
macro_rules! t {
($a:expr, $b:expr) => ({
assert_eq!(super::demangle($a).to_string(), $b);
})
}
macro_rules! t_nohash {
($a:expr, $b:expr) => ({
assert_eq!(format!("{:#}", super::demangle($a)), $b);
})
}
#[test]
fn demangle() {
t!("test", "test");
t!("_ZN4testE", "test");
t!("_ZN4test", "_ZN4test");
t!("_ZN4test1a2bcE", "test::a::bc");
}
#[test]
fn demangle_dollars() {
t!("_ZN4$RP$E", ")");
t!("_ZN8$RF$testE", "&test");
t!("_ZN8$BP$test4foobE", "*test::foob");
t!("_ZN9$u20$test4foobE", " test::foob");
t!("_ZN35Bar$LT$$u5b$u32$u3b$$u20$4$u5d$$GT$E", "Bar<[u32; 4]>");
}
#[test]
fn demangle_many_dollars() {
t!("_ZN13test$u20$test4foobE", "test test::foob");
t!("_ZN12test$BP$test4foobE", "test*test::foob");
}
#[test]
fn demangle_osx() {
t!("__ZN5alloc9allocator6Layout9for_value17h02a996811f781011E", "alloc::allocator::Layout::for_value::h02a996811f781011");
t!("__ZN38_$LT$core..option..Option$LT$T$GT$$GT$6unwrap18_MSG_FILE_LINE_COL17haf7cb8d5824ee659E", "<core::option::Option<T>>::unwrap::_MSG_FILE_LINE_COL::haf7cb8d5824ee659");
t!("__ZN4core5slice89_$LT$impl$u20$core..iter..traits..IntoIterator$u20$for$u20$$RF$$u27$a$u20$$u5b$T$u5d$$GT$9into_iter17h450e234d27262170E", "core::slice::<impl core::iter::traits::IntoIterator for &'a [T]>::into_iter::h450e234d27262170");
}
#[test]
fn demangle_windows() {
t!("ZN4testE", "test");
t!("ZN13test$u20$test4foobE", "test test::foob");
t!("ZN12test$RF$test4foobE", "test&test::foob");
}
#[test]
fn demangle_elements_beginning_with_underscore() {
t!("_ZN13_$LT$test$GT$E", "<test>");
t!("_ZN28_$u7b$$u7b$closure$u7d$$u7d$E", "{{closure}}");
t!("_ZN15__STATIC_FMTSTRE", "__STATIC_FMTSTR");
}
#[test]
fn demangle_trait_impls() {
t!("_ZN71_$LT$Test$u20$$u2b$$u20$$u27$static$u20$as$u20$foo..Bar$LT$Test$GT$$GT$3barE",
"<Test + 'static as foo::Bar<Test>>::bar");
}
#[test]
fn demangle_without_hash() {
let s = "_ZN3foo17h05af221e174051e9E";
t!(s, "foo::h05af221e174051e9");
t_nohash!(s, "foo");
}
#[test]
fn demangle_without_hash_edgecases() {
// One element, no hash.
t_nohash!("_ZN3fooE", "foo");
// Two elements, no hash.
t_nohash!("_ZN3foo3barE", "foo::bar");
// Longer-than-normal hash.
t_nohash!("_ZN3foo20h05af221e174051e9abcE", "foo");
// Shorter-than-normal hash.
t_nohash!("_ZN3foo5h05afE", "foo");
// Valid hash, but not at the end.
t_nohash!("_ZN17h05af221e174051e93fooE", "h05af221e174051e9::foo");
// Not a valid hash, missing the 'h'.
t_nohash!("_ZN3foo16ffaf221e174051e9E", "foo::ffaf221e174051e9");
// Not a valid hash, has a non-hex-digit.
t_nohash!("_ZN3foo17hg5af221e174051e9E", "foo::hg5af221e174051e9");
}
#[test]
fn demangle_thinlto() {
// One element, no hash.
t!("_ZN3fooE.llvm.9D1C9369", "foo");
t!("_ZN3fooE.llvm.9D1C9369@@16", "foo");
t_nohash!("_ZN9backtrace3foo17hbb467fcdaea5d79bE.llvm.A5310EB9", "backtrace::foo");
}
#[test]
fn dont_panic() {
super::demangle("_ZN2222222222222222222222EE").to_string();
super::demangle("_ZN5*70527e27.ll34csaғE").to_string();
super::demangle("_ZN5*70527a54.ll34_$b.1E").to_string();
super::demangle("\
_ZN5~saäb4e\n\
2734cOsbE\n\
5usage20h)3\0\0\0\0\0\0\07e2734cOsbE\
").to_string();
}
}

4
third_party/rust/rustc-demangle/src/main.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,4 @@
extern crate rustc_demangle;
fn main() {
}

Просмотреть файл

@ -52,6 +52,10 @@ if CONFIG['OS_ARCH'] != 'WINNT':
'-O2',
'-g',
]
HOST_DEFINES['HAVE_RUST_DEMANGLE'] = True
LOCAL_INCLUDES += [
'/toolkit/crashreporter/rust',
]
HostLibrary('host_breakpad_common_s')
if CONFIG['OS_TARGET'] == 'Android':

Просмотреть файл

@ -23,6 +23,20 @@ HOST_USE_LIBS += [
'host_breakpad_common_s',
'host_breakpad_dwarf_s',
]
# Order matters here, but HOST_USE_LIBS must be sorted.
HOST_USE_LIBS += [
'dump_syms_rust_demangle',
]
# Ideally, this should be derived from the output of rustc
# --print=native-static-libs or something like that.
HOST_OS_LIBS += [
'dl',
'pthread',
]
if CONFIG['HOST_OS_ARCH'] == 'Linux':
HOST_OS_LIBS += [
'rt',
]
LOCAL_INCLUDES += [
'../../../common/linux',

Просмотреть файл

@ -25,6 +25,20 @@ HOST_USE_LIBS += [
'host_breakpad_common_s',
'host_breakpad_dwarf_s',
]
# Order matters here, but HOST_USE_LIBS must be sorted.
HOST_USE_LIBS += [
'dump_syms_rust_demangle',
]
# Ideally, this should be derived from the output of rustc
# --print=native-static-libs or something like that.
HOST_OS_LIBS += [
'dl',
'pthread',
]
if CONFIG['HOST_OS_ARCH'] == 'Linux':
HOST_OS_LIBS += [
'rt',
]
LOCAL_INCLUDES += [
'../../../common/mac',

Просмотреть файл

@ -44,6 +44,7 @@ if CONFIG['MOZ_CRASHREPORTER']:
'google-breakpad/src/common/mac',
'google-breakpad/src/processor',
'google-breakpad/src/tools/mac/dump_syms',
'rust',
]
elif CONFIG['OS_ARCH'] == 'Linux':
@ -54,6 +55,7 @@ if CONFIG['MOZ_CRASHREPORTER']:
'google-breakpad/src/common/linux',
'google-breakpad/src/processor',
'google-breakpad/src/tools/linux/dump_syms',
'rust',
]

Просмотреть файл

@ -0,0 +1,16 @@
[package]
name = "dump_syms_rust_demangle"
version = "0.1.0"
[dependencies]
rustc-demangle = "0.1"
[lib]
path = "lib.rs"
crate-type = ["staticlib"]
test = false
doctest = false
bench = false
doc = false
plugin = false
harness = false

Просмотреть файл

@ -0,0 +1,25 @@
extern crate rustc_demangle;
use rustc_demangle::demangle;
use std::ffi::{CStr, CString};
use std::ptr;
/// Demangle `name` as a Rust symbol.
///
/// The resulting pointer should be freed with `free_demangled_name`.
#[no_mangle]
pub extern fn rust_demangle(name: *const std::os::raw::c_char) -> *mut std::os::raw::c_char {
let demangled = format!("{:#}", demangle(&unsafe { CStr::from_ptr(name) }.to_string_lossy()));
CString::new(demangled)
.map(|s| s.into_raw())
.unwrap_or(ptr::null_mut())
}
/// Free a string that was returned from `rust_demangle`.
#[no_mangle]
pub extern fn free_rust_demangled_name(demangled: *mut std::os::raw::c_char) {
if demangled != ptr::null_mut() {
// Just take ownership here.
unsafe { CString::from_raw(demangled) };
}
}

Просмотреть файл

@ -0,0 +1 @@
HostRustLibrary('dump_syms_rust_demangle')

Просмотреть файл

@ -0,0 +1,15 @@
#ifndef __RUST_DEMANGLE_H__
#define __RUST_DEMANGLE_H__
#ifdef __cplusplus
extern "C" {
#endif
extern char *rust_demangle(const char *);
extern void free_rust_demangled_name(char *);
#ifdef __cplusplus
}
#endif
#endif /* __RUST_DEMANGLE_H__ */