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

C++ debugging character arrays and strings: <error reading variable> and "Converting character sets: Invalid argument."

Open georgetian3 opened this issue 3 years ago • 8 comments

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:

bad

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:

good

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:

  1. Create a character array in C++ file
  2. Start debugging

The issue still persists after disabling all extensions apart from the C/C++ tools extension.

georgetian3 avatar Jan 15 '21 10:01 georgetian3

Does the machine that are not displaying the characters have python installed? GDB visualizers are dependent on python.

WardenGnaw avatar Jan 15 '21 19:01 WardenGnaw

Python 3.9.0 is installed and is in PATH.

georgetian3 avatar Jan 16 '21 05:01 georgetian3

Hi. I have the same problem with python 3.8 in PATH. Is there a workaround?

alanlivio avatar Mar 14 '21 22:03 alanlivio

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

alanlivio avatar Mar 14 '21 23:03 alanlivio

That seems to have been the issue, problem solved, thank you!

georgetian3 avatar Mar 16 '21 01:03 georgetian3

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.

alanlivio avatar Mar 16 '21 17:03 alanlivio

That's true, I'll reopen and hope they'll be able to have a look.

georgetian3 avatar Mar 17 '21 02:03 georgetian3

I had the same issue and this stackoverflow answer solved the problem perfectly

void-ecs avatar Aug 04 '22 10:08 void-ecs

Summary of the solutions:

  1. Turn off Unicode UTF-8 on Windows
  2. 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!

legends2k avatar Nov 03 '22 12:11 legends2k

Summary of the solutions:

  1. Turn off Unicode UTF-8 on Windows
  2. 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!

Thanks for your awesome answer! If combining 1 (turn on) and 2 (enable) together, the result is amazing! (fixed 2 bugs simultaneously)

Pika-Lee avatar Mar 19 '23 07:03 Pika-Lee