vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

debugger cannot show chinese characters from a string variable

Open dreamer2q opened this issue 5 years ago • 5 comments

#include <bits/stdc++.h>

using namespace std;

string replace(string line, string o, string n) {
    auto i = line.find(o);
    if (i != string::npos) {
        return line.replace(i, o.length(), n);
    }
    return line;
}

int main() {
    string line;
    cout << "> ";
    while (getline(cin, line)) {
        line = replace(line, "你", "我");
        line = replace(line, "吗", "");
        line = replace(line, "?", "");
        line = replace(line, "?", "");
        cout << line << endl;
        cout << "> ";
    }
}

I try to debug these code above and input "你好吗" to line but the debugger cannot show its content properly.

It seem a matter of gdb problem, if so, what can I do to fix it?

my config is as follow

{
      "name": "desktop debug",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
      "args": [],
      "stopAtEntry": true,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": true,
      "MIMode": "gdb",
      "miDebuggerPath": "C:\\sdk\\mingw64\\mingw64\\bin\\gdb.exe",
      "setupCommands": [
        {
          "description": "为 gdb 启用整齐打印",
          "text": "-enable-pretty-printing",
          "ignoreFailures": false
        }
      ],
      "preLaunchTask": "g++.exe build active file"
}
➜ g++ --version
g++.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

➜ gdb --version
GNU gdb (GDB) 8.1
Copyright (C) 2018 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-w64-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".

plugin version

0.29.0-insiders

os version

20H2 (os  内部版本 19042.330)

dreamer2q avatar Jun 29 '20 15:06 dreamer2q

The debugger can only handle ASCII characters at the moment, if you enable engine logging. You can see that we are printing the unicode values instead of the actual UTF-8 reprensentation.

WardenGnaw avatar Jun 30 '20 18:06 WardenGnaw

How to change the encoding of the cppgdb. After I enter chcp 936, I think that I have already changed the encoding of the cppgdb. But when I press F5 and enter chcp, There is 65001 on the integrated terminal.

zyt19803293899 avatar Apr 23 '22 08:04 zyt19803293899

The debugger can only handle ASCII characters at the moment, if you enable engine logging. You can see that we are printing the unicode values instead of the actual UTF-8 reprensentation.

do you have a plan to fix this problem, it's been a long time...

uhavemyword avatar Jul 24 '24 04:07 uhavemyword

Is this the same as #918?

starball5 avatar May 27 '25 01:05 starball5

@starball5 Yes, it seems like it might be the same root issue. We could potentially close this issue as a duplicate of #918.

sean-mcmanus avatar Jun 06 '25 21:06 sean-mcmanus