vscode-cpptools
vscode-cpptools copied to clipboard
[CPPVSDBG] Debugger truncates long strings when inspecting values
When inspecting values in the debugger, long strings are truncated, which, for example, makes it impossible to see the rest of this exception message here:

The value is also truncated if I right-click the message on the "variables" window and click "Copy Value". The value also gets truncated in the debug console, if I try printing it there. I don't think there's currently any way to view this string without it getting truncated.
I have the latest stable of VS Code (1.21.1) and vscode-cpptools (0.16.1) installed.
Right now I'm working around this by modifying the code to print the message to std::cout before throwing, but that's obviously not ideal..
@aleksijuvani I assume you are using gdb. This looks like the default setting for gdb which is 200 characters. You can add a command to increase it to unlimited by using set print elements <size> where size is the number of elements and 0 being unlimited.
So in your launch.json, add the following block to the "setupCommands": array:
{
"text": "-interpreter-exec console \"set print elements 0\"",
"ignoreFailures": true
}
to make it unlimited.
@pieandcakes Sorry, I forgot to mention this. I'm using the cppvsdbg debugger.
Was there ever a solution to this issue? Seems like the answer above is for gdb and not cppvsdbg. The truncation is a real issue when trying to copy long strings or byte arrays in the local variables list
@pieandcakes Is there any solution? LLDB also meets this problem, this is unacceptable
@JemmyWong Any solution for truncation in cppvsdbg will be in the debugger itself and will not apply to lldb. You can try the solution for gdb for lldb
Hello @pieandcakes : Is there any update about this issue ? I've also been using CPPVSDBG for a while and still can't copy large string values. Since I'm not using GDB, I couldn't figure out any kind of parameter that would allow to extend that characters limit.
This is really annoying, since copying and analyzing data from the variables tab is one of the major features for a real-time debugger. Thanks in advance for your response !
@JoffreyAlto I haven't had time to investigate yet, but it is on my list.
@pieandcakes Any updates on this issue? :-)
Just hit this issue myself. It's pretty bad that VS Code doesn't seem to have a nice multi-line string view, but then this just makes it completely useless when debugging strings :)
run into this matter too, any update now?
Same here. cppvsdbg
Hi, Do you have any updates for this issue regarding cppvsdbg?
@pieandcakes This is an important feature that is not working, first reported in 2018, what's the status update on it, and would it be possible to prioritize this bug?
Solution that worked for me :
start debugger, in your debug console write:
-exec set print elements 1000
You can modify 1000 to any other number. 0 signifies no limit(not recommended as some variables can be nasty).

Is there a solution to this on Windows when debugging with cppvsdbg using the MSVC debugger? I am running VSCode 1.74.2 on Windows 10.
I tried the suggested solution of typing -exec set print elements 1000 into the Debug Console, after starting the debugger, but that resulted in an error:
identifier "exec" is undefined

NOTE: That I am trying to debug pure C code using the MSVC debugger components installed from Visual Studio 2019.
Any update on this issue? Any workaround for cppvsdbg?
@vijay-563 We don't have an update on this issue. One "workaround" may be to log the string value to stdout or a file.
@sean-mcmanus Any chance to prioritize this issue, a debugger should be able to inspect long strings. For me, it feels like a high-priority bug
@jay1975h I'll let the debugger team know that this bug is the most upvoted debugger bug.
To people here still looking for a resolution, since there's no update on the issue I figured out some kind of way to get copy large strings. Using the "Watch" or "Variable" tab when in debugging feature, identify the string you want to copy then click on the "View binary data" icon, at the right of the string value as showed below.

Then now the tab "memory.bin" is open, just copy your value from the "Decoded text" section using your mouse cursor or a simple click at the beginning of the string, and shift+click at the ending of your string.

Copy it, then you will be able to paste the string value to another text support. I hope it helps.
Any updates ? Please prioritize this.
Same issue here.
@pieandcakes @sean-mcmanus @vscode @Colengms
I don't understand this at all, you wrote that this is most upvoted debugger bug yet nothing happens. The bug was open Apr 4, 2018, why is not being fixed, how can the developers at Microsoft do nothing?
You are committed all kinds of useless stuff, for example -> Fix change "eg." to "e.g.". Fix the things that are important instead.
We have determined that your valuable suggestion has a broad community impact and will improve the product experience. We have added the feature to our roadmap and will keep you updated soon as we make progress. We highly appreciate your contribution in making our product better.
Fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/v1.18.0
Is this actually fixed? I still see strings truncated to ~200 characters in hovers, watch & when evaluating the string in the debug console...
VSCode: 1.88.1 CppTools: 1.19.9
@tklajnscek Are you using cppvsdbg or cppdbg? It's working for me with cppvsdbg. Are you referring to std::string? Which implemention? MSVC?
@sean-mcmanus
- cppvsdbg
- either std::string or a just a plain char*
- compiled with CMake/Ninja using MSVC 19.37.32824.0
It's literally this:
# CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(string_test)
add_executable(string_test main.cpp)
and:
// main.cpp
#include <stdio.h>
#include <string>
void main() {
std::string str = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
const char* cstr = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
printf("str: %s\n", str.c_str());
printf("cstr: %s\n", cstr);
}
@tklajnscek I see -- I was looking at the data as an array of characters and the characters are all visible in the debugger that way. I'm not sure if that is intentional or not.