getsentry / pdb

A parser for Microsoft PDB (Program Database) debugging information
https://docs.rs/pdb/
Apache License 2.0
368 stars 68 forks source link

UserDefinedTypeSourceId::source_file field is incorrect type #95

Closed camden-smallwood closed 3 years ago

camden-smallwood commented 3 years ago

The source_file field in the UserDefinedTypeSourceId struct is of type IdIndex, but it should be of type StringRef. Currently I have to manually de/reconstruct it by hand. Fortunately the IdIndex and StringRef types both have public fields and there is a workaround, but this should not be necessary:

https://github.com/willglynn/pdb/blob/3d394eaf547998eeebc7c08ac5788d83d98a1caa/src/tpi/id.rs#L163

if let Ok(IdData::UserDefinedTypeSource(udt)) = typ.parse() {
    if let Ok(source_file) = StringRef(udt.source_file.0).to_string_lossy(&string_table) {
        println!("{:?}", source_file);
    }
}
jan-auer commented 3 years ago

Thanks for the report!

There seems to be a difference between LF_UDT_SRC_LINE and LF_UDT_MOD_SRC_LINE that we missed in the initial implementation.

I currently don't have PDBs at hand to verify this, but it looks like we either need to split this into two types, or we create an enum field for the file reference that can either be a IdIndex or a (u16, StringRef).