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 2/3] [gdb/contrib] Fix UnicodeDecodeError in dwarf-to-dwarf-assembler.py
Date: Mon,  8 Jun 2026 14:54:19 +0200	[thread overview]
Message-ID: <20260608125420.2318026-3-tdevries@suse.de> (raw)
In-Reply-To: <20260608125420.2318026-1-tdevries@suse.de>

When running dwarf-to-dwarf-assembler.py on outputs/gdb.rust/unicode/unicode,
I run into a UnicodeDecodeError for (using readelf -w):
...
 <4><9cf>: Abbrev Number: 10 (DW_TAG_variable)
    <9d3>   DW_AT_name        : (indirect string, offset: 0xab4): 𝕯
...
or more explicit using llvm-dwarfdump -v:
...
0x000009cf:         DW_TAG_variable [10]   (0x000009c2)
                      DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000ab4] \
                                                  = "\360\235\225\257")
...

Fix this by printing:
...
                        DW_TAG_variable {
			    ...
                            DW_AT_name "\xf0\x9d\x95\xaf" DW_FORM_strp
...

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33970
---
 gdb/contrib/dwarf-to-dwarf-assembler.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gdb/contrib/dwarf-to-dwarf-assembler.py b/gdb/contrib/dwarf-to-dwarf-assembler.py
index fa32bc4bbab..c1818f9fdb8 100755
--- a/gdb/contrib/dwarf-to-dwarf-assembler.py
+++ b/gdb/contrib/dwarf-to-dwarf-assembler.py
@@ -174,7 +174,14 @@ class DWARFAttribute:
             else:
                 return str(self.value)
         elif isinstance(self.value, bytes):
-            return self._format_str(self.value.decode("ascii"))
+            try:
+                return self._format_str(self.value.decode("ascii"))
+            except UnicodeDecodeError:
+                # Print the data as a string in "\x01\x02\x03\x04" format.
+                result = ""
+                for byte in self.value:
+                    result += f"\\x{byte:02x}"
+                return '"' + result + '"'
         elif isinstance(self.value, str):
             return self._format_str(self.value)
         elif isinstance(self.value, ListContainer):
-- 
2.51.0


  parent reply	other threads:[~2026-06-08 12:56 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 ` Tom de Vries [this message]
2026-06-09 17:07   ` [PATCH 2/3] [gdb/contrib] Fix UnicodeDecodeError " Tom Tromey
2026-06-10  9:12     ` Tom de Vries
2026-06-08 12:54 ` [PATCH 3/3] [gdb/contrib] Fix ELFParseError " Tom de Vries
2026-06-08 13:18   ` 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-3-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