Skip to content

Commit

Permalink
Issue eliben#8: fix the dwarf_decode_address example (off-by-one erro…
Browse files Browse the repository at this point in the history
…r in line reporting)
  • Loading branch information
eliben committed Apr 12, 2013
1 parent cc1e557 commit d79a0a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions examples/dwarf_decode_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion examples/reference_output/dwarf_decode_address.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Processing file: ./examples/sample_exe64.elf
Function: main
File: z.c
Line: 4
Line: 3

0 comments on commit d79a0a3

Please sign in to comment.