From d79a0a3c1a7ee3dbe4445a035400ddefa1b7f51e Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Fri, 12 Apr 2013 06:29:37 -0700 Subject: [PATCH] Issue #8: fix the dwarf_decode_address example (off-by-one error in line reporting) --- examples/dwarf_decode_address.py | 18 ++++++++++-------- .../reference_output/dwarf_decode_address.out | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/dwarf_decode_address.py b/examples/dwarf_decode_address.py index 55b31c7..80b53ee 100644 --- a/examples/dwarf_decode_address.py +++ b/examples/dwarf_decode_address.py @@ -63,16 +63,18 @@ def decode_file_line(dwarfinfo, address): for CU in dwarfinfo.iter_CUs(): # First, look at line programs to find the file/line for the address lineprog = dwarfinfo.line_program_for_CU(CU) - prevaddr = maxint + prevstate = None for entry in lineprog.get_entries(): # We're interested in those entries where a new state is assigned - state = entry.state - if state is not None and not state.end_sequence: - if prevaddr <= address <= state.address: - filename = lineprog['file_entry'][state.file - 1].name - line = state.line - return filename, line - prevaddr = state.address + if entry.state is None or entry.state.end_sequence: + continue + # Looking for a range of addresses in two consecutive states that + # contain the required address. + if prevstate and prevstate.address <= address < entry.state.address: + filename = lineprog['file_entry'][prevstate.file - 1].name + line = prevstate.line + return filename, line + prevstate = entry.state return None, None diff --git a/examples/reference_output/dwarf_decode_address.out b/examples/reference_output/dwarf_decode_address.out index 73ca9ee..e14d84a 100644 --- a/examples/reference_output/dwarf_decode_address.out +++ b/examples/reference_output/dwarf_decode_address.out @@ -1,4 +1,4 @@ Processing file: ./examples/sample_exe64.elf Function: main File: z.c -Line: 4 +Line: 3 -- 2.30.2