Skip to content

fix(debuginfo): Detect mangled anonymous namespaces in PDB inlinees #261

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 2 commits into from
Sep 10, 2020
Merged
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
17 changes: 16 additions & 1 deletion debuginfo/src/pdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,15 @@ impl DebugSession for PdbDebugSession<'_> {
}
}

/// Checks whether the given name declares an anonymous namespace.
///
/// ID records specify the mangled format for anonymous namespaces: `?A0x<id>`, where `id` is a hex
/// identifier of the namespace. Demanglers usually resolve this as "anonymous namespace".
fn is_anonymous_namespace(name: &str) -> bool {
name.strip_prefix("?A0x")
.map_or(false, |rest| u32::from_str_radix(rest, 16).is_ok())
}

/// Formatter for function types.
///
/// This formatter currently only contains the minimum implementation requried to format inline
Expand Down Expand Up @@ -693,7 +702,13 @@ impl<'u, 'd> TypeFormatter<'u, 'd> {
write!(target, "\"")?;
}
Ok(pdb::IdData::String(data)) => {
write!(target, "{}", data.name.to_string())?;
let mut string = data.name.to_string();

if is_anonymous_namespace(&string) {
string = Cow::Borrowed("`anonymous namespace'");
}

write!(target, "{}", string)?;
}
Ok(pdb::IdData::UserDefinedTypeSource(_)) => {
// nothing to do.
Expand Down
26 changes: 26 additions & 0 deletions debuginfo/tests/test_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,29 @@ fn test_pdb_functions() -> Result<(), Error> {

Ok(())
}

#[test]
fn test_pdb_anonymous_namespace() -> Result<(), Error> {
// Regression test for ?A0x<hash> namespaces

let view = ByteView::open(fixture("windows/crash.pdb"))?;
let object = Object::parse(&view)?;

let session = object.debug_session()?;
let main_function = session
.functions()
.filter_map(|f| f.ok())
.find(|f| f.address == 0x2910)
.expect("main function at 0x2910");

let start_function = main_function
.inlinees
.iter()
.find(|f| f.address == 0x2a3d)
.expect("start function at 0x2a3d");

// was: "?A0xc3a0617d::start"
assert_eq!(start_function.name, "`anonymous namespace'::start");

Ok(())
}
10 changes: 8 additions & 2 deletions py/symbolic/debuginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ def make_cficache(self):
)

def __repr__(self):
return "<Object %s %r>" % (self.debug_id, self.arch,)
return "<Object %s %r>" % (
self.debug_id,
self.arch,
)


class ObjectRef(object):
Expand All @@ -165,7 +168,10 @@ def __init__(self, data):
self.name = self.code_file

def __repr__(self):
return "<ObjectRef %s %r>" % (self.debug_id, self.arch,)
return "<ObjectRef %s %r>" % (
self.debug_id,
self.arch,
)


class ObjectLookup(object):
Expand Down
5 changes: 4 additions & 1 deletion py/symbolic/sourcemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ def __ne__(self, other):
return not self.__eq__(other)

def __repr__(self):
return "<SourceMapTokenMatch %s:%d>" % (self.src, self.src_line,)
return "<SourceMapTokenMatch %s:%d>" % (
self.src,
self.src_line,
)


class SourceView(RustObject):
Expand Down
6 changes: 5 additions & 1 deletion py/symbolic/symcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ def rel_path(self):
return strip_common_path_prefix(self.abs_path, self.comp_dir)

def __str__(self):
return "%s:%s (%s)" % (self.function_name, self.line, self.rel_path,)
return "%s:%s (%s)" % (
self.function_name,
self.line,
self.rel_path,
)

def __repr__(self):
return "LineInfo(%s)" % (
Expand Down