1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
| ➜ gitlab-tools git:(master) dlv debug -- project ls //编译并开始运行程序,命令行参数 project ls
Type 'help' for list of commands.
(dlv) c /*****运行程序到下一个断点处,因为没加过断点,所以程序直接运行结束了*****/
Warning: load config failed! error:config file:/Users/caiyili/.gitlab/config not exists!
254 android/maven https://git.baijiashilian.com/android/maven
Process 81002 has exited with status 0
(dlv) b root.go:53 /*****尝试给room.go第53行加断点,失败了,提示进程已经结束*****/
Process 81002 has exited with status 0
(dlv) r /*****重启程序*****/
Process restarted with PID 81007
(dlv) b root.go:53 /*****再次浓度给room.go第53行加断点,提示这个room.go文件有歧义*****/
Command failed: Location "root.go:53" ambiguous: /Users/caiyili/Code/gitlab-tools/cmd/root.go, /usr/local/go/src/crypto/x509/root.go…
(dlv) b cmd/root.go:53 /*****给cmd/root.go:53加断点*****/
Breakpoint 1 set at 0x104899fb0 for gitlab-tools/cmd.onInit() ./cmd/root.go:53
(dlv) bp /****查看所有断点*****/
Breakpoint runtime-fatal-throw (enabled) at 0x10448e2b0 for runtime.throw() /usr/local/go/src/runtime/panic.go:982 (0)
Breakpoint unrecovered-panic (enabled) at 0x10448e5c0 for runtime.fatalpanic() /usr/local/go/src/runtime/panic.go:1065 (0)
print runtime.curg._panic.arg
Breakpoint 1 (enabled) at 0x104899fb0 for gitlab-tools/cmd.onInit() ./cmd/root.go:53 (0)
(dlv) c /*****运行程序到下一个断点处******/
> gitlab-tools/cmd.onInit() ./cmd/root.go:53 (hits goroutine(1):1 total:1) (PC: 0x104899fb0)
48:
49: func onInit() {
50: if cfgPath == "" {
51: cfgPath = config.GetDefaultCfgPath()
52: }
=> 53: if err := config.LoadConfig(cfgPath); err != nil {
54: fmt.Fprintf(os.Stderr, "Warning: load config failed! error:%v \n\n", err)
55: }
56: cfg = config.Cfg()
57: if verbose {
58: printJson(cfg)
(dlv) locals
(no locals)
(dlv) p cfgPath
"/Users/caiyili/.gitlab/config"
(dlv) vars cmd.cfg*
gitlab-tools/cmd.cfgCmd = ("*github.com/spf13/cobra.Command")(0x104bc79a0)
gitlab-tools/cmd.cfgShowCmd = ("*github.com/spf13/cobra.Command")(0x104bc7c20)
gitlab-tools/cmd.cfgSetCmd = ("*github.com/spf13/cobra.Command")(0x104bcb0a0)
gitlab-tools/cmd.cfgPath = "/Users/caiyili/.gitlab/config"
gitlab-tools/cmd.cfg = *gitlab-tools/config.Config nil
(dlv) l
> gitlab-tools/cmd.onInit() ./cmd/root.go:53 (hits goroutine(1):1 total:1) (PC: 0x104899fb0)
48:
49: func onInit() {
50: if cfgPath == "" {
51: cfgPath = config.GetDefaultCfgPath()
52: }
=> 53: if err := config.LoadConfig(cfgPath); err != nil {
54: fmt.Fprintf(os.Stderr, "Warning: load config failed! error:%v \n\n", err)
55: }
56: cfg = config.Cfg()
57: if verbose {
58: printJson(cfg)
(dlv) s /*****step 下一步,会进到调用函数里****/
> gitlab-tools/config.LoadConfig() ./config/config.go:28 (PC: 0x1045d5f30)
23:
24: func (c *Config) GetApiHost() string {
25: return c.Host
26: }
27:
=> 28: func LoadConfig(cfgPath string) (err error) {
29: var c = cfg
30: c.path = cfgPath
31: if !fileExist(cfgPath) {
32: return fmt.Errorf("config file:%s not exists!", cfgPath)
33: }
(dlv) n /*****下一行源码*****/
> gitlab-tools/config.LoadConfig() ./config/config.go:32 (PC: 0x1045d61a4)
27:
28: func LoadConfig(cfgPath string) (err error) {
29: var c = cfg
30: c.path = cfgPath
31: if !fileExist(cfgPath) {
=> 32: return fmt.Errorf("config file:%s not exists!", cfgPath)
33: }
34: file, err := os.OpenFile(cfgPath, os.O_RDONLY, 0644)
35: if err != nil {
36: return fmt.Errorf("read config file '%s' error: %w", cfgPath, err)
37: }
(dlv) stepout /*****把当前函数执行完,回到上一层函数*****/
> gitlab-tools/cmd.onInit() ./cmd/root.go:53 (PC: 0x104899fc4)
Values returned:
err: error(*errors.errorString) *{
s: "config file:/Users/caiyili/.gitlab/config not exists!",}
48:
49: func onInit() {
50: if cfgPath == "" {
51: cfgPath = config.GetDefaultCfgPath()
52: }
=> 53: if err := config.LoadConfig(cfgPath); err != nil {
54: fmt.Fprintf(os.Stderr, "Warning: load config failed! error:%v \n\n", err)
55: }
56: cfg = config.Cfg()
57: if verbose {
58: printJson(cfg)
(dlv)
|