当PuTTY终端设置为使用UTF-8时,gdb --tui无法使用正确的行显示边框

Lon*_*ner 10 putty gdb character-encoding

问题

我使用PuTTY登录远程CentOS系统,并使用g ++和gdb进行开发.我的PuTTY设置为将终端输出解释为UTF-8并相应地渲染它.此设置配置如下.

在此输入图像描述

在调试时gdb --tui我发现源代码窗格周围的边框没有用线条正确绘制.它看起来像终端字符编码问题.

终端能够正确显示Unicode字符.以下是一些示例输出:

[root@gel ~]# python -c "print u'\u2665'"
?
[root@gel ~]# printf "\xe2\x99\xa5\n"
?
Run Code Online (Sandbox Code Playgroud)

这是我的终端设置:

[root@gel ~]# echo $LANG
en_US.UTF-8
[root@gel ~]# echo $LC_CTYPE

[root@gel ~]# locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
[root@gel ~]# echo $TERM
xterm
Run Code Online (Sandbox Code Playgroud)

然而,当我启动gdb -tui

   lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
   x                                                                           x
   x                                                                           x
   x                                                                           x
   x                                                                           x
   x                                                                           x
   x                                                                           x
   x             [ No Source Available ]                                       x
   x                                                                           x
   x                                                                           x
   x                                                                           x
   x                                                                           x
   x                                                                           x
   x                                                                           x
   mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
None No process In:                                           Line: ??   PC: ??
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
---Type <return> to continue, or q <return> to quit---
Run Code Online (Sandbox Code Playgroud)

您可以看到源代码窗格周围的边框是用q和x绘制的.

如何解决此问题,以便gdb -tui输出使用正确的线条绘制边框?

解决方法

现在,我正在解决这个问题,通过配置PuTTY将终端数据解释为ISO-8859-1,如下所示.使用此设置,终端输出如下所示.

在此输入图像描述

[root@gel ~]# python -c "print u'\u2665'"
â¥
[root@gel ~]# printf "\xe2\x99\xa5\n"
â¥
Run Code Online (Sandbox Code Playgroud)

使用此设置gdb --tui输出看起来正确.

   ?????????????????????????????????????????????????????????????????????????????
   ?                                                                           ?
   ?                                                                           ?
   ?                                                                           ?
   ?                                                                           ?
   ?                                                                           ?
   ?                                                                           ?
   ?             [ No Source Available ]                                       ?
   ?                                                                           ?
   ?                                                                           ?
   ?                                                                           ?
   ?                                                                           ?
   ?                                                                           ?
   ?                                                                           ?
   ?????????????????????????????????????????????????????????????????????????????
None No process In:                                           Line: ??   PC: ??
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
---Type <return> to continue, or q <return> to quit---
Run Code Online (Sandbox Code Playgroud)

Sha*_*ing 5

根据这个答案(链接在@jpe 的评论中),问题在于“某些终端模拟器(例如 Putty)在 UTF-8 模式下不遵守 ACS 控制序列”。这提出了两种可能的解决方案:

  1. 使 PuTTY 脱离 UTF-8 模式。这似乎是您的解决方法的效果。

  2. 停止 GDB 使用 ACS 控制序列。根据文档,这可以通过命令来完成set tui border-kind ascii。文档没有说明这个命令必须在进入 TUI 模式之前给出。