Wednesday, March 10, 2021

gdb print wchar_t *

wchar.gdb

define wchar_print 
        echo "

        set $i = 0
        while (1 == 1)
            set $c = (char)(($arg0)[$i++])
            if ($c == '\0')
                loop_break
            end
            printf "%c", $c
        end

        echo "\n
end


$ gdb -x wchar.gdb  ./myprogram
> wchar_print  mywidevar

or with modern gdb

> set target-wide-charset UTF-16
> p (wchar_t*) mywidevar


Source: https://www.generacodice.com/en/articolo/370005/How-can-I-display-Unicode-strings-while-debugging-on-linux

No comments:

Blog Archive