Jonathan Cano
Jonathan Cano

Reputation: 87

how to get Go Delve debugger (dlv) 'display' command to show all values of a slice or map

I'm trying to use the Delve (dlv) "display" command to show the values of a slice and a map. The "print" command shows the full value but "display" only ever shows "[...]"

contrast the display and print output below

(dlv) display
0: gns = []string len: 2, cap: 2, [...]
1: chGnMap = map[string]int [...]
(dlv) p gns
[]string len: 2, cap: 2, ["ecam","site"]
(dlv) p chGnMap
map[string]int [
        "ecam": 2, 
        "site": 2, 
]
(dlv) config -list
aliases                   map[]
substitute-path           []
max-string-len            1024
max-array-values          1024
max-variable-recurse      10
disassemble-flavor        <not defined>
show-location-expr        false
source-list-line-color    <nil>
source-list-arrow-color   ""
source-list-keyword-color ""
source-list-string-color  ""
source-list-number-color  ""
source-list-comment-color ""
source-list-line-count    <not defined>
debug-info-directories    [/usr/lib/debug/.build-id]
(dlv) exit
# dlv version
Delve Debugger
Version: 1.7.2

Upvotes: 4

Views: 2780

Answers (1)

Leo Wotzak
Leo Wotzak

Reputation: 194

This doesn't entirely answer your question, but:

When you are adding your display variables display -a ..., you can reference a key in the dictionary.

See steps below:

  1. Add map w/ key supplied using display -a
  2. Show that the key currently doesn't exist
  3. The key is automatically added when the program advances

Note: I needed to append [0] to the display line because handlerHeader["Content-Type"] returns a string slice.

(dlv) args
handler = (*main.ProduceHandler)(0x14000112d10)
wri = net/http.ResponseWriter(*net/http.response) 0x14000193708
req = ("*net/http.Request")(0x14000182000)
(dlv) display -a wri.w.wr.res.handlerHeader["Content-Type"][0]
0: wri.w.wr.res.handlerHeader["Content-Type"][0] = error key not found
(dlv) print %T wri.w.wr.res.handlerHeader
net/http.Header []
(dlv) n
> main.(*ProduceHandler).ServeHTTP() ./api.go:144 (PC: 0x100984480)
   139:     switch req.Method {
   140:     case http.MethodGet:
   141:         if len(req.URL.Query()["code"]) == 0 {
   142:             log.Println("Sending entire produce database")
   143:             wri.Header().Add("Content-Type", "application/json")
=> 144:             wri.WriteHeader(http.StatusOK)
   145:             json.NewEncoder(wri).Encode(handler.DB)
   146:             return
   147:         }
   148:
   149:         c := req.URL.Query()["code"][0]
0: wri.w.wr.res.handlerHeader["Content-Type"][0] = "application/json"

Upvotes: 1

Related Questions