Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I print the full value of a string variable in delve?

Tags:

I'm using the delve go debugger to debug some code. When I try to print a string variable, it gives me an abbreviated version.

(dlv) print myString "my string...+539 more" 

How do I get it to print the full string?

like image 378
Alex Altair Avatar asked Sep 20 '18 01:09

Alex Altair


2 Answers

The ability to configure the length of printed strings was recently added to delve. To see the full list of configuration options, run config -list;

(dlv) config -list aliases            map[] substitute-path    [] max-string-len     <not defined> max-array-values   <not defined> show-location-expr false 

The one we're interested in here is called max-string-len, which you can see is currently <not defined>. To increase the length to e.g. 1000, run

(dlv) config max-string-len 1000 

Now running print myString should print the whole string.

like image 122
Alex Altair Avatar answered Sep 23 '22 00:09

Alex Altair


Just to add to your answer, if you're using VS Code debugging feature, add the following config to your settings.json:

    "go.delveConfig": {         "dlvLoadConfig": {             "maxStringLen": 1024,         },         "apiVersion": 2,     }, 
like image 40
rustyx Avatar answered Sep 21 '22 00:09

rustyx