DWARF expr: tests passing with new parser
authorEli Bendersky <eliben@gmail.com>
Fri, 13 Mar 2020 13:23:52 +0000 (06:23 -0700)
committerEli Bendersky <eliben@users.noreply.github.com>
Sat, 14 Mar 2020 12:24:52 +0000 (05:24 -0700)
elftools/dwarf/descriptions.py
elftools/dwarf/dwarf_expr.py

index 02065784fec04077ab15458ac86163f9fb3a7e85..c77abb76149fda45d66604b47326c63be897b54d 100644 (file)
@@ -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 = []
 
index 8ef6b6f0673c40e675883aab9de221f8ff344016..c5b6bda59a09c721e699f4719081db0a48b96c4a 100644 (file)
@@ -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):