From 1cf67b8f1ad070d453ad705f68eb9dbdf8cc9a4d Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sat, 4 Jan 2025 13:07:13 -0600 Subject: [PATCH] Add Configure Max String Print Length For Delve as a Go TIL --- README.md | 3 +- ...igure-max-string-print-length-for-delve.md | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 go/configure-max-string-print-length-for-delve.md diff --git a/README.md b/README.md index e4c0a24..065fcff 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1556 TILs and counting..._ +_1557 TILs and counting..._ See some of the other learning resources I work on: - [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators) @@ -411,6 +411,7 @@ See some of the other learning resources I work on: - [Build For A Specific OS And Architecture](go/build-for-a-specific-os-and-architecture.md) - [Check If Cobra Flag Was Set](go/check-if-cobra-flag-was-set.md) - [Combine Two Slices](go/combine-two-slices.md) +- [Configure Max String Print Length For Delve](go/configure-max-string-print-length-for-delve.md) - [Connect To A SQLite Database](go/connect-to-a-sqlite-database.md) - [Create A Slice From An Array](go/create-a-slice-from-an-array.md) - [Detect If Stdin Comes From A Redirect](go/detect-if-stdin-comes-from-a-redirect.md) diff --git a/go/configure-max-string-print-length-for-delve.md b/go/configure-max-string-print-length-for-delve.md new file mode 100644 index 0000000..7e39582 --- /dev/null +++ b/go/configure-max-string-print-length-for-delve.md @@ -0,0 +1,29 @@ +# Configure Max String Print Length For Delve + +During a [Delve](https://github.com/go-delve/delve) debugging session, we can +print out the value of a given variable with the `print` command. Similarly, we +can see the values of all local variables with the `locals` command. + +Whenever Delve is printing out strings and slices, it will truncate what it +displays to 64 characters (or items) by default. + +```go +(dlv) print diagnostics.Solutions[0] +"295743861\n431865972\n876192543\n387459216\n612387495\n549216738\n7635...+25 more" +``` + +This can be overridden by [changing the `config` of +`max-string-len`](https://github.com/derekparker/delve/blob/237c5026f40e38d2dd6f62a7362de7b25b00c1c7/Documentation/cli/expr.md?plain=1#L59) +to something longer. In my case here, all I need are about 90 characters to +display my full string, so run `config max-string-len 90` from the `dlv` +session. + +```go +(dlv) config max-string-len 90 +(dlv) print diagnostics.Solutions[0] +"295743861\n431865972\n876192543\n387459216\n612387495\n549216738\n763524189\n928671354\n154938627" +``` + +Now I can see the entire string instead of the truncated version. + +[source](https://stackoverflow.com/a/52416264/535590)