* [PATCH 0/3] [gdb/contrib] Some dwarf-to-dwarf-assember.py fixes
@ 2026-03-09 12:19 Tom de Vries
2026-03-09 12:19 ` [PATCH 1/3] [gdb/contrib] Handle DW_LANG_Mips_Assembler in dwarf-to-dwarf-assembler.py Tom de Vries
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Tom de Vries @ 2026-03-09 12:19 UTC (permalink / raw)
To: gdb-patches
I ran into trouble using dwarf-to-dwarf-assember.py on a hello world
executable, due to DW_LANG_MIPS_assembler.
The first patch fixes this.
I then tested the script on the executables generated by the testsuite, and ran into
DW_FORM_data16 being unsupported.
The second patch fixes that.
The third patch removes the only raise from the script, preferring imperfect
to partial output.
I tested the changes using the following command:
...
$ for f in $(find outputs/ -type f -executable| sort); do \
./src/gdb/contrib/dwarf-to-dwarf-assembler.py $f > /dev/null; \
st=$?; \
if [ $st -ne 0 ]; then echo "FILE: $f: $st"; fi; \
done \
2>&1 | tee LOG
Error parsing ELF file. Does it contain DWARF information?
'int' object has no attribute 'decode'
FILE: outputs/gdb.base/dwz-symtabs/libfoo-2.so: 61
Error parsing ELF file. Does it contain DWARF information?
'int' object has no attribute 'decode'
FILE: outputs/gdb.base/dwz-symtabs/libfoo.so: 61
Error parsing ELF file. Does it contain DWARF information?
Magic number does not match
FILE: outputs/gdb.base/gnu-debugdata/gnu-debugdata.mini_debuginfo-debuglink.xz: 61
Error parsing ELF file. Does it contain DWARF information?
'ascii' codec can't decode byte 0xc3 in position 6: ordinal not in range(128)
FILE: outputs/gdb.base/utf8-identifiers/utf8-identifiers: 61
Error parsing ELF file. Does it contain DWARF information?
'int' object has no attribute 'decode'
FILE: outputs/gdb.debuginfod/solib-with-dwz/debug/libfoo-2.so.debug: 61
Error parsing ELF file. Does it contain DWARF information?
'int' object has no attribute 'decode'
FILE: outputs/gdb.debuginfod/solib-with-dwz/debug/libfoo.so.debug: 61
Error parsing ELF file. Does it contain DWARF information?
refaddr 12346399 not in DIE range of CU 721
FILE: outputs/gdb.dwarf2/corrupt/corrupt: 61
Error parsing ELF file. Does it contain DWARF information?
unexpected end of stream while parsing a ULEB128 encoded value
FILE: outputs/gdb.dwarf2/debug-names-missing-cu/debug-names-missing-cu: 61
Error parsing ELF file. Does it contain DWARF information?
no decoding mapping for 103 [unit_type]
FILE: outputs/gdb.dwarf2/dw2-error/dw2-error: 61
Error parsing ELF file. Does it contain DWARF information?
refaddr 756 not in DIE range of CU 756
FILE: outputs/gdb.dwarf2/dw2-inter-cu-error-2/dw2-inter-cu-error-2: 61
Error parsing ELF file. Does it contain DWARF information?
769
FILE: outputs/gdb.dwarf2/dw2-inter-cu-error/dw2-inter-cu-error: 61
Error parsing ELF file. Does it contain DWARF information?
1271
FILE: outputs/gdb.dwarf2/dw2-op-out-param/dw2-op-out-param: 61
Error parsing ELF file. Does it contain DWARF information?
'NoneType' object has no attribute 'stream'
FILE: outputs/gdb.dwarf2/dw2-using-debug-str/dw2-using-debug-str-no-debug-str: 61
Error parsing ELF file. Does it contain DWARF information?
'DW_FORM_strx'
FILE: outputs/gdb.dwarf2/dw-form-strx/dw-form-strx: 61
Error parsing ELF file. Does it contain DWARF information?
'DW_FORM_strx'
FILE: outputs/gdb.dwarf2/dw-form-strx-out-of-bounds/dw-form-strx-out-of-bounds: 61
Error parsing ELF file. Does it contain DWARF information?
2
FILE: outputs/gdb.dwarf2/implptrpiece/implptrpiece: 61
Error parsing ELF file. Does it contain DWARF information?
refaddr 860 not in DIE range of CU 721
FILE: outputs/gdb.dwarf2/imported-unit-c/imported-unit-c: 61
Traceback (most recent call last):
File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 663, in <module>
main(sys.argv)
~~~~^^^^^^^^^^
File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 659, in main
generator.generate()
~~~~~~~~~~~~~~~~~~^^
File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 631, in generate
self.generate_die(die, indent_count)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 610, in generate_die
die_lines = die.format(self.dwarf_parser.offset_to_die, indent_count)
File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 300, in format
return "\n".join(self.format_lines(offset_die_lookup, indent_count))
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 397, in format_lines
inner_lines = super().format_lines(offset_die_lookup, indent_count + 1)
File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 288, in format_lines
child_lines = child.format_lines(
offset_die_lookup, indent_count=indent_count + 1
)
File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 288, in format_lines
child_lines = child.format_lines(
offset_die_lookup, indent_count=indent_count + 1
)
File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 288, in format_lines
child_lines = child.format_lines(
offset_die_lookup, indent_count=indent_count + 1
)
[Previous line repeated 1 more time]
File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 272, in format_lines
attr_line = attr.format(
offset_die_lookup, indent_count=indent_count + 1
)
File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 222, in format
s += self._format_value(offset_die_lookup)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 170, in _format_value
return self._format_str(self.value.decode("ascii"))
~~~~~~~~~~~~~~~~~^^^^^^^^^
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf0 in position 0: ordinal not in range(128)
FILE: outputs/gdb.rust/unicode/unicode: 1
...
I filed the UnicodeDecodeError as PR testsuite/33970 [1].
[1] https://sourceware.org/bugzilla/show_bug.cgi?id=33970
Tom de Vries (3):
[gdb/contrib] Handle DW_LANG_Mips_Assembler in
dwarf-to-dwarf-assembler.py
[gdb/contrib] Handle DW_FORM_data16 in dwarf-to-dwarf-assembler.py
[gdb/contrib] Avoid NotImplementedError in dwarf-to-dwarf-assembler.py
gdb/contrib/dwarf-to-dwarf-assembler.py | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
base-commit: 072ea1fa0d39ea0110722385f37415ab6352315d
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] [gdb/contrib] Handle DW_LANG_Mips_Assembler in dwarf-to-dwarf-assembler.py
2026-03-09 12:19 [PATCH 0/3] [gdb/contrib] Some dwarf-to-dwarf-assember.py fixes Tom de Vries
@ 2026-03-09 12:19 ` Tom de Vries
2026-03-09 14:10 ` Tom Tromey
2026-03-09 12:19 ` [PATCH 2/3] [gdb/contrib] Handle DW_FORM_data16 " Tom de Vries
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Tom de Vries @ 2026-03-09 12:19 UTC (permalink / raw)
To: gdb-patches
I ran gdb/contrib/dwarf-to-dwarf-assembler.py on a hello world executable, and
ran into:
...
Traceback (most recent call last):
File "dwarf-to-dwarf-assembler.py", line 654, in <module>
main(sys.argv)
~~~~^^^^^^^^^^
File "dwarf-to-dwarf-assembler.py", line 650, in main
generator.generate()
~~~~~~~~~~~~~~~~~~^^
File "dwarf-to-dwarf-assembler.py", line 622, in generate
self.generate_die(die, indent_count)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "dwarf-to-dwarf-assembler.py", line 601, in generate_die
die_lines = die.format(self.dwarf_parser.offset_to_die, indent_count)
File "dwarf-to-dwarf-assembler.py", line 291, in format
return "\n".join(self.format_lines(offset_die_lookup, indent_count))
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "dwarf-to-dwarf-assembler.py", line 388, in format_lines
inner_lines = super().format_lines(offset_die_lookup, indent_count + 1)
File "dwarf-to-dwarf-assembler.py", line 263, in format_lines
attr_line = attr.format(
offset_die_lookup, indent_count=indent_count + 1
)
File "dwarf-to-dwarf-assembler.py", line 209, in format
s += "@" + LANG_NAME[self.value]
~~~~~~~~~^^^^^^^^^^^^
KeyError: 32769
...
The problem is that the language 0x8001 (DW_LANG_lo_user + 1) is not listed in
elftools.dwarf.enums.ENUM_DW_LANG.
This is MIPS vendor extension DW_LANG_MIPS_assembler, commonly used for
any assembly in DWARF versions that don't define a value for it (starting v6,
there's DW_LANG_Assembly).
Fix the generic case by emitting:
...
DW_AT_language 32769 DW_FORM_sdata
...
and this specific case by emitting:
...
DW_AT_language @DW_LANG_Mips_Assembler
...
---
gdb/contrib/dwarf-to-dwarf-assembler.py | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/gdb/contrib/dwarf-to-dwarf-assembler.py b/gdb/contrib/dwarf-to-dwarf-assembler.py
index 3efaf0dc85d..ca4c7696835 100755
--- a/gdb/contrib/dwarf-to-dwarf-assembler.py
+++ b/gdb/contrib/dwarf-to-dwarf-assembler.py
@@ -206,7 +206,13 @@ class DWARFAttribute:
s += " "
if self.name == "DW_AT_language" and isinstance(self.value, int):
- s += "@" + LANG_NAME[self.value]
+ if LANG_NAME.get(self.value) is None:
+ if self.value == 0x8001:
+ s += "@DW_LANG_Mips_Assembler"
+ else:
+ s += str(self.value) + " DW_FORM_sdata"
+ else:
+ s += "@" + LANG_NAME[self.value]
elif self.name == "DW_AT_encoding" and isinstance(self.value, int):
s += "@" + ATE_NAME[self.value]
else:
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/3] [gdb/contrib] Handle DW_FORM_data16 in dwarf-to-dwarf-assembler.py
2026-03-09 12:19 [PATCH 0/3] [gdb/contrib] Some dwarf-to-dwarf-assember.py fixes Tom de Vries
2026-03-09 12:19 ` [PATCH 1/3] [gdb/contrib] Handle DW_LANG_Mips_Assembler in dwarf-to-dwarf-assembler.py Tom de Vries
@ 2026-03-09 12:19 ` Tom de Vries
2026-03-09 12:19 ` [PATCH 3/3] [gdb/contrib] Avoid NotImplementedError " Tom de Vries
2026-03-09 14:10 ` [PATCH 0/3] [gdb/contrib] Some dwarf-to-dwarf-assember.py fixes Tom Tromey
3 siblings, 0 replies; 7+ messages in thread
From: Tom de Vries @ 2026-03-09 12:19 UTC (permalink / raw)
To: gdb-patches
I ran gdb/contrib/dwarf-to-dwarf-assembler.py on testsuite executable
gdb.ada/task_bp/foo, and ran into:
...
Traceback (most recent call last):
File "dwarf-to-dwarf-assembler.py", line 660, in <module>
main(sys.argv)
~~~~^^^^^^^^^^
File "dwarf-to-dwarf-assembler.py", line 656, in main
generator.generate()
~~~~~~~~~~~~~~~~~~^^
File "dwarf-to-dwarf-assembler.py", line 628, in generate
self.generate_die(die, indent_count)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "dwarf-to-dwarf-assembler.py", line 607, in generate_die
die_lines = die.format(self.dwarf_parser.offset_to_die, indent_count)
File "dwarf-to-dwarf-assembler.py", line 297, in format
return "\n".join(self.format_lines(offset_die_lookup, indent_count))
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "dwarf-to-dwarf-assembler.py", line 394, in format_lines
inner_lines = super().format_lines(offset_die_lookup, indent_count + 1)
File "dwarf-to-dwarf-assembler.py", line 285, in format_lines
child_lines = child.format_lines(
offset_die_lookup, indent_count=indent_count + 1
)
File "dwarf-to-dwarf-assembler.py", line 269, in format_lines
attr_line = attr.format(
offset_die_lookup, indent_count=indent_count + 1
)
File "dwarf-to-dwarf-assembler.py", line 219, in format
s += self._format_value(offset_die_lookup)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "dwarf-to-dwarf-assembler.py", line 173, in _format_value
raise NotImplementedError(f"Unknown data type: {type(self.value)}")
NotImplementedError: Unknown data type: <class 'elftools.construct.lib.container.ListContainer'>
...
when trying to print the DW_FORM_data16 constant for this upper bound:
...
<1><3af88>: Abbrev Number: 47 (DW_TAG_subrange_type)
<3af89> DW_AT_lower_bound : 0
<3af89> DW_AT_upper_bound : 0xffffffffffffffffffffffffffffffff
<3af99> DW_AT_name : system__put_images__lll_integer_images__unsigned_typeXn
...
Fix this by handling elftools.construct.lib.container.ListContainer.
---
gdb/contrib/dwarf-to-dwarf-assembler.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/gdb/contrib/dwarf-to-dwarf-assembler.py b/gdb/contrib/dwarf-to-dwarf-assembler.py
index ca4c7696835..91e868da998 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.construct.lib.container import ListContainer
from elftools.dwarf.compileunit import CompileUnit as RawCompileUnit
from elftools.dwarf.die import DIE as RawDIE
from elftools.dwarf.die import AttributeValue
@@ -169,6 +170,8 @@ class DWARFAttribute:
return self._format_str(self.value.decode("ascii"))
elif isinstance(self.value, str):
return self._format_str(self.value)
+ elif isinstance(self.value, ListContainer):
+ return "0x" + "".join(format(i, "x") for i in self.value)
else:
raise NotImplementedError(f"Unknown data type: {type(self.value)}")
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/3] [gdb/contrib] Avoid NotImplementedError in dwarf-to-dwarf-assembler.py
2026-03-09 12:19 [PATCH 0/3] [gdb/contrib] Some dwarf-to-dwarf-assember.py fixes Tom de Vries
2026-03-09 12:19 ` [PATCH 1/3] [gdb/contrib] Handle DW_LANG_Mips_Assembler in dwarf-to-dwarf-assembler.py Tom de Vries
2026-03-09 12:19 ` [PATCH 2/3] [gdb/contrib] Handle DW_FORM_data16 " Tom de Vries
@ 2026-03-09 12:19 ` Tom de Vries
2026-03-09 14:10 ` [PATCH 0/3] [gdb/contrib] Some dwarf-to-dwarf-assember.py fixes Tom Tromey
3 siblings, 0 replies; 7+ messages in thread
From: Tom de Vries @ 2026-03-09 12:19 UTC (permalink / raw)
To: gdb-patches
The previous commit mentions:
...
File "dwarf-to-dwarf-assembler.py", line 173, in _format_value
raise NotImplementedError(f"Unknown data type: {type(self.value)}")
NotImplementedError: Unknown data type: <class 'elftools.construct.lib.container.ListContainer'>
...
While the NotImplementedError makes its point clear, it's unhelpful in two ways:
- it's hard to find out what part of the input causes the error, and
- it may be that the user is not interested at all in the bit triggering the
error, but some part after it, and the error prevents the user from seeing it
Fix this by returning an error string instead of raising an error, resulting in this output:
...
DW_AT_upper_bound Unknown data type: <class 'elftools.construct.lib.container.ListContainer'>: \
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255] DW_FORM_data16
...
---
gdb/contrib/dwarf-to-dwarf-assembler.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/contrib/dwarf-to-dwarf-assembler.py b/gdb/contrib/dwarf-to-dwarf-assembler.py
index 91e868da998..4832c6c8cb1 100755
--- a/gdb/contrib/dwarf-to-dwarf-assembler.py
+++ b/gdb/contrib/dwarf-to-dwarf-assembler.py
@@ -173,7 +173,7 @@ class DWARFAttribute:
elif isinstance(self.value, ListContainer):
return "0x" + "".join(format(i, "x") for i in self.value)
else:
- raise NotImplementedError(f"Unknown data type: {type(self.value)}")
+ return f"Unknown data type: {type(self.value)}: {self.value}"
def format(
self, offset_die_lookup: dict[int, "DWARFDIE"], indent_count: int = 0
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] [gdb/contrib] Handle DW_LANG_Mips_Assembler in dwarf-to-dwarf-assembler.py
2026-03-09 12:19 ` [PATCH 1/3] [gdb/contrib] Handle DW_LANG_Mips_Assembler in dwarf-to-dwarf-assembler.py Tom de Vries
@ 2026-03-09 14:10 ` Tom Tromey
2026-03-09 15:25 ` Tom de Vries
0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2026-03-09 14:10 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> Fix the generic case by emitting:
Tom> ...
Tom> DW_AT_language 32769 DW_FORM_sdata
Tom> ...
Tom> and this specific case by emitting:
Tom> ...
Tom> DW_AT_language @DW_LANG_Mips_Assembler
Thanks, this is ok.
I wonder if this is worth filing as a bug against elftools.
https://github.com/eliben/pyelftools
Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/3] [gdb/contrib] Some dwarf-to-dwarf-assember.py fixes
2026-03-09 12:19 [PATCH 0/3] [gdb/contrib] Some dwarf-to-dwarf-assember.py fixes Tom de Vries
` (2 preceding siblings ...)
2026-03-09 12:19 ` [PATCH 3/3] [gdb/contrib] Avoid NotImplementedError " Tom de Vries
@ 2026-03-09 14:10 ` Tom Tromey
3 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2026-03-09 14:10 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> I ran into trouble using dwarf-to-dwarf-assember.py on a hello world
Tom> executable, due to DW_LANG_MIPS_assembler.
Tom> The first patch fixes this.
Tom> I then tested the script on the executables generated by the testsuite, and ran into
Tom> DW_FORM_data16 being unsupported.
Tom> The second patch fixes that.
Tom> The third patch removes the only raise from the script, preferring imperfect
Tom> to partial output.
This all seems reasonable to me.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] [gdb/contrib] Handle DW_LANG_Mips_Assembler in dwarf-to-dwarf-assembler.py
2026-03-09 14:10 ` Tom Tromey
@ 2026-03-09 15:25 ` Tom de Vries
0 siblings, 0 replies; 7+ messages in thread
From: Tom de Vries @ 2026-03-09 15:25 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 3/9/26 3:10 PM, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
>
> Tom> Fix the generic case by emitting:
> Tom> ...
> Tom> DW_AT_language 32769 DW_FORM_sdata
> Tom> ...
> Tom> and this specific case by emitting:
> Tom> ...
> Tom> DW_AT_language @DW_LANG_Mips_Assembler
>
> Thanks, this is ok.
>
> I wonder if this is worth filing as a bug against elftools.
> https://github.com/eliben/pyelftools
Hi,
thanks for the reviews, I've committed the series and filed an issue (
https://github.com/eliben/pyelftools/issues/632 ).
- Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-03-09 15:26 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-09 12:19 [PATCH 0/3] [gdb/contrib] Some dwarf-to-dwarf-assember.py fixes Tom de Vries
2026-03-09 12:19 ` [PATCH 1/3] [gdb/contrib] Handle DW_LANG_Mips_Assembler in dwarf-to-dwarf-assembler.py Tom de Vries
2026-03-09 14:10 ` Tom Tromey
2026-03-09 15:25 ` Tom de Vries
2026-03-09 12:19 ` [PATCH 2/3] [gdb/contrib] Handle DW_FORM_data16 " Tom de Vries
2026-03-09 12:19 ` [PATCH 3/3] [gdb/contrib] Avoid NotImplementedError " Tom de Vries
2026-03-09 14:10 ` [PATCH 0/3] [gdb/contrib] Some dwarf-to-dwarf-assember.py fixes Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox