前言
看完raft后, 一直有计划通过看etcd进一步学习, 毕竟在生产环境中引入了etcd, 有必要对其更透彻的了解. 在调试etcd时遇到了一些梗. 这里做个记录.
问题
cannot load 系列
如
cannot load golang_org/x/net/dns/dnsmessage
原因是golang的包管理工具bug, 在参考golang uninstall完全清理干净后:
sudo rm -r /usr/local/go
再按官网golang install说明安装. 即可解决.
wget https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.13.5.linux-amd64.tar.gz
推荐在安装golang时, 不使用包管理工具, 按官网说明, 手动删除, 安装. 会更干净, 不容易出问题.
no debugging symbols found 问题
As of Go 1.11, debug information is compressed by default. Older versions of gdb, such as the one available by default on MacOS, do not understand the compression. You can generate uncompressed debug information by using go build -ldflags=-compressdwarf=false. (For convenience you can put the -ldflags option in the GOFLAGS environment variable so that you don't have to specify it each time.)
diff --git a/build b/build
index 2d2ee5c..1f6c5cb 100755
--- a/build
+++ b/build
@@ -10,6 +10,7 @@ if [[ -n "$FAILPOINTS" ]]; then
fi
# Set GO_LDFLAGS="-s" for building without symbols for debugging.
+GO_LDFLAGS="-compressdwarf=false"
步骤
go get
gopath为$HOME/go
go get github.com/etcd-io/etcd
build
~/go/src/go.etcd.io/etcd(master*) » ./build
gdb debug
~/go/src/go.etcd.io/etcd(master*) » cd bin && gdb ./etcd
在gdb中调试如下:
(gdb) b raft.go:324
Breakpoint 1 at 0xa8ae32: file /home/enjolras/go/src/go.etcd.io/etcd/raft/raft.go, line 324.
(gdb) run --listen-client-urls http://0.0.0.0:2879 --advertise-client-urls http://0.0.0.0:2879
Starting program: /home/enjolras/go/src/go.etcd.io/etcd/bin/etcd --listen-client-urls http://0.0.0.0:2879 --advertise-client-urls http://0.0.0.0:2879
Thread 1 "etcd" hit Breakpoint 1, io/etcd/raft.newRaft (c=0xc000203708, ~r1=<optimized out>) at /home/enjolras/go/src/go.etcd.io/etcd/raft/raft.go:324
324 if err := c.validate(); err != nil {
(gdb) bt
#0 io/etcd/raft.newRaft (c=0xc000203708, ~r1=<optimized out>) at /home/enjolras/go/src/go.etcd.io/etcd/raft/raft.go:324
#1 0x0000000000a9886f in io/etcd/raft.NewRawNode (config=0xc000203708, ~r1=<optimized out>, ~r2=...) at /home/enjolras/go/src/go.etcd.io/etcd/raft/rawnode.go:48
#2 0x0000000000a87543 in io/etcd/raft.RestartNode (c=0xc000203708, ~r1=...) at /home/enjolras/go/src/go.etcd.io/etcd/raft/node.go:235
#3 0x0000000000c08b92 in io/etcd/etcdserver.restartNode (cfg=..., snapshot=0x0, ~r2=<optimized out>, ~r3=<optimized out>, ~r4=..., ~r5=<optimized out>, ~r6=<optimized out>)
at /home/enjolras/go/src/go.etcd.io/etcd/etcdserver/raft.go:546
#4 0x0000000000c0e8e5 in io/etcd/etcdserver.NewServer (cfg=..., srv=<optimized out>, err=...) at /home/enjolras/go/src/go.etcd.io/etcd/etcdserver/server.go:475
#5 0x0000000000dd24ca in io/etcd/embed.StartEtcd (inCfg=0xc000278000, e=0xc000278b00, err=...) at /home/enjolras/go/src/go.etcd.io/etcd/embed/etcd.go:211
#6 0x0000000000e2a3e0 in io/etcd/etcdmain.startEtcd (cfg=0xc000278000, ~r1=<optimized out>, ~r2=<optimized out>, ~r3=...) at /home/enjolras/go/src/go.etcd.io/etcd/etcdmain/etcd.go:302
#7 0x0000000000e28dab in io/etcd/etcdmain.startEtcdOrProxyV2 () at /home/enjolras/go/src/go.etcd.io/etcd/etcdmain/etcd.go:144
#8 0x0000000000e333b7 in io/etcd/etcdmain.Main () at /home/enjolras/go/src/go.etcd.io/etcd/etcdmain/main.go:46
#9 0x0000000000e37880 in main.main () at /home/enjolras/go/src/go.etcd.io/etcd/main.go:28~~~~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。