eliben / pyelftools

Parsing ELF and DWARF in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot parse DW_OP_GNU_uninit

KelvinChung2000 opened this issue · comments

The DWARFExprParser.parse_expr fails to parse with key 0xf0, which is DW_OP_GNU_uninit.

Have you got a binary with this? Support can be added, but an autotest would be nice.

Yes. I got this when I compiled a benchmark with the riscv64-unknown-linux-gnu-gcc compiler.
bfs.zip

A PR is waiting, but in the meantime, here is a monkeypatch for the issue:

import elftools.dwarf.dwarf_expr

def monkeypatch():
    elftools.dwarf.dwarf_expr.DW_OP_name2opcode['DW_OP_GNU_uninit'] = 0xf0
    elftools.dwarf.dwarf_expr.DW_OP_opcode2name[0xf0] = 'DW_OP_GNU_uninit'
    old_init_dispatch_table = elftools.dwarf.dwarf_expr._init_dispatch_table
    def _init_dispatch_table_patch(structs):
        table = old_init_dispatch_table(structs)  
        table[0xf0] = lambda s: []
        return table
    elftools.dwarf.dwarf_expr._init_dispatch_table = _init_dispatch_table_patch

Source: https://github.com/sevaa/dwex/blob/master/dwex/patch.py

@KelvinChung2000 thanks for the report. Can this be closed following @sevaa 's #511 ?