]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/contrib] Handle unknown attribute in dwarf-to-dwarf-assembler.py
authorTom de Vries <tdevries@suse.de>
Wed, 22 Oct 2025 05:28:45 +0000 (07:28 +0200)
committerTom de Vries <tdevries@suse.de>
Wed, 22 Oct 2025 05:28:45 +0000 (07:28 +0200)
I ran gdb/contrib/dwarf-to-dwarf-assembler.py on a hello world compiled with
gcc 15, and ran into:
...
Traceback (most recent call last):
  File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 642, in <module>
    main(sys.argv)
    ~~~~^^^^^^^^^^
  File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 638, in main
    generator.generate()
    ~~~~~~~~~~~~~~~~~~^^
  File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 610, in generate
    self.generate_die(die, indent_count)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 589, 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 279, 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 376, 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 251, 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 199, in format
    s += self.name + " "
         ~~~~~~~~~~^~~~~
TypeError: unsupported operand type(s) for +: 'int' and 'str'
...
because of trying to print DWARF v6 attributes DW_AT_language_name (0x90) and
DW_AT_language_version (0x91).

Fix this by printing the number if the name is not known:
...
            {DW_AT_0x90 3 DW_FORM_data1}
            {DW_AT_0x91 202311 DW_FORM_data4}
...

gdb/contrib/dwarf-to-dwarf-assembler.py

index cf00be0e1ae8f62d12e4a434ecb61da6e18d3211..58fb6cbe549499eb6dc109206cbfdf9b171c6ec3 100755 (executable)
@@ -196,7 +196,11 @@ class DWARFAttribute:
             applicable.
         """
         s = lbrace
-        s += self.name + " "
+        if isinstance(self.name, int):
+            s += "DW_AT_" + hex(self.name)
+        else:
+            s += self.name
+        s += " "
         s += self._format_value(offset_die_lookup)
 
         # Only explicitly state form if it's not a reference.