package main import "fmt" func ifacePrint(a interface{}) { fmt.Println(a) } func main() { ifacePrint("Habrahabr") }
(gdb) b main.ifacePrint Breakpoint 1 at 0x401000: file /tmp/main.go, line 5.
(gdb) run Starting program: /tmp/main [New LWP 4892] [New LWP 4893] [New LWP 4894] [New LWP 4895] Breakpoint 1, main.ifacePrint (a=...) at /tmp/main.go:5 5 func ifacePrint(a interface{}) {
(gdb) whatis a type = interface {}
(gdb) pa $1 = {_type = 0x4b8e00, data = 0xc8200761b0}
// type EmptyInterface struct { __type_descriptor *TypeDescriptor // - __object uintptr // } // - type TypeDescriptor struct { kind uint8 // , ID align uint8 // fieldAlign uint8 // ( ) size uintptr // hash uint32 hashfn uint32 //TODO equalfn uint32 //TODO gc uintptr //TODO string *string // ("string", "int") uncommonType *Uncommon // ptrToThis *TypeDescriptor // } // type Uncommon struct { name *string // pkgPath *string // , methods uintptr //TODO , }
(gdb) p *a._type $7 = {size = 16, ptrdata = 8, hash = 3774831796, _unused = 0 '\000', align = 8 '\b', fieldalign = 8 '\b', kind = 24 '\030', alg = 0x582860 <runtime.algarray+224>, gcdata = 0x52a3ac "\001\002\003\004\005\006\a\b\t\n\r\016\017\020\022\025\026\031\032\033\037,568<?AUr~\236\237\325\365\370\377", _string = 0x50e5e0, x = 0x4b8e40, ptrto = 0x4b1ba0}
(gdb) p a._type._string $11 = (struct string *) 0x50e5e0 (gdb) p *a._type._string $12 = 0x4fdfb0 "string" (gdb) p *a._type.x $13 = {name = 0x50e5e0, pkgpath = 0x0, mhdr = {array = 0x4b8e68, len = 0, cap = 0}} (gdb) p *a._type.x.name $14 = 0x4fdfb0 "string" (gdb) p *a._type.ptrto $15 = {size = 8, ptrdata = 8, hash = 1511480045, _unused = 0 '\000', align = 8 '\b', fieldalign = 8 '\b', kind = 54 '6', alg = 0x5827d0 <runtime.algarray+80>, gcdata = 0x52a3ac "\001\002\003\004\005\006\a\b\t\n\r\016\017\020\022\025\026\031\032\033\037,568<?AUr~\236\237\325\365\370\377", _string = 0x5045d0, x = 0x0, ptrto = 0x0} (gdb) p *a._type.ptrto._string $16 = 0x4fc2b8 "*string" (gdb) p *a._type.alg $17 = {hash = {void (void *, uintptr, uintptr *)} 0x582860 <runtime.algarray+224>, equal = {void (void *, void *, bool *)} 0x582860 <runtime.algarray+224>} (gdb) p *a._type.alg.hash $18 = {void (void *, uintptr, uintptr *)} 0x582860 <runtime.algarray+224> (gdb) p *a._type.alg.equal $19 = {void (void *, void *, bool *)} 0x582868 <runtime.algarray+232>
Source: https://habr.com/ru/post/315260/
All Articles