[example] bug fixes in dwarf_decode_address example (#361)
authorJangseop Shin <jeffy861009@gmail.com>
Tue, 31 Aug 2021 13:19:27 +0000 (22:19 +0900)
committerGitHub <noreply@github.com>
Tue, 31 Aug 2021 13:19:27 +0000 (06:19 -0700)
* [example] Handle lpe with end_sequence correctly

* [example] exclude highpc in address comparison in decode_funcname

Co-authored-by: Jangseop Shin <j.s.shin@samsung.com>
examples/dwarf_decode_address.py

index 047ce3b56281abd4938b3e6e793a69a42d09bfdf..e206ae9ae471c06b093928c5cb0fd7e67bb03310 100644 (file)
@@ -67,7 +67,7 @@ def decode_funcname(dwarfinfo, address):
                               highpc_attr_class)
                         continue
 
-                    if lowpc <= address <= highpc:
+                    if lowpc <= address < highpc:
                         return DIE.attributes['DW_AT_name'].value
             except KeyError:
                 continue
@@ -85,17 +85,22 @@ def decode_file_line(dwarfinfo, address):
             # We're interested in those entries where a new state is assigned
             if entry.state is None:
                 continue
-            if entry.state.end_sequence:
-                # if the line number sequence ends, clear prevstate.
-                prevstate = None
-                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
+            if entry.state.end_sequence:
+                # For the state with `end_sequence`, `address` means the address
+                # of the first byte after the target machine instruction
+                # sequence and other information is meaningless. We clear
+                # prevstate so that it's not used in the next iteration. Address
+                # info is used in the above comparison to see if we need to use
+                # the line information for the prevstate.
+                prevstate = None
+            else:
+                prevstate = entry.state
     return None, None