go-delve / delve

Delve is a debugger for the Go programming language.
MIT License
22.7k stars 2.13k forks source link

Failed to eval expression issue with field tags #1768

Closed omcnoe closed 4 years ago

omcnoe commented 4 years ago
  1. What version of Delve are you using (dlv version)? Delve Debugger Version: 1.3.2 Build: $Id: 569ccbd514fc47c8b4c521b142556867ec5e6917 $

  2. What version of Go are you using? (go version)? go version go1.13.4 windows/amd64

  3. What operating system and processor architecture are you using? windows/amd64

With the following code, try to inspect the value of the BrokenInner slice in in VSCode. It will fail & print an error message on the debug console. As far as I can tell this only happens when inspecting a slice of an anonymous struct with a tagged field. Doesn't happen if you move the slice outside the struct.

type Broken struct {
    BrokenInner []struct {
        MyField string `json:"field"`
    }
}

func main() {
    var b = Broken{
        BrokenInner: []struct {
            MyField string `json:"field"`
        }{{"test"}},
    }
    fmt.Printf("%v\n", b)
}

When I inspect the value in the VSCode debugger, I get this in console:

Failed to eval expression:  {
 "Expr": "*(*\"struct { MyField string \"json:\\\"field\\\"\" }\")(824634008048)",
 "Scope": {
  "goroutineID": -1,
  "frame": 0
 },
 "Cfg": {
  "followPointers": true,
  "maxVariableRecurse": 1,
  "maxStringLen": 64,
  "maxArrayValues": 64,
  "maxStructFields": -1
 }
} 

Eval error: 1:30: expected ')', found json (and 1 more errors)
Failed to evaluate expression - 1:30: expected ')', found json (and 1 more errors)
chainhelen commented 4 years ago
  1. I try to use vscode, the same issue.
    By wireshark, the "Expre" is "*(*\"struct { MyField string \"json:\\\"field\\\"\" }\")(824633786848)"

  2. The I use goland , the result is ok. By wireshark, the "Expr" is "Expr":"*(*\"struct { MyField string \\\"json:\\\\\\\"field\\\\\\\"\\\" }\")(824633786848)"

  3. Use dlv --headless. If I input p *(*"struct { MyField string \"json:\\\"field\\\"\" }")(824633786848) , the result is ok.
    By wireshark, the "Expr" is "*(*\"struct { MyField string \\\"json:\\\\\\\"field\\\\\\\"\\\" }\")(824633786848)"

Obviously escape character .Maybe the plugin in vsocde can't handle the situation, not bug in area/proc ?

chainhelen commented 4 years ago

1213

derekparker commented 4 years ago

Based on @chainhelen comment this seems like an issue with VSCode encoding.