gdb support for wide char

Yifan Wang
Mon Oct 13 08:56:00 GMT 2008

Thanks Tom.

I already have wrote a patch to make c/c++ support fixed length
characters(u8, u16, u32).
and now i am working on utf8 which is not fixed length character.
The solution rely on the glibc functions, eg.mbstowcs(), iconv(), to
support wide character.

I dont know whether this solution is good enough, because it does not
support other programming language
and it rely on the glibc functions.


2008/10/1 Tom Tromey <>:
>>>>>> "Yifan" == Yifan Wang <> writes:
> Yifan> in gdb, i usually use "p" or "x /s" to print strings in my
> Yifan> program.  But the problem is, when i write some program for
> Yifan> non-english user, i usually use utf-8 or utf-16 strings. gdb
> Yifan> can not print those string properly.  so i want to write a
> Yifan> patch to gdb so that gdb can support printing utf strings.
> Yifan> I am not familar with the gdb source files, can someone give
> Yifan> some ideas about where i should start and which part of the
> Yifan> source files cover the topic?  Any hints or ideas are great
> gdb has an idea about the host and target charsets.  Unfortunately it
> does not understand very many encodings.
> You could start by looking at charset.c.  I think it needs an API
> overhaul to work with "more complicated" character set encodings,
> though offhand I don't recall whether UTF-8 fits into that category.
> If you are on a system with a nice iconv (anything using glibc at
> least), you could make charset.c handle just about anything.  This
> would let you do:
>    set target-charset UTF-8
>    print str
> If your host isn't using glibc, I would suggest investigating the use
> of libiconv, rather than continuing down the current path of
> charset.c.
> There are actually a few other missing features in this area.  I think
> gdb should probably also have a "wide target charset", for programs
> using wchar_t.  And, with the new UTF strings stuff in GCC, perhaps a
> "/u" format to "p" would be appropriate.
> Tom

More information about the Gdb mailing list