Skip to content

Commit

Permalink
Merge pull request #68 from jan-auer/fix/symbol-lines
Browse files Browse the repository at this point in the history
ProcedureSymbol records for MASM functions have code ranges associated
that do not match the actual code or line records.

lines_at_offset assumed that if there is a lines subsection for a
symbol, it shares the exact same start offset as the symbol. However,
this is not the case for MASM functions, where the symbol's offset can
lie after the actual start of the instructions / line records. Since the
name of lines_at_offset was chosen badly, it is now renamed to
lines_for_symbol, and explicitly states that it may return line records
outside of the symbol's stated code range.

A consumer of this should probably collect the line records for each
symbol and infer a proper code range.

Also, the internal implementation of lines_at_offset was slow in two
regards: It had linear runtime complexity, and repeatedly had to iterate
through large chunks of memory to find the appropriate section.
LineProgram now collects and sorts all line sections ahead of time to
perform faster binary search.
  • Loading branch information
jan-auer authored Jun 2, 2022
2 parents ad39f23 + e9085e1 commit 1419c8b
Show file tree
Hide file tree
Showing 3 changed files with 276 additions and 49 deletions.
2 changes: 1 addition & 1 deletion examples/pdb_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn dump_pdb(filename: &str) -> pdb::Result<()> {
let sign = if proc.global { "+" } else { "-" };
println!("{} {}", sign, proc.name);

let mut lines = program.lines_at_offset(proc.offset);
let mut lines = program.lines_for_symbol(proc.offset);
while let Some(line_info) = lines.next()? {
let rva = line_info.offset.to_rva(&address_map).expect("invalid rva");
let file_info = program.get_file_info(line_info.file_index)?;
Expand Down
Loading

0 comments on commit 1419c8b

Please sign in to comment.