#if 0
代码文件为UTF-8,终端也为UTF-8,GDB的中文显示仍为乱码,可用此函数打印含中文字符串的变量;
程序代码: pS="中文";
(gdb) call ShowStr(pS)
#endif
//gdb中打印中文;
void ShowStr(const char *pS)
{
if(pS) {
char c=*pS;
int i=0;
while(c) {
i=0;
do {
++i; //一个UTF-8字符有多少个字节;
} while(c&(0x100>>i));
fprintf(stdout, "%.*s", i, pS);
pS+=i;
c=*pS;
}
fprintf(stdout, "\n");
//fflush(stdout);
}
}