关于golang:gdb-golang-查看iface-内部结构

59次阅读

共计 1500 个字符,预计需要花费 4 分钟才能阅读完成。

环境阐明

macOs bigSur 11.4
GNU gdb (GDB) 10.2

代码筹备

package main

type Ner interface {a()
    b(int)
    c(string) string
}

type N int

func (N) a() {}

func (*N) b(i int) {return}

func (*N) c(s string) string {return "c"}

func main() {
    var n N
    var t Ner = &n
    t.a()}

命令执行

go build -gcflags “-N -l” -ldflags=-compressdwarf=false main.go
gdb main

失常输入图

  1. 设置断点(在第 25 行),而后执行
(gdb) b main.go:25

Loading Go Runtime support.
(gdb) b main.go:25
Breakpoint 1 at 0x1054d98: file /Users/didi/GolandProjects/goLarnNote/Chapter7/Iface/debugGDB/main.go, line 25.
(gdb) run
Starting program: /Users/didi/GolandProjects/goLarnNote/Chapter7/Iface/debugGDB/main 
[New Thread 0x2603 of process 72590]
[New Thread 0x1a03 of process 72590]
warning: unhandled dyld version (17)
[New Thread 0x2403 of process 72590]
[New Thread 0x2507 of process 72590]
[New Thread 0x2203 of process 72590]

Thread 2 hit Breakpoint 1, main.main () at /Users/didi/GolandProjects/goLarnNote/Chapter7/Iface/debugGDB/main.go:25
25              t.a()
  1. 查看信息并打印
(gdb) info locals
t = {tab = 0x1076b60 <N,main.Ner>, data = 0xc00003c748}
n = 0
(gdb) p *t.tab 
$1 = {inter = 0x105b800 <type.*+26912>, _type = 0x105b580 <type.*+26272>, hash = 3289684567, _ = "\000\000\000", 
  fun = {16812096}}
(gdb) p *t.tab_type 
There is no member named tab_type.
(gdb) p *t.tab.inter
$2 = {typ = {size = 16, ptrdata = 16, hash = 1801897693, tflag = 7 '\a', align = 8 '\b', fieldAlign = 8 '\b', 
    kind = 20 '\024', equal = {void (void *, void *, bool *)} 0x105b818 <type.*+26936>, 
    gcdata = 0x1065b18 <func.*+254> "\002", str = 2790, ptrToThis = 9664}, pkgpath = {bytes = 0x105500a <type.*+298> ""}, mhdr = []runtime.imethod = {{name = 8, ityp = 15552}, {name = 11, 
      ityp = 16128}, {name = 14, ityp = 20288}}}

后续 todo

联合 iface,eface 的构造来分析接口判等 等系列问题

参考资料

gdb-debugger-with-go

正文完
 0