When running dwarf-to-dwarf-assembler.py on
outputs/gdb.dwarf2/implptr-64bit/implptr-64bit-d2-o8-a4-r4-t0, I run into:
...
elftools.common.exceptions.ELFParseError: expected 8, found 5
...
for the DWARF:
...
<2><335>: Abbrev Number: 8 (DW_TAG_variable)
<336> DW_AT_name : p
<338> DW_AT_location : 6 byte block: f2 14 3 0 0 0 \
(DW_OP_GNU_implicit_pointer: <0x314> 0)
...
Pyelftools expects that DW_OP_GNU_implicit_pointer has an 8-byte reference
operand (because it's a 64-bit DWARF unit), but instead it has a 4-byte
reference.
The DWARF is correct, it's a cornercase of using DW_OP_GNU_implicit_pointer in
DWARF v2, where DW_FORM_ref_addr references have the same size as an address
on the target system, something that was changed in DWARF v3.
Handle this by catching the error and printing:
...
DW_AT_location "\xf2\x14\x03\x00\x00\x00" DW_FORM_block \
# Failed to print DWARF expression: expected 8, found 5
...
Approved-By: Tom Tromey <tom@tromey.com>
from logging import getLogger
from typing import Annotated, Optional
+from elftools.common.exceptions import ELFParseError
from elftools.construct.lib.container import ListContainer
from elftools.dwarf.compileunit import CompileUnit as RawCompileUnit
from elftools.dwarf.die import DIE as RawDIE
postfix = " # Failed to print op as DWARF expression: " + hex(
int(str(e))
)
+ except ELFParseError as e:
+ # Fall through to basic printing.
+ postfix = " # Failed to print DWARF expression: " + str(e)
# Print the data as a string in "\x01\x02\x03\x04" format.
result = ""
for op in self.value: