Go Func Stack

go函数调用过程分析 对go的简单函数调用过程通过GDB调试的方式分析一下,查看一下函数的栈帧变化情况。 源代码 源代码: package main func add(a, b int) (int, int) { c := 3 c = c + 1 return a + b, b - a } func main() { add(1, 2) } // GOOS=linux GOARCH=amd64 go build -gcflags=all="-N -l" a.go gdb调试开始 进入gdb调试 通过gdb a进入gdb调试 gdb a (gdb) info files Symbols from "/home/qraffa/gopkg/a". Local exec file: `/home/qraffa/gopkg/a', file type elf64-x86-64. Entry point: 0x465860 0x0000000000401000 - 0x0000000000467907 is .text 0x0000000000468000 - 0x00000000004884a6 is ....

January 26, 2021 · 3 min · Theme PaperMod