From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/3] [gdb/contrib] Fix ELFParseError in dwarf-to-dwarf-assembler.py
Date: Mon, 8 Jun 2026 14:54:20 +0200 [thread overview]
Message-ID: <20260608125420.2318026-4-tdevries@suse.de> (raw)
In-Reply-To: <20260608125420.2318026-1-tdevries@suse.de>
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
...
---
gdb/contrib/dwarf-to-dwarf-assembler.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/gdb/contrib/dwarf-to-dwarf-assembler.py b/gdb/contrib/dwarf-to-dwarf-assembler.py
index c1818f9fdb8..797d5a46d72 100755
--- a/gdb/contrib/dwarf-to-dwarf-assembler.py
+++ b/gdb/contrib/dwarf-to-dwarf-assembler.py
@@ -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
@@ -245,6 +246,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:
--
2.51.0
next prev parent reply other threads:[~2026-06-08 12:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-08 12:54 [PATCH 0/3] [gdb/contrib] Some dwarf-to-dwarf-assembler.py fixes Tom de Vries
2026-06-08 12:54 ` [PATCH 1/3] [gdb/contrib] Fix KeyError in dwarf-to-dwarf-assembler.py Tom de Vries
2026-06-09 17:04 ` Tom Tromey
2026-06-10 7:57 ` Tom de Vries
2026-06-10 13:23 ` Tom Tromey
2026-06-08 12:54 ` [PATCH 2/3] [gdb/contrib] Fix UnicodeDecodeError " Tom de Vries
2026-06-09 17:07 ` Tom Tromey
2026-06-10 9:12 ` Tom de Vries
2026-06-08 12:54 ` Tom de Vries [this message]
2026-06-08 13:18 ` [PATCH 3/3] [gdb/contrib] Fix ELFParseError " Tom de Vries
2026-06-09 17:08 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260608125420.2318026-4-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox