From: Eli Bendersky Date: Fri, 13 Mar 2020 13:23:52 +0000 (-0700) Subject: DWARF expr: tests passing with new parser X-Git-Tag: v0.27~46 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3d97b6e04be5ead470bc3edb64456ec23b49595c;p=pyelftools.git DWARF expr: tests passing with new parser --- diff --git a/elftools/dwarf/descriptions.py b/elftools/dwarf/descriptions.py index 0206578..c77abb7 100644 --- a/elftools/dwarf/descriptions.py +++ b/elftools/dwarf/descriptions.py @@ -9,7 +9,7 @@ from collections import defaultdict from .constants import * -from .dwarf_expr import GenericExprVisitor +from .dwarf_expr import GenericExprVisitor, parse_expr from .die import DIE from ..common.utils import preserve_stream_pos, dwarf_assert from ..common.py3compat import bytes2str @@ -531,18 +531,26 @@ _REG_NAMES_x64 = [ ] -class ExprDumper(GenericExprVisitor): - """ A concrete visitor for DWARF expressions that dumps a textual +class ExprDumper(object): + """ A dumper for DWARF expressions that dumps a textual representation of the complete expression. Usage: after creation, call process_expr, and then get_str for a semicolon-delimited string representation of the decoded expression. """ def __init__(self, structs): - super(ExprDumper, self).__init__(structs) + self.structs = structs self._init_lookups() self._str_parts = [] + def process_expr(self, expr): + """ Parse and process a DWARF expression. expr should be a list of + (integer) byte values. + """ + parsed = parse_expr(expr, self.structs) + for deo in parsed: + self._str_parts.append(self._dump_to_string(deo.op, deo.op_name, deo.args)) + def clear(self): self._str_parts = [] diff --git a/elftools/dwarf/dwarf_expr.py b/elftools/dwarf/dwarf_expr.py index 8ef6b6f..c5b6bda 100644 --- a/elftools/dwarf/dwarf_expr.py +++ b/elftools/dwarf/dwarf_expr.py @@ -317,7 +317,7 @@ def _init_dispatch_table(structs): return lambda stream: [] def parse_op_addr(): - return lambda stream: [struct_parse(self.structs.Dwarf_target_addr(''), + return lambda stream: [struct_parse(structs.Dwarf_target_addr(''), stream)] def parse_arg_struct(arg_struct):