Skip to content

Commit

Permalink
Use pdb2 crate.
Browse files Browse the repository at this point in the history
  • Loading branch information
afranchuk committed Aug 2, 2023
1 parent d1a4e75 commit e50b0f0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exclude = ["/.github", "/tests"]
[dependencies]
bitflags = "1.0"
maybe-owned = "0.3.4"
pdb = { git = "https://github.com/afranchuk/pdb" }
pdb2 = "0.9"
range-collections = "0.2.4"
thiserror = "1.0"
elsa = "1.4.0"
Expand Down
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub enum Error {
FormatError(#[source] std::fmt::Error),

#[error("PDB error: {0}")]
PdbError(#[source] pdb::Error),
PdbError(#[source] pdb2::Error),

#[error("Unexpected type for argument list")]
ArgumentTypeNotArgumentList,
Expand Down Expand Up @@ -53,8 +53,8 @@ pub enum Error {
ModuleInfoNotFound(usize),
}

impl From<pdb::Error> for Error {
fn from(err: pdb::Error) -> Self {
impl From<pdb2::Error> for Error {
fn from(err: pdb2::Error) -> Self {
Self::PdbError(err)
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
//! ```
//! use pdb_addr2line::pdb; // (this is a re-export of the pdb crate)
//!
//! fn look_up_addresses<'s, S: pdb::Source<'s> + Send + 's>(stream: S, addresses: &[u32]) -> std::result::Result<(), pdb_addr2line::Error> {
//! let pdb = pdb::PDB::open(stream)?;
//! fn look_up_addresses<'s, S: pdb2::Source<'s> + Send + 's>(stream: S, addresses: &[u32]) -> std::result::Result<(), pdb_addr2line::Error> {
//! let pdb = pdb2::PDB::open(stream)?;
//! let context_data = pdb_addr2line::ContextPdbData::try_from_pdb(pdb)?;
//! let context = context_data.make_context()?;
//!
Expand All @@ -42,7 +42,7 @@
//! ```

pub use maybe_owned;
pub use pdb;
pub use pdb2 as pdb;

mod constants;
mod error;
Expand Down Expand Up @@ -71,11 +71,11 @@ use std::{borrow::Cow, cell::RefCell, collections::BTreeMap};

type Result<V> = std::result::Result<V, Error>;

/// Allows to easily create a [`Context`] directly from a [`pdb::PDB`].
/// Allows to easily create a [`Context`] directly from a [`pdb2::PDB`].
///
/// ```
/// # fn wrapper<'s, S: pdb::Source<'s> + Send + 's>(stream: S) -> std::result::Result<(), pdb_addr2line::Error> {
/// let pdb = pdb::PDB::open(stream)?;
/// # fn wrapper<'s, S: pdb2::Source<'s> + Send + 's>(stream: S) -> std::result::Result<(), pdb_addr2line::Error> {
/// let pdb = pdb2::PDB::open(stream)?;
/// let context_data = pdb_addr2line::ContextPdbData::try_from_pdb(pdb)?;
/// let context = context_data.make_context()?;
/// # Ok(())
Expand All @@ -87,7 +87,7 @@ type Result<V> = std::result::Result<V, Error>;
/// going through an intermediate [`ContextPdbData`] object. However, there doesn't
/// seem to be an easy way to do this, due to certain lifetime dependencies: The
/// [`Context`] object wants to store certain objects inside itself (mostly for caching)
/// which have a lifetime dependency on [`pdb::ModuleInfo`], so the [`ModuleInfo`] has to be
/// which have a lifetime dependency on [`pdb2::ModuleInfo`], so the [`ModuleInfo`] has to be
/// owned outside of the [`Context`]. So the [`ContextPdbData`] object acts as that external
/// [`ModuleInfo`] owner.
pub struct ContextPdbData<'p, 's, S: Source<'s> + Send + 's> {
Expand All @@ -114,14 +114,14 @@ const _: fn() = || {
};

impl<'p, 's, S: Source<'s> + Send + 's> ContextPdbData<'p, 's, S> {
/// Create a [`ContextPdbData`] from a [`PDB`](pdb::PDB). This parses many of the PDB
/// Create a [`ContextPdbData`] from a [`PDB`](pdb2::PDB). This parses many of the PDB
/// streams and stores them in the [`ContextPdbData`].
/// This creator function takes ownership of the pdb object and never gives it back.
pub fn try_from_pdb(pdb: PDB<'s, S>) -> Result<Self> {
Self::try_from_maybe_owned(MaybeOwnedMut::Owned(pdb))
}

/// Create a [`ContextPdbData`] from a [`PDB`](pdb::PDB). This parses many of the PDB
/// Create a [`ContextPdbData`] from a [`PDB`](pdb2::PDB). This parses many of the PDB
/// streams and stores them in the [`ContextPdbData`].
/// This creator function takes an exclusive reference to the pdb object, for consumers
/// that want to keep using the pdb object once the `ContextPdbData` object is dropped.
Expand Down Expand Up @@ -207,7 +207,7 @@ impl<'p, 's, S: Source<'s> + Send + 's> ModuleProvider<'s> for ContextPdbData<'p
&self,
module_index: usize,
module: &Module,
) -> std::result::Result<Option<&ModuleInfo<'s>>, pdb::Error> {
) -> std::result::Result<Option<&ModuleInfo<'s>>, pdb2::Error> {
if let Some(module_info) = self.module_infos.get(&module_index) {
return Ok(Some(module_info));
}
Expand Down
28 changes: 14 additions & 14 deletions src/type_formatter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::Error;
use bitflags::bitflags;
use pdb::{
use pdb2::{
ArgumentList, ArrayType, ClassKind, ClassType, CrossModuleExports, CrossModuleImports,
CrossModuleRef, DebugInformation, FallibleIterator, FunctionAttributes, IdData, IdIndex,
IdInformation, Item, ItemFinder, ItemIndex, ItemIter, MachineType, MemberFunctionType,
Expand Down Expand Up @@ -62,7 +62,7 @@ pub trait ModuleProvider<'s> {
&self,
module_index: usize,
module: &Module,
) -> std::result::Result<Option<&ModuleInfo<'s>>, pdb::Error>;
) -> std::result::Result<Option<&ModuleInfo<'s>>, pdb2::Error>;
}

/// Allows printing function signatures, for example for use in stack traces.
Expand All @@ -71,7 +71,7 @@ pub trait ModuleProvider<'s> {
/// and no function arguments. Instead, the arguments need to be obtained from the symbol's type
/// information. [`TypeFormatter`] handles that.
///
/// The same is true for "inlinee" functions - these are referenced by their [`pdb::IdIndex`], and their
/// The same is true for "inlinee" functions - these are referenced by their [`pdb2::IdIndex`], and their
/// [`IdData`]'s name string again only contains the raw function name but no arguments and also
/// no namespace or class name. [`TypeFormatter`] handles those, too, in [`TypeFormatter::format_id`].
// Lifetimes:
Expand Down Expand Up @@ -125,7 +125,7 @@ impl<'a, 's> TypeFormatter<'a, 's> {
id_info: &'a IdInformation<'s>,
string_table: Option<&'a StringTable<'s>>,
flags: TypeFormatterFlags,
) -> std::result::Result<Self, pdb::Error> {
) -> std::result::Result<Self, pdb2::Error> {
let type_map = TypeMap {
iter: type_info.iter(),
finder: type_info.finder(),
Expand Down Expand Up @@ -195,7 +195,7 @@ impl<'a, 's> TypeFormatter<'a, 's> {
/// If the TypeIndex is 0, then only the raw name is emitted. In that case, the
/// name may need to go through additional demangling / "undecorating", but this
/// is the responsibility of the caller.
/// This method is used for [`ProcedureSymbol`s](pdb::ProcedureSymbol).
/// This method is used for [`ProcedureSymbol`s](pdb2::ProcedureSymbol).
/// The module_index is the index of the module in which this procedure was found. It
/// is necessary in order to properly resolve cross-module references.
pub fn format_function(
Expand All @@ -214,7 +214,7 @@ impl<'a, 's> TypeFormatter<'a, 's> {
/// If the TypeIndex is 0, then only the raw name is emitted. In that case, the
/// name may need to go through additional demangling / "undecorating", but this
/// is the responsibility of the caller.
/// This method is used for [`ProcedureSymbol`s](pdb::ProcedureSymbol).
/// This method is used for [`ProcedureSymbol`s](pdb2::ProcedureSymbol).
/// The module_index is the index of the module in which this procedure was found. It
/// is necessary in order to properly resolve cross-module references.
pub fn emit_function(
Expand Down Expand Up @@ -269,7 +269,7 @@ impl<'cache, 'a, 's> TypeFormatterForModule<'cache, 'a, 's> {
/// If the TypeIndex is 0, then only the raw name is emitted. In that case, the
/// name may need to go through additional demangling / "undecorating", but this
/// is the responsibility of the caller.
/// This method is used for [`ProcedureSymbol`s](pdb::ProcedureSymbol).
/// This method is used for [`ProcedureSymbol`s](pdb2::ProcedureSymbol).
pub fn emit_function(
&mut self,
w: &mut impl Write,
Expand Down Expand Up @@ -312,11 +312,11 @@ impl<'cache, 'a, 's> TypeFormatterForModule<'cache, 'a, 's> {
pub fn emit_id(&mut self, w: &mut impl Write, id_index: IdIndex) -> Result<()> {
let id_data = match self.parse_id_index(id_index) {
Ok(id_data) => id_data,
Err(Error::PdbError(pdb::Error::UnimplementedTypeKind(t))) => {
Err(Error::PdbError(pdb2::Error::UnimplementedTypeKind(t))) => {
write!(w, "<unimplemented type kind 0x{:x}>", t)?;
return Ok(());
}
Err(Error::PdbError(pdb::Error::TypeNotFound(type_index))) => {
Err(Error::PdbError(pdb2::Error::TypeNotFound(type_index))) => {
write!(w, "<missing type 0x{:x}>", type_index)?;
return Ok(());
}
Expand Down Expand Up @@ -1089,11 +1089,11 @@ impl<'cache, 'a, 's> TypeFormatterForModule<'cache, 'a, 's> {
fn emit_type_index(&mut self, w: &mut impl Write, index: TypeIndex) -> Result<()> {
match self.parse_type_index(index) {
Ok(type_data) => self.emit_type(w, type_data),
Err(Error::PdbError(pdb::Error::UnimplementedTypeKind(t))) => {
Err(Error::PdbError(pdb2::Error::UnimplementedTypeKind(t))) => {
write!(w, "<unimplemented type kind 0x{:x}>", t)?;
Ok(())
}
Err(Error::PdbError(pdb::Error::TypeNotFound(type_index))) => {
Err(Error::PdbError(pdb2::Error::TypeNotFound(type_index))) => {
write!(w, "<missing type 0x{:x}>", type_index)?;
Ok(())
}
Expand All @@ -1104,7 +1104,7 @@ impl<'cache, 'a, 's> TypeFormatterForModule<'cache, 'a, 's> {
fn emit_type(&mut self, w: &mut impl Write, type_data: TypeData) -> Result<()> {
match self.emit_type_inner(w, type_data) {
Ok(()) => Ok(()),
Err(Error::PdbError(pdb::Error::TypeNotFound(type_index))) => {
Err(Error::PdbError(pdb2::Error::TypeNotFound(type_index))) => {
write!(w, "<missing type 0x{:x}>", type_index)?;
Ok(())
}
Expand Down Expand Up @@ -1166,7 +1166,7 @@ impl<'a, I> ItemMap<'a, I>
where
I: ItemIndex,
{
pub fn try_get(&mut self, index: I) -> std::result::Result<Item<'a, I>, pdb::Error> {
pub fn try_get(&mut self, index: I) -> std::result::Result<Item<'a, I>, pdb2::Error> {
if index <= self.finder.max_index() {
return self.finder.find(index);
}
Expand All @@ -1180,7 +1180,7 @@ where
}
}

Err(pdb::Error::TypeNotFound(index.into()))
Err(pdb2::Error::TypeNotFound(index.into()))
}
}

Expand Down

0 comments on commit e50b0f0

Please sign in to comment.