dlv version)?1.4.0go version)?1.14linux/amd64Is there a way to retrieve the name of the go module of the debug program launched through dlv?
The infomation of the go module would not be generated into debug section.
ps: We can fetch all file name of source code if exectuate with optimizations and inlining disabled.
I think you can do it by printing the information stored for the runtime, see how it works here https://golang.org/cl/144220
I guess you can invoke the same ReadBuildInfo function?
Disclaimer, I haven't tried this yet.
The name of the module is always main. You can find out its compile-time directory path by using objdump and looking for main's compile unit. The import path can be extracted by parsing p runtime.modinfo[16:].
@aarzilli For example, in this Go folder, the go.mod has module frontend. From a breakpoint set in the main.go file, how do I get this frontend name?
If you have access to the source code the go list command will provide the information about the module in "Module" field.
$ go list -m -f '{{.Dir}} {{.Path}}'
/Users/hakim/projects/cloud-code-samples/golang/go-guestbook/src/frontend frontend
Or even you can just parse the go.mod file :-)
If you don't have access to the source code
go version -m <binary> is convenient. $ go version -m frontend
frontend: go1.14.5
path frontend
mod frontend (devel)
runtime.modinfo[16:] is one option. Plain text, new line separated.(dlv) p runtime.modinfo[16:]
"path\tfrontend\nmod\tfrontend\t(devel)\t\n�2C1�\x18 r\x00�B\x10A\x16��...+-10 more"
Thanks @hyangah! I'll use p runtime.modinfo[16:].
Most helpful comment
If you have access to the source code the
go listcommand will provide the information about the module in "Module" field.Or even you can just parse the
go.modfile :-)If you don't have access to the source code
go version -m <binary>is convenient.runtime.modinfo[16:]is one option. Plain text, new line separated.