Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/3] [gdb/contrib] Handle DW_LANG_Mips_Assembler in dwarf-to-dwarf-assembler.py
Date: Mon,  9 Mar 2026 13:19:28 +0100	[thread overview]
Message-ID: <20260309121930.3098744-2-tdevries@suse.de> (raw)
In-Reply-To: <20260309121930.3098744-1-tdevries@suse.de>

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


  reply	other threads:[~2026-03-09 12:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-03-09 14:10   ` [PATCH 1/3] [gdb/contrib] Handle DW_LANG_Mips_Assembler in dwarf-to-dwarf-assembler.py 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

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=20260309121930.3098744-2-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