Skip to content

Understand the value of a DW_AT_data_member_location #572

Answered by sevaa
f-zl asked this question in Q&A
Discussion options

You must be logged in to vote

The first thing to do will be parsing the expression blob into operations and arguments:

from elftools.dwarf.dwarf_expr import DWARFExprParser
parser = DWARFExprParser(die.cu.structs)
expression = parser.parse_expr(value)

You can cache the parser object; it's stateless. One instance per CU if you are being meticulous.

Then you get a parsed expression, which is a list of namedtuples with op (numeric), op_name (string, the DWARF mnemonic), and args (the variable length tuple with whatever arguments the operation takes).

Then the condition can go like this:

if len(expression) == 1 and expression[0].op_name == 'DW_OP_plus_uconst':
    return expression[0].args[0]
else:
   # Unsupported

You …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@f-zl
Comment options

Answer selected by f-zl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants