我刚刚安装了最新发布的gdb--gdb7.5。当我用它调试使用utf-8编码的c++程序时,我使用命令“set charset utf-8”将gdb字符集设置为utf8 ”。但是,当我想打印字符串: char *str = "明天是个好天气"
时,“p str”结果是字符串的地址而不是内容。那么gdb调试utf8字符串需要什么东西吗?
断点1,test()位于test.cpp:6
6 char *str = "我们的世界多么美好";
(gdb)n
8 printf( "%s\n", str );
(gdb)p str
$1 = 0x40067c "0\221我们2\204265\214321016好"
(gdb) 设置字符集 UTF-8
(gdb) 显示字符集
主机字符集是“UTF-8”。 目标字符集是“UTF-8”。 目标宽字符集是“auto;当前为 UTF-32”。
(gdb)p str
$2 = 0x40067c
(gdb)
最佳答案
请准确告诉我们您做了什么,以及准确GDB 打印了什么。
使用 gdb-7.5:
Temporary breakpoint 1, main () at t.c:5
5 char *str = "明天是个好天气";
(gdb) n
6 return 0;
(gdb) p str
$1 = 0x4005cc "明天是个好天气"
(gdb) show charset
The host character set is "auto; currently UTF-8".
The target character set is "auto; currently UTF-8".
The target wide character set is "auto; currently UTF-32".
(gdb) set charset utf
Undefined item: "utf".
这表明:
- GDB 为我做了“开箱即用”的正确事情。
- 您可能没有执行
set charset utf
,而是执行了其他操作。
您在环境中的 LAN
设置相关。我的是:
$ echo $LANG
en_US.UTF-8
如果我取消设置 LANG
,我会得到:
(gdb) p str
$1 = 0x4005cc "\346\230\216\345\244\251\346\230\257\344\270\252\345\245\275\345\244\251\346\260\224"
关于utf-8 - gdb7.5打印utf8字符串显示字符串地址而不是字符串内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13671460/