29

I have been having trouble seeing the entire value of variables while debugging in Go. When I click on a rather long value, it shows me ... +# more. But I can't find a way to see the rest of that value. Even in watch mode it does the same thing, even when I click copy value it copies the ...+# more. Here is an example below. Anyone know how to see the rest of the +114 more?

"Some really really long string..+114 more"

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
coloradoman
  • 341
  • 1
  • 5
  • 11
  • Hey @coloradoman, I too faced the same issue, even copying was not helping. In this case I just used to print the variable on console using `fmt.Println`, but this is not the optimal way. I am also waiting for the answer to your question. – Deepak Patankar Jan 15 '20 at 17:06
  • 1
    You should be able to use the [delve commands](https://github.com/go-delve/delve/blob/master/Documentation/cli/README.md) in the Debug Console tab of the Terminal panel (View menu -> Debug Console if it's not already showing). – Adrian Jan 15 '20 at 17:13
  • I am still seeing +# more in the debug console tab. – coloradoman Jan 15 '20 at 17:22
  • Even using e.g. [print](https://github.com/go-delve/delve/blob/master/Documentation/cli/README.md#print)? – Adrian Jan 15 '20 at 17:23
  • 1
    Eval error: function calls not allowed without using 'call' Unable to eval expression: "function calls not allowed without using 'call'" This is what I get from trying to use print in the debug console. – coloradoman Jan 15 '20 at 18:12
  • It looks like if you're paused at a breakpoint, in the Debug Console panel you can type in the variable name to the prompt at the bottom and it'll print the full string. I just tried it with a variable holding json and it worked. No config changes. It does print it as a quoted string so my JSON had a bunch of escape sequences but at least it was all there. – Corey Ogburn Aug 25 '23 at 21:06

4 Answers4

11

You can configure delve in the vscode settings.json.

There is a parameter called "maxStringLen" you can set it to a higher value. I do not recommend setting the values to high. The debugger can get very slow if you set the maxStringLen, maxArrayValues, etc. to high. So if you play arround with these delve settings and your debugger gets slow, better chose lower values again.

Here is an example showing maxStringLen and some other possible values:

"go.delveConfig": {
    "useApiV1": false,
    "dlvLoadConfig": {
        "followPointers": true,
        "maxVariableRecurse": 3,
        "maxStringLen": 400,
        "maxArrayValues": 400,
        "maxStructFields": -1
    }
}
Tobias Theel
  • 3,088
  • 2
  • 25
  • 45
  • 2
    Where did you find these settings documented? VSCode 1.55.2 does not recognize them for the project settings (they remain greyed out and a mouse over warns about them being unrecognized). When added to my user settings there aren't any complaints but the debugger only shows the first 300 elements, reports the length of expanded arrays that are longer than 300 elements as having a len of 300. So does not work. – Jason Harrison Apr 16 '21 at 16:47
  • 2
    I have no idea where these are documented. I just typed in the settings.json and intellisense (even today) knows these options and i get suggestions to use them. They are also not greyed out. – Tobias Theel Apr 23 '21 at 12:13
7

I needed this answer for my go programming. The answer is a little different than the one provided by Tobias (perhaps I have a newer version of the debugger).

Here's how to change the length of the strings you can see in the debugger:

  1. Set up your go program for debugging (install the go extension for vs code)

  2. In your workspace, there will be a .vscode directory. In there is a file called launch.json. If one does not exist, then when you are about to launch the debugger, you can create one.

  3. Edit the launch.json file. It will have a simple JSON conf in it. Extend that JSON so that it looks like this (I extended the maximum length to 400):

    {
    // 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": "Launch Package",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${workspaceFolder}",
            "apiVersion": 2,
            "dlvLoadConfig": {
                "followPointers": true,
                "maxVariableRecurse": 1,
                "maxStringLen": 400,
                "maxArrayValues": 64,
                "maxStructFields": -1
            }
        }
        ]
    }
    
-1

I was able to dump a long variable result to the terminal using my app's native logger.
This example is for a python app, but I am sure there are flavors for other languages.

My logger was already set up in the app, so this was very simple. In the debug console, I entered:

logging.warning(f"{my_very_long_var}")

... and I got the entire result as a log entry in the terminal tab, without any of the worthless ...'s I was getting in the debug console.

Note: My logger did not dump this immediately... I had to resume out of the breakpoint before I got to see the output. That may be typical for logging.

Tom Wilson
  • 797
  • 9
  • 26
-2

Perhaps this has changed since this question was first asked a year ago, but at this time, right clicking on the truncated value in Locals or Watch window, and selecting "Copy Value" will copy the entire value which I can paste into another window.

Daemon42
  • 187
  • 2
  • 8