microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.46k stars 1.53k forks source link

debugger cannot show chinese characters from a string variable #5712

Open dreamer2q opened 4 years ago

dreamer2q commented 4 years ago
#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)
WardenGnaw commented 4 years ago

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.

zyt19803293899 commented 2 years ago

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.

uhavemyword commented 1 month ago

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...