vscode-cpptools
vscode-cpptools copied to clipboard
C++ debugging character arrays and strings: <error reading variable> and "Converting character sets: Invalid argument."
When debugging a C++ file containing character arrays or strings, the contents of the array/string are not shown, but instead shows "<error reading variable>" for character arrays and "Converting character sets: Invalid argument." for strings. Integer arrays are not affected:
However, what puzzles me is that on a different machine but with the exact same VSCode version (1.52.1), C/C++ extension version (v1.1.3) and C++ compiler (mingw-w64 x86_64-8.1.0-posix-seh-rt_v6-rev0), and launch.json
file, the contents of the array/string appears normally:
The contents of launch.json
are given below:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
This problem has been posted elsewhere but with no solutions, as seen here and here
- VSCode Version: 1.52.1
- OS Version: Windows 10 20H2
- C/C++ extension Version: 1.1.3
Steps to Reproduce:
- Create a character array in C++ file
- Start debugging
The issue still persists after disabling all extensions apart from the C/C++ tools extension.
Does the machine that are not displaying the characters have python
installed? GDB visualizers are dependent on python
.
Python 3.9.0 is installed and is in PATH.
Hi. I have the same problem with python 3.8 in PATH. Is there a workaround?
I found a workaround in this chinese blog https://blog.csdn.net/m0_46304383/article/details/113487503 (translated with google transator). It seems a Windows 10 UTF-8 problem. I hope it can also help you @georgetian3.
The workaround is: "Windows Settings" -> "Time and Language" -> "Region" -> "Other Date -> Time and Regional Settings" -> "Change Date -> Time or Number Format" -> "Manage" -> "Change System Regional Settings" -> Uncheck "Beta version: Use Unicode UTF-8 to provide global language support" -> restart the computer
That seems to have been the issue, problem solved, thank you!
Hi @georgetian3 I happy that worked for you. 👍 But, for me, the solution is only a work around. May the @WardenGnaw and cpptools team may evaluate if it is a bug that requeres be fixed.
That's true, I'll reopen and hope they'll be able to have a look.
I had the same issue and this stackoverflow answer solved the problem perfectly
Summary of the solutions:
- Turn off Unicode UTF-8 on Windows
- Enable UTF-8 on GDB
I find (2) to be better. Create a .gdbinit
with set charset UTF-8
and things start working. I don't use VSCode but plain GDB on MSYS2 but found this issue discussion useful. Thanks!
Summary of the solutions:
- Turn off Unicode UTF-8 on Windows
- Enable UTF-8 on GDB
I find (2) to be better. Create a
.gdbinit
withset charset UTF-8
and things start working. I don't use VSCode but plain GDB on MSYS2 but found this issue discussion useful. Thanks!
Thanks for your awesome answer! If combining 1 (turn on) and 2 (enable) together, the result is amazing! (fixed 2 bugs simultaneously)