What version of Delve are you using (dlv version)?
1.2.0
What version of Go are you using? (go version)?
go1.11.6 linux/amd64 and go1.12.1 darwin/amd64
What operating system and processor architecture are you using?
linux/amd64 and darwin/amd64
What did you do?
I want to print interface.tab for iface and interface._type for eface and I failed, however gdb can do the job
What did you expect to see?
see tab and _type value
What did you see instead?
I see this
(dlv) p i.tab
Command failed: i has no member tab
$cat main.go
package main
func main() {
var a int = 1
var i interface{}
i = a
_ = i
}
$ dlv debug main.go
...
(dlv) p i
interface {}(int) 1
(dlv) p i._type
Command failed: i (type int) is not a struct
I declear i as an interface which underlay is eface type, I want to display the eface member value, but I failed.
If you want to see an interface variable as its underlying runtime struct type you have to manually cast to either runtime.iface or runtime.eface:
(dlv) p *((*runtime.eface)(uintptr(&i)))
runtime.eface {
_type: *runtime._type {
size: 8,
ptrdata: 0,
hash: 4149441018,
tflag: tflagUncommon|tflagExtraStar|tflagNamed (7),
align: 8,
fieldalign: 8,
kind: 2,
alg: *(*runtime.typeAlg)(0x4c3050),
gcdata: *1,
str: 775,
ptrToThis: 30080,},
data: unsafe.Pointer(0xc000038770),}
It's inconvenient but it's also rarely useful compared to having member access autodereference interfaces.
If you want to see an interface variable as its underlying runtime struct type you have to manually cast to either runtime.iface or runtime.eface:
(dlv) p *((*runtime.eface)(uintptr(&i))) runtime.eface { _type: *runtime._type { size: 8, ptrdata: 0, hash: 4149441018, tflag: tflagUncommon|tflagExtraStar|tflagNamed (7), align: 8, fieldalign: 8, kind: 2, alg: *(*runtime.typeAlg)(0x4c3050), gcdata: *1, str: 775, ptrToThis: 30080,}, data: unsafe.Pointer(0xc000038770),}It's inconvenient but it's also rarely useful compared to having member access autodereference interfaces.
I got it, thank you very very much!
Most helpful comment
If you want to see an interface variable as its underlying runtime struct type you have to manually cast to either runtime.iface or runtime.eface:
It's inconvenient but it's also rarely useful compared to having member access autodereference interfaces.