Skip to content

Commit

Permalink
DWARF expr: tests passing with new parser
Browse files Browse the repository at this point in the history
  • Loading branch information
eliben committed Mar 14, 2020
1 parent 43adb41 commit 3d97b6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions elftools/dwarf/descriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -531,18 +531,26 @@ def _import_extra(attr, die, section_offset):
]


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 = []

Expand Down
2 changes: 1 addition & 1 deletion elftools/dwarf/dwarf_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def parse_noargs():
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):
Expand Down

0 comments on commit 3d97b6e

Please sign in to comment.