Eli Bendersky avatar Eli Bendersky committed a7f685a

Issue #8: fix the dwarf_decode_address example (off-by-one error in line reporting)

Comments (0)

Files changed (2)


     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


 Processing file: ./examples/sample_exe64.elf
 Function: main
 File: z.c
-Line: 4
+Line: 3
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.