SoFunction
Updated on 2025-03-05

Golang command line for debug debugging operations

GoLang debugging tool Delve

1. Get it first:

go get -u /derekparker/delve/cmd/dlv

2. Write test code:

func main(){
 ("/test",func(writer ,req *){
 //TODO
 })
 (("127.0.0.1:8080",nil))
}

start up:

dlv debug 

4. Breakpoint:

4.1): Break points for the method:

b main.function name

4.2): Run to the breakpoint:

c

4.3: Break points for a certain line:

You need to get the file location and break the point:

b /Users/joker/go/src/…/:14 break points for 14 lines

As for how to perform operations consistent with the ide: through n,s

  • n: F6 equivalent to Java-Eclipse
  • s: F5 equivalent to Java-Eclipse

How to view variables:p

p testName will output the value of testName

args: will output all method parameter information

locals: will output all local variables

The command line compilation of emmmmmmmmm golang feels very inconvenient, so I'd better find a way to get it on the idea.

Use go to play Debug, Info, Error level log

Directly upload the code:

package mylog
import (
    "log"
    "os"
)
var (
    Debug *
    Info *
    Error *
)
func init() {
    ("init ...")
    Debug = (, "[DEBUG] ", ||)
    Info = (, "[INFO] ", ||)
    Error = (, "[ERROR] ", ||)
}
package main
import "mylog"
func main(){
  ("good");
  ("good");
  ("good");
}

that's all.

Summarize

The above is the entire content of this article. I hope that the content of this article has certain reference value for your study or work. Thank you for your support. If you want to know more about it, please see the following links