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

feat: Add an accessor for the mvid to the Metadata Reader #660

Draft
wants to merge 2 commits into
base: feat/clr-metadata
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions symbolic-ppdb/src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ impl<'data> PortablePdb<'data> {
self.pdb_stream.as_ref().map(|stream| stream.id())
}

/// Reads the Module Version Id (`mvid`) of the first (and by definition only) Module if it exists.
pub fn mvid(&self) -> Option<Uuid> {
let guid_idx = self.get_table_cell_u32(TableType::Module, 1, 3).ok()?;
self.get_guid(guid_idx).ok()
}

/// Reads the `(row, col)` cell in the given table as a `u32`.
///
/// This returns an error if the indices are out of bounds for the table
Expand Down
Binary file modified symbolic-ppdb/tests/fixtures/integration.dll
Binary file not shown.
Binary file modified symbolic-ppdb/tests/fixtures/integration.pdb
Binary file not shown.
25 changes: 19 additions & 6 deletions symbolic-ppdb/tests/test_caches.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use std::str::FromStr;

use symbolic_common::DebugId;
use symbolic_common::Language;
use symbolic_debuginfo::pe::PeObject;
use symbolic_ppdb::LineInfo;
use symbolic_ppdb::PortablePdb;
use symbolic_ppdb::PortablePdbCache;
Expand Down Expand Up @@ -99,22 +103,31 @@ fn test_matching_ids() {

let (guid, age) = pdb_id.split_at(16);
let age = u32::from_ne_bytes(age.try_into().unwrap());
let pdb_debug_id = symbolic_common::DebugId::from_guid_age(guid, age).unwrap();
let pdb_debug_id = DebugId::from_guid_age(guid, age).unwrap();

let pe_buf = std::fs::read("tests/fixtures/integration.dll").unwrap();
let pe = symbolic_debuginfo::pe::PeObject::parse(&pe_buf).unwrap();
let pe = PeObject::parse(&pe_buf).unwrap();
let pe_debug_id = pe.debug_id();

assert_eq!(pe_debug_id, pdb_debug_id);
assert_eq!(
pdb_debug_id,
DebugId::from_str("1d6929b4-468b-4db8-9389-9a12bd257e1b-ab8cf31e").unwrap()
);
}

#[test]
fn test_pe_metadata() {
fn test_pe_mvid() {
let pe_buf = std::fs::read("tests/fixtures/integration.dll").unwrap();
let pe = symbolic_debuginfo::pe::PeObject::parse(&pe_buf).unwrap();
let pe = PeObject::parse(&pe_buf).unwrap();

let clr_metadata_buf = pe.clr_metadata().unwrap();
let metadata = PortablePdb::parse(clr_metadata_buf);
let metadata = PortablePdb::parse(clr_metadata_buf).unwrap();

assert!(metadata.is_ok());
let mvid = metadata.mvid();

assert_eq!(
mvid,
Some(uuid::uuid!("7d4fc54f-cafa-45ba-a23f-60c8e128f3cf"))
)
}