Struct pdb::TypeInformation [] [src]

pub struct TypeInformation<'t> { /* fields omitted */ }

TypeInformation provides zero-copy access to a PDB type data stream.

PDB type information is stored as a stream of length-prefixed Type records, and thus the most fundamental operation supported by TypeInformation is to iterate over Types.

Types are uniquely identified by TypeIndex, and types are stored within the PDB in ascending order of TypeIndex.

Many types refer to other types by TypeIndex, and these references may refer to other types forming a chain that's arbitrarily long. Fortunately, PDB format requires that types refer only to types with lower TypeIndexes; thus, the stream of types form a directed acyclic graph.

TypeInformation can iterate by TypeIndex, since that's essentially the only operation permitted by the data. TypeFinder is a secondary data structure to provide efficient backtracking.

Examples

Iterating over the types while building a TypeFinder:


let type_information = pdb.type_information()?;
let mut type_finder = type_information.new_type_finder();

let mut iter = type_information.iter();
while let Some(typ) = iter.next()? {
    // build the type finder as we go
    type_finder.update(&iter);

    // parse the type record
    match typ.parse() {
        Ok(pdb::TypeData::Class{name, properties, fields: Some(fields), ..}) => {
            // this Type describes a class-like type with fields
            println!("type {} is a class named {} with fields = {}", typ.type_index(), name, fields);

            // fields is a TypeIndex, so to find information about the fields, find and parse that Type
            match type_finder.find(fields)?.parse()? {
                pdb::TypeData::FieldList{ fields, continuation } => {
                    for field in fields {
                        if let pdb::TypeData::Member { offset, name, field_type, .. } = field {
                            // follow "field_type" as desired
                            println!("  - field {} at offset {:x}", name, offset);
                        } else {
                            // do stuff with member functions, nested types, etc.
                        }
                    }

                    // FieldLists can be split across multiple records; follow "continuation" in live code
                }
                _ => { }
            }

        },
        Ok(_) => {
            // ignore other types
        },
        Err(pdb::Error::UnimplementedTypeKind(_)) => {
            // TODO: parse everything
            // ignore for now
        },
        Err(e) => {
            // other parse error
            return Err(e);
        }
    }
}

Methods

impl<'t> TypeInformation<'t>
[src]

Returns an iterator that can traverse the type table in sequential order.

Returns the number of types contained in this TypeInformation.

Note that primitive types are not stored in the PDB file, so the number of distinct types reachable via this TypeInformation will be higher than len().

Returns a TypeFinder with a default time-space tradeoff.

The TypeFinder is initially empty and must be populated by iterating.

Trait Implementations

impl<'t> Debug for TypeInformation<'t>
[src]

Formats the value using the given formatter.