[PATCH][gdb] Improve "Converting character sets: Invalid argument"

Tom de Vries tdevries@suse.de
Tue Jun 7 12:16:55 GMT 2022


Hi,

When running selftest rust-lex on an openSUSE Leap 15.3 system with
glibc-locale-base and glibc-locale packages deinstalled, we run into:
...
$ gdb -q -batch -ex "maint selftest rust-lex"
Running selftest rust-lex.
Self test failed: Converting character sets: Invalid argument.
Ran 1 unit tests, 1 failed
...

The "invalid argument" is due to iconv_open returning EINVALID, meaning the
conversion is not supported by the implementation.

Make the error more informative, such that we have:
...
Self test failed: Cannot convert between character sets `ANSI_X3.4-1968' and \
  `UTF-32LE'
...

Tested on x86_64-linux.

https://sourceware.org/bugzilla/show_bug.cgi?id=29202


Any comments?

Thanks,
- Tom

[gdb] Improve "Converting character sets: Invalid argument"

---
 gdb/charset.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gdb/charset.c b/gdb/charset.c
index 74f742e0aa7..e182a67d683 100644
--- a/gdb/charset.c
+++ b/gdb/charset.c
@@ -474,7 +474,14 @@ class iconv_wrapper
   {
     m_desc = iconv_open (to, from);
     if (m_desc == (iconv_t) -1)
-      perror_with_name (_("Converting character sets"));
+      {
+	if (errno == EINVAL)
+	  throw_error (NOT_SUPPORTED_ERROR,
+		       _("Cannot convert between character sets `%s' and `%s'"),
+		       from, to);
+	else
+	  perror_with_name (_("Converting character sets"));
+      }
   }
 
   ~iconv_wrapper ()


More information about the Gdb-patches mailing list