Skip to content

Commit 1cf67b8

Browse files
committed
Add Configure Max String Print Length For Delve as a Go TIL
1 parent f9c0a56 commit 1cf67b8

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1556 TILs and counting..._
13+
_1557 TILs and counting..._
1414

1515
See some of the other learning resources I work on:
1616
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
@@ -411,6 +411,7 @@ See some of the other learning resources I work on:
411411
- [Build For A Specific OS And Architecture](go/build-for-a-specific-os-and-architecture.md)
412412
- [Check If Cobra Flag Was Set](go/check-if-cobra-flag-was-set.md)
413413
- [Combine Two Slices](go/combine-two-slices.md)
414+
- [Configure Max String Print Length For Delve](go/configure-max-string-print-length-for-delve.md)
414415
- [Connect To A SQLite Database](go/connect-to-a-sqlite-database.md)
415416
- [Create A Slice From An Array](go/create-a-slice-from-an-array.md)
416417
- [Detect If Stdin Comes From A Redirect](go/detect-if-stdin-comes-from-a-redirect.md)

Diff for: go/configure-max-string-print-length-for-delve.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Configure Max String Print Length For Delve
2+
3+
During a [Delve](https://github.com/go-delve/delve) debugging session, we can
4+
print out the value of a given variable with the `print` command. Similarly, we
5+
can see the values of all local variables with the `locals` command.
6+
7+
Whenever Delve is printing out strings and slices, it will truncate what it
8+
displays to 64 characters (or items) by default.
9+
10+
```go
11+
(dlv) print diagnostics.Solutions[0]
12+
"295743861\n431865972\n876192543\n387459216\n612387495\n549216738\n7635...+25 more"
13+
```
14+
15+
This can be overridden by [changing the `config` of
16+
`max-string-len`](https://github.com/derekparker/delve/blob/237c5026f40e38d2dd6f62a7362de7b25b00c1c7/Documentation/cli/expr.md?plain=1#L59)
17+
to something longer. In my case here, all I need are about 90 characters to
18+
display my full string, so run `config max-string-len 90` from the `dlv`
19+
session.
20+
21+
```go
22+
(dlv) config max-string-len 90
23+
(dlv) print diagnostics.Solutions[0]
24+
"295743861\n431865972\n876192543\n387459216\n612387495\n549216738\n763524189\n928671354\n154938627"
25+
```
26+
27+
Now I can see the entire string instead of the truncated version.
28+
29+
[source](https://stackoverflow.com/a/52416264/535590)

0 commit comments

Comments
 (0)