could not attach to pid: decoding dwarf section info at offset 0x0: too short

第一次使用dlv attach,就碰到了这个莫名的问题。查了好多资料,都说是dlv版本太低,让更新dlv,,,试了,无果。
终于在derekparker/delve的issue中的一个问题找到查错思路,go build的参数?
查看编译命令:go build -o $(APP) -x -ldflags "-w -s"
参数中-ldflags "-w -s"含义:

-ldflags 'flag list'
    '-s -w': 压缩编译后的体积
    -s: 去掉符号表
    -w: 去掉调试信息,不能gdb调试了

去掉了-ldflags "-w -s"后重新编包,问题解决。

你可能感兴趣的:(golang)