From: Jangseop Shin Date: Tue, 31 Aug 2021 13:19:27 +0000 (+0900) Subject: [example] bug fixes in dwarf_decode_address example (#361) X-Git-Tag: v0.28~14 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9db67b19b237f0d75f119633b3f23f4b67a60b3d;p=pyelftools.git [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 --- 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