Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redundant package prefix in anonymous struct field name #1521

Closed
nd opened this issue Mar 25, 2019 · 3 comments
Closed

Redundant package prefix in anonymous struct field name #1521

nd opened this issue Mar 25, 2019 · 3 comments

Comments

@nd
Copy link
Contributor

nd commented Mar 25, 2019

  1. What version of Delve are you using (dlv version)?

built on commit ac3b1c7

  1. What version of Go are you using? (go version)?

go version go1.12 linux/amd64

  1. What operating system and processor architecture are you using?

linux/amd64

  1. What did you do?

Printed the value of the t variable once the program reached a breakpoint:

package main

import "runtime"

func main() {
	t := struct {a string} {a: "ok"}
	runtime.Breakpoint()
	println(t.a)
}
  1. What did you expect to see?

It's type presented like this struct { a string }

  1. What did you see instead?

It's type presented like this struct { main.a string }

Notice the redundant package name prefix in the field.

Rpc log:

(dlv) p t
DEBU[0005] <- RPCServer.Eval(rpc2.EvalIn{"Scope":{"GoroutineID":-1,"Frame":0,"DeferredCall":0},"Expr":"t","Cfg":{"FollowPointers":true,"MaxVariableRecurse":1,"MaxStringLen":64,"MaxArrayValues":64,"MaxStructFields":-1}})  layer=rpc
DEBU[0005] -> *rpc2.EvalOut{"Variable":{"name":"t","addr":824634001256,"onlyAddr":false,"type":"struct { main.a string }","realType":"struct { main.a string }","flags":0,"kind":25,"value":"","len":1,"cap":0,"children":[{"name":"a","addr":824634001256,"onlyAddr":false,"type":"string","realType":"string","flags":0,"kind":24,"value":"ok","len":2,"cap":0,"children":[],"base":4678956,"unreadable":"","LocationExpr":"","DeclLine":0}],"base":0,"unreadable":"","LocationExpr":"[block] DW_OP_fbreg -0x30 ","DeclLine":6}} error: ""  layer=rpc
struct { main.a string } {a: "ok"}
@aarzilli
Copy link
Member

This is complicated. We're just printing the name of the type that's in debug_info, to remove those prefixes we'd have to parse that string and strip them. Unfortunately there's no parser for that (it looks like go, but it isn't valid go, obviously) and no formal grammar (besides the code that outputs them, somewhere in the compiler).
The name in debug_info comes from the name of the type symbol produced by the compiler, we can't change the way the compiler generates that name because it probably has a good reason to include that prefix (or maybe not? I don't know for sure). We could regenerate the name in the linker when debug_info is written but that's probably expensive and complex.
Parsing and stripping them in the debugger is probably the least-wrong answer, but I'm not sure we want all that extra complexity for a cosmetic improvement.

@aarzilli
Copy link
Member

This doesn't seem to have bothered anyone, it doesn't usually come up and the added complexity for the cosmetic fix is high. It seems we shouldn't implement it.

@ajwerner
Copy link

I feel like this is go bug, not a delve bug. I filed it here: golang/go#70963

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants