delve can't print interface inner member except `data` property

Created on 29 Apr 2019  路  2Comments  路  Source: go-delve/delve

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

  2. What version of Go are you using? (go version)?
    go1.11.6 linux/amd64 and go1.12.1 darwin/amd64

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

  4. 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

  5. What did you expect to see?
    see tab and _type value

  6. What did you see instead?
    I see this

(dlv) p i.tab
Command failed: i has no member tab

example code

$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.

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:

(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.

All 2 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ramya-rao-a picture ramya-rao-a  路  3Comments

derekparker picture derekparker  路  6Comments

runningbar picture runningbar  路  4Comments

kdeenanauth picture kdeenanauth  路  5Comments

luminacious picture luminacious  路  5Comments