Say my Go project depends on package example.com/foo
. I am using Go 1.12
, so the dependency is automatically pulled in by Go modules. That dependency contains errors that I want to debug by adding logs or with step by step execution.
I can find the source code of the dependency on GitHub but I don't know how to fit it into my project, so that it replaces the dependency which was pulled in by Go modules.
To debug a program, execute the dlv debug command. Attach the filename at the end of this command, and debugging will start. For example, if you want to debug the main.go file, run the command dlv debug main.go . It is also known as “delve server” because this is a running process waiting for instructions.
Setting breakpointsSet a breakpoint at the TestFind function: (gdb) b 'regexp. TestFind' Breakpoint 1 at 0x424908: file /home/user/go/src/regexp/find_test.go, line 148. the one marked with the * is the current goroutine.
In Go, you manage dependencies as modules that contain the packages you import. This process is supported by: A decentralized system for publishing modules and retrieving their code. Developers make their modules available for other developers to use from their own repository and publish with a version number.
First fetch all the dependency packages into the vendor
folder.
go mod vendor
Then, change the source code in that and build your project by specifying to look into vendor
folder.
go build -mod=vendor
or
go run -mode=vendor myapp.go
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With