Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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
8 changes: 4 additions & 4 deletions examples/pdb2hpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use pdb::FallibleIterator;

type TypeSet = BTreeSet<pdb::TypeIndex>;

pub fn type_name<'p>(
type_finder: &pdb::TypeFinder<'p>,
pub fn type_name(
type_finder: &pdb::TypeFinder<'_>,
type_index: pdb::TypeIndex,
needed_types: &mut TypeSet,
) -> pdb::Result<String> {
Expand Down Expand Up @@ -359,8 +359,8 @@ impl<'p> Method<'p> {
}
}

fn argument_list<'p>(
type_finder: &pdb::TypeFinder<'p>,
fn argument_list(
type_finder: &pdb::TypeFinder<'_>,
type_index: pdb::TypeIndex,
needed_types: &mut TypeSet,
) -> pdb::Result<Vec<String>> {
Expand Down
11 changes: 10 additions & 1 deletion examples/pdb_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::env;
use pdb2 as pdb;

use getopts::Options;
use pdb::{FallibleIterator, PdbInternalSectionOffset};
use pdb::{FallibleIterator, PdbInternalSectionOffset, RawString};

fn print_usage(program: &str, opts: Options) {
let brief = format!("Usage: {} input.pdb", program);
Expand All @@ -28,6 +28,15 @@ fn print_symbol(symbol: &pdb::Symbol<'_>) -> pdb::Result<()> {
pdb::SymbolData::Procedure(data) => {
print_row(data.offset, "function", data.name);
}
pdb::SymbolData::ManagedProcedure(data) => {
match data.name {
None => print_row(data.offset, "function", RawString::from(&b"<empty>"[..])),
Some(name) => print_row(data.offset, "function", name),
}
}
pdb::SymbolData::ManagedSlot(data) => {
print_row(data.offset, "data", data.name);
}
_ => {
// ignore everything else
}
Expand Down
12 changes: 10 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::result;
use std::slice;

use scroll::ctx::TryFromCtx;
use scroll::{self, Endian, Pread, LE};
use scroll::{Endian, Pread, LE};

use crate::tpi::constants;

Expand Down Expand Up @@ -581,7 +581,7 @@ pub trait ItemIndex:
/// [`ModuleInfo`](crate::ModuleInfo). Note that this comparison needs to be done
/// case-insensitively as the name in the DBI stream and name table are known to not
/// have matching cases.
/// 4. Resolve the [`Local`](crate::Local) index into a global one using
/// 4. Resolve the [`Local`] index into a global one using
/// [`CrossModuleExports`](crate::CrossModuleExports).
///
/// Cross module references are specially formatted indexes with the most significant bit set to
Expand All @@ -605,6 +605,14 @@ impl_pread!(TypeIndex);

impl ItemIndex for TypeIndex {}

/// COM+ metadata token for managed procedures (`CV_tkn_t`).
#[derive(Clone, Copy, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct COMToken(pub u32);

impl_convert!(COMToken, u32);
impl_hex_fmt!(COMToken);
impl_pread!(COMToken);

/// Index of an [`Id`](crate::Id) in [`IdInformation`](crate::IdInformation) stream.
///
/// If this index is a [cross module reference](ItemIndex::is_cross_module), it must be resolved
Expand Down
11 changes: 11 additions & 0 deletions src/dbi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ impl<'s> DebugInformation<'s> {
}
}

/// Returns whether or not this PDB has been marked as stripped. Stripped PDBs do not contain
/// type information, line number information, or per-object CV symbols.
///
/// This flag is set when a PDB is written with [/PDBSTRIPPED] by MSVC.
///
/// [/PDBSTRIPPED]: https://learn.microsoft.com/en-us/cpp/build/reference/pdbstripped-strip-private-symbols?view=msvc-170
pub fn is_stripped(&self) -> bool {
// flags.fStripped
(self.header.flags & 0x2) != 0
}

/// Returns an iterator that can traverse the modules list in sequential order.
pub fn modules(&self) -> Result<ModuleIter<'_>> {
let mut buf = self.stream.parse_buffer();
Expand Down
7 changes: 3 additions & 4 deletions src/modi/c13.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use scroll::{ctx::TryFromCtx, Endian, Pread};

use crate::common::*;
use crate::modi::{
constants, CrossModuleExport, CrossModuleRef, FileChecksum, FileIndex, FileInfo, LineInfo,
LineInfoKind, ModuleRef,
constants, CrossModuleExport, CrossModuleRef, FileChecksum, FileInfo, LineInfo, LineInfoKind,
ModuleRef,
};
use crate::symbol::{BinaryAnnotation, BinaryAnnotationsIter, InlineSiteSymbol};
use crate::FallibleIterator;
Expand Down Expand Up @@ -345,6 +345,7 @@ enum LineEntry {
/// Declares a source line number.
Number(LineNumberEntry),
/// Declares a debugging marker.
#[allow(dead_code)] // reason = "the inner `LineMarkerEntry` is not (yet) accessed"
Marker(LineMarkerEntry),
}

Expand Down Expand Up @@ -1418,8 +1419,6 @@ impl<'a> LineProgram<'a> {
mod tests {
use super::*;

use std::mem;

use crate::symbol::BinaryAnnotations;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/modi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'s> ModuleInfo<'s> {
}

fn lines_data(&self, size: usize) -> &[u8] {
let start = self.symbols_size as usize;
let start = self.symbols_size;
&self.stream[start..start + size]
}

Expand Down
2 changes: 1 addition & 1 deletion src/msf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ mod big {
let _ = stream_table.take((stream_count - stream_number - 1) as usize * 4)?;

// skip the preceding streams' page numbers
let _ = stream_table.take((page_numbers_to_skip as usize) * 4)?;
let _ = stream_table.take(page_numbers_to_skip * 4)?;

// we're now at the list of pages for our stream
// accumulate them into a PageList
Expand Down
1 change: 0 additions & 1 deletion src/msf/page_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ impl PageList {
#[cfg(test)]
mod tests {
use crate::msf::page_list::*;
use crate::source::SourceSlice;

#[test]
fn test_push() {
Expand Down
4 changes: 1 addition & 3 deletions src/omap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl fmt::Debug for OMAPRecord {
impl PartialOrd for OMAPRecord {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.source_address().partial_cmp(&other.source_address())
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -577,8 +577,6 @@ impl PdbInternalSectionOffset {
mod tests {
use super::*;

use std::mem;

#[test]
fn test_omap_record() {
assert_eq!(mem::size_of::<OMAPRecord>(), 8);
Expand Down
Loading