Closed emad-elsaid closed 6 months ago
Thanks for reporting! I just sent in https://github.com/go-delve/delve/pull/3695 to fix this.
To be clear, the bug is that Delve ends up panic'ing (and recovering) instead of returning a nicer error. As it stands, when a program is built and executed via go run ...
the Go compiler does not include the necessary DWARF debug information in the binary for Delve to be able to locate variables. If you want a better debugging experience I would suggest simply: dlv debug ./cmd/xlog/
instead, which will let Delve compile the binary for you and run it directly under the debugger in one step. From there you can continue
and then make requests to your service.
I see, thanks @derekparker for the clarification. I didn't know go run
doesn't include DWARF data.
Do you have any document that expand on that, I'm looking for flags or env variables to change this behavior in Go. What I'm trying to achieve depends on that.
I can't find the issue where this was explained anymore but it's by design and there is no way to change this behavior.
This is what I was trying to achieve over the past days: https://github.com/emad-elsaid/examine
I accepted the fact that the concept won't work with go run
When running a go program with
go run ./path/to/main
and attaching Delve to the process. when it hits a breakpoint it can't print args.These are steps to reproduce it:
runtime.Breakpoint()
call herego run ./cmd/xlog/
ps a
it should look something like:162843 pts/2 Sl+ 0:00 /tmp/go-build2627955907/b001/exe/xlog
dlv attach 162843
localhost:3000
args
I got the following panic:
Env:
What version of Delve are you using (
dlv version
)?What version of Go are you using? (
go version
)?What operating system and processor architecture are you using?
I probably missed something in Delve conditions to show args/locals...etc. I expected it to work even if the process ran from
go run
command.I made another experiment where I built the app first and ran it then attached delve to the process and everything is fine. So I'm not sure if this is an expected behavior or is it a bug.