]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/contrib] Fix ELFParseError in dwarf-to-dwarf-assembler.py
authorTom de Vries <tdevries@suse.de>
Wed, 10 Jun 2026 07:54:22 +0000 (09:54 +0200)
committerTom de Vries <tdevries@suse.de>
Wed, 10 Jun 2026 07:54:22 +0000 (09:54 +0200)
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>
gdb/contrib/dwarf-to-dwarf-assembler.py

index fa32bc4bbabe86d09248ba1db609cfd9c45f1617..d47355e0a7cd912a53131a294f30601ba7cff343 100755 (executable)
@@ -48,6 +48,7 @@ from io import BytesIO, IOBase
 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
@@ -238,6 +239,9 @@ class DWARFAttribute:
                     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: