Issue #8: fix the dwarf_decode_address example (off-by-one error in line reporting)
authorEli Bendersky <eliben@gmail.com>
Fri, 12 Apr 2013 13:29:37 +0000 (06:29 -0700)
committerEli Bendersky <eliben@gmail.com>
Fri, 12 Apr 2013 13:29:37 +0000 (06:29 -0700)
examples/dwarf_decode_address.py
examples/reference_output/dwarf_decode_address.out

index 55b31c7dfbb05ae909d79ff02f6f3eafbe3d5397..80b53eefc897cdc7899dd3d2ab89f22c9d6d1a86 100644 (file)
@@ -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
 
 
index 73ca9eeaab97284e6eb26cd10e1063aa4f52e633..e14d84a77dbaa0c7b6591e32e623ba7984bfcd34 100644 (file)
@@ -1,4 +1,4 @@
 Processing file: ./examples/sample_exe64.elf
 Function: main
 File: z.c
-Line: 4
+Line: 3