From 9db67b19b237f0d75f119633b3f23f4b67a60b3d Mon Sep 17 00:00:00 2001 From: Jangseop Shin Date: Tue, 31 Aug 2021 22:19:27 +0900 Subject: [PATCH] [example] bug fixes in dwarf_decode_address example (#361) * [example] Handle lpe with end_sequence correctly * [example] exclude highpc in address comparison in decode_funcname Co-authored-by: Jangseop Shin --- examples/dwarf_decode_address.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/dwarf_decode_address.py b/examples/dwarf_decode_address.py index 047ce3b..e206ae9 100644 --- a/examples/dwarf_decode_address.py +++ b/examples/dwarf_decode_address.py @@ -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 -- 2.30.2