Filename in lineprog index fix made DWARF5 aware (#463)
authorSeva Alekseyev <sevaa@yarxi.ru>
Tue, 21 Mar 2023 00:01:05 +0000 (20:01 -0400)
committerGitHub <noreply@github.com>
Tue, 21 Mar 2023 00:01:05 +0000 (17:01 -0700)
examples/dwarf_decode_address.py

index e335d0bb5d9ac48668f31c42fd2b595de275117f..79938e4b6de586b5ff237c093356f719ac519587 100644 (file)
@@ -80,6 +80,7 @@ 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)
+        delta = 1 if lineprog.header.version < 5 else 0
         prevstate = None
         for entry in lineprog.get_entries():
             # We're interested in those entries where a new state is assigned
@@ -88,7 +89,7 @@ def decode_file_line(dwarfinfo, address):
             # 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
+                filename = lineprog['file_entry'][prevstate.file - delta].name
                 line = prevstate.line
                 return filename, line
             if entry.state.end_sequence: