[binutils-gdb] [gdb/contrib] Fix UnicodeDecodeError in dwarf-to-dwarf-assembler.py

Tom de Vries via Gdb-cvs <[email protected]> Wed, 10 Jun 2026 09:11:58 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31431841c09357f6f598549d69d9e98b89dde08e

commit 31431841c09357f6f598549d69d9e98b89dde08e
Author: Tom de Vries <[email protected]>
Date:   Wed Jun 10 11:11:53 2026 +0200

    [gdb/contrib] Fix UnicodeDecodeError in dwarf-to-dwarf-assembler.py
    
    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 using UTF-8 instead of ascii decoding, which gets us instead:
    ...
      DW_AT_name 𝕯 DW_FORM_strp
    ...
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33970

Diff:
---
 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 d47355e0a7c..c539e5f1e2f 100755
--- a/gdb/contrib/dwarf-to-dwarf-assembler.py
+++ b/gdb/contrib/dwarf-to-dwarf-assembler.py
@@ -175,7 +175,7 @@ class DWARFAttribute:
             else:
                 return str(self.value)
         elif isinstance(self.value, bytes):
-            return self._format_str(self.value.decode("ascii"))
+            return self._format_str(self.value.decode("UTF-8", "backslashreplace"))
         elif isinstance(self.value, str):
             return self._format_str(self.value)
         elif isinstance(self.value, ListContainer):