eliben / pyelftools

Parsing ELF and DWARF in Python
Other
2.02k stars 511 forks source link

Cannot parse DW_OP_GNU_uninit #508

Closed KelvinChung2000 closed 1 year ago

KelvinChung2000 commented 1 year ago

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

sevaa commented 1 year ago

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

KelvinChung2000 commented 1 year ago

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

sevaa commented 1 year ago

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

eliben commented 1 year ago

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