* [PATCH] [gdb/expr] Handle iconv EINVAL better in wchar_iterator::iterate
@ 2026-11-08 11:25 Tom de Vries
2026-11-09 14:44 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2026-11-08 11:25 UTC (permalink / raw)
To: gdb-patches
PR exp/34976 reports the following problem.
Given this char* variable:
...
char *value = "abc\xe0";
...
printing it gets us:
...
$1 = 0x402004 "ab", <incomplete sequence \340>
...
We get 'a' and 'b' but not 'c'.
Fix this in wchar_iterator::iterate by handling EINVAL the same as EILSEQ and
E2BIG: if iconv converted some of the input sequence, use it.
This gets us instead:
...
$1 = 0x402004 "abc", <incomplete sequence \340>
...
Tested on aarch64-linux.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34976
---
gdb/charset.c | 9 +++++++--
gdb/testsuite/gdb.base/charset.exp | 4 ++++
gdb/testsuite/gdb.guile/scm-pretty-print.exp | 3 ++-
gdb/testsuite/gdb.python/py-prettyprint.exp | 3 ++-
4 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/gdb/charset.c b/gdb/charset.c
index 66199407a1f..4558625abf6 100644
--- a/gdb/charset.c
+++ b/gdb/charset.c
@@ -663,8 +663,13 @@ wchar_iterator::iterate (enum wchar_iterate_result *out_result,
continue;
case EINVAL:
- /* Incomplete input sequence. Let the caller know, and
- arrange for future calls to see EOF. */
+ /* Incomplete input sequence. We still might have converted a
+ character; if so, return it. */
+ if (out_avail < out_request * sizeof (gdb_wchar_t))
+ break;
+
+ /* Otherwise, let the caller know and arrange for future calls
+ to see EOF. */
*out_result = wchar_iterate_incomplete;
*ptr = m_input;
*len = m_bytes;
diff --git a/gdb/testsuite/gdb.base/charset.exp b/gdb/testsuite/gdb.base/charset.exp
index 9995021dabc..376b7ad88a2 100644
--- a/gdb/testsuite/gdb.base/charset.exp
+++ b/gdb/testsuite/gdb.base/charset.exp
@@ -519,6 +519,10 @@ foreach val {0 1 2 3 4 5 6 7 8 9 a b c d e f} {
gdb_test "print \"\\0\" \"${val}\"" " = \"\\\\000${val}\""
}
+# Regression test for PR34976.
+gdb_test {print "abc\xe0"} \
+ [string_to_regexp { = "abc", <incomplete sequence \340>}]
+
# Tests for wide- or unicode- strings. L is the prefix letter to use,
# either "L" (for wide strings), "u" (for UTF-16), or "U" (for UTF-32).
# NAME is used in the test names and should be related to the prefix
diff --git a/gdb/testsuite/gdb.guile/scm-pretty-print.exp b/gdb/testsuite/gdb.guile/scm-pretty-print.exp
index 585e2b80643..c0b4adf1e23 100644
--- a/gdb/testsuite/gdb.guile/scm-pretty-print.exp
+++ b/gdb/testsuite/gdb.guile/scm-pretty-print.exp
@@ -93,7 +93,8 @@ proc run_lang_tests {exefile lang} {
gdb_test "print estring" " = \"embedded x\\\\201\\\\202\\\\203\\\\204\""
gdb_test_no_output "guile (set! *pp-ls-encoding* \"UTF-8\")"
- gdb_test "print estring2" "\"embedded \", <incomplete sequence \\\\302>"
+ gdb_test "print estring2" \
+ [string_to_regexp {"embedded x", <incomplete sequence \302>}]
gdb_test_no_output "set guile print-stack full"
gdb_test "print hint_error" "ERROR: Invalid display hint: 42\r\nhint_error_val"
diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp
index ab31928fa77..780edf5b968 100644
--- a/gdb/testsuite/gdb.python/py-prettyprint.exp
+++ b/gdb/testsuite/gdb.python/py-prettyprint.exp
@@ -105,7 +105,8 @@ proc run_lang_tests {exefile lang} {
}
gdb_test_no_output "python pp_ls_encoding = 'UTF-8'"
- gdb_test "print estring2" "\"embedded \", <incomplete sequence \\\\302>"
+ gdb_test "print estring2" \
+ [string_to_regexp {"embedded x", <incomplete sequence \302>}]
gdb_test_no_output "set python print-stack full"
gdb_test "print hint_error" "Exception: hint failed\r\nhint_error_val"
base-commit: 819dfa7b5325656ccb58ea5f65761982bb7844e3
--
2.51.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] [gdb/expr] Handle iconv EINVAL better in wchar_iterator::iterate
2026-11-08 11:25 [PATCH] [gdb/expr] Handle iconv EINVAL better in wchar_iterator::iterate Tom de Vries
@ 2026-11-09 14:44 ` Tom Tromey
2026-11-09 15:11 ` Tom de Vries
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2026-11-09 14:44 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> Fix this in wchar_iterator::iterate by handling EINVAL the same as EILSEQ and
Tom> E2BIG: if iconv converted some of the input sequence, use it.
Thanks.
Tom> +# Regression test for PR34976.
Here if you write "PR exp/34976", Emacs will turn it into a link.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] [gdb/expr] Handle iconv EINVAL better in wchar_iterator::iterate
2026-11-09 14:44 ` Tom Tromey
@ 2026-11-09 15:11 ` Tom de Vries
0 siblings, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2026-11-09 15:11 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 11/9/26 3:44 PM, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
>
> Tom> Fix this in wchar_iterator::iterate by handling EINVAL the same as EILSEQ and
> Tom> E2BIG: if iconv converted some of the input sequence, use it.
>
> Thanks.
>
> Tom> +# Regression test for PR34976.
>
> Here if you write "PR exp/34976", Emacs will turn it into a link.
>
/me learns about M-x bug-reference-prog-mode.
I see, I made that update.
> Approved-By: Tom Tromey <tom@tromey.com>
Thanks for the review, I'll push shortly.
Thanks,
- Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-09 15:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-08 11:25 [PATCH] [gdb/expr] Handle iconv EINVAL better in wchar_iterator::iterate Tom de Vries
2026-11-09 14:44 ` Tom Tromey
2026-11-09 15:11 ` Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox