[binutils-gdb] [gdb/testsuite, Tcl 9.0] Fix error: invalid or incomplete multibyte or wide character

Tom de Vries via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7024087a9c9e4bd873916e74e7aa110cf3954b21

commit 7024087a9c9e4bd873916e74e7aa110cf3954b21
Author: Tom de Vries <[email protected]>
Date:   Fri Mar 20 10:13:27 2026 +0100

    [gdb/testsuite, Tcl 9.0] Fix error: invalid or incomplete multibyte or wide character
    
    With Tcl 9.0 and test-case gdb.python/py-source-styling.exp, I run into:
    ...
    ERROR: tcl error sourcing gdb.python/py-source-styling.exp.
    ERROR: tcl error code POSIX EILSEQ {invalid or incomplete multibyte or wide character}
    ERROR: error reading "file8": invalid or incomplete multibyte or wide character
        while executing
    "read $fh"
        (procedure "auto_lappend_include_files_1" line 14)
    ...
    
    Fix this by using "fconfigure $fh -encoding utf-8 -profile replace" [1] in
    auto_lappend_include_files_1.  Likewise in gdb_get_line_number.
    
    Approved-By: Tom Tromey <[email protected]>
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33948
    
    [1] https://core.tcl-lang.org/tcl/wiki?name=Migrating+scripts+to+Tcl+9

Diff:
---
 gdb/testsuite/lib/gdb.exp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 5fdaa2f0ea6..218e5910ffb 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -8564,6 +8564,10 @@ proc gdb_get_line_number { text { file "" } } {
 	error "$message"
     }
 
+    if {[tcl_version_at_least 9 0 0]} {
+	fconfigure $fd -encoding utf-8 -profile replace
+    }
+
     set found -1
     for { set line 1 } { 1 } { incr line } {
 	if {[catch { set nchar [gets "$fd" body] } message]} {
@@ -11510,6 +11514,9 @@ proc auto_lappend_include_files_1 {flags source {visited {}}} {
     if {[catch {open $source r} fh err]} {
 	error "Failed to open file '$source': $err"
     }
+    if {[tcl_version_at_least 9 0 0]} {
+	fconfigure $fh -encoding utf-8 -profile replace
+    }
     set contents [read $fh]
     close $fh
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.