go-delve / delve

Delve is a debugger for the Go programming language.
MIT License
22.37k stars 2.13k forks source link

Breakpoint line numbers not matching #3746

Closed mvhatch closed 3 weeks ago

mvhatch commented 3 weeks ago

Please answer the following before submitting your issue:

Note: Please include any substantial examples (debug session output, stacktraces, etc) as linked gists.

If this is about source listing not showing up (or breakpoints not being accepted) while running in a container please read our FAQ first.

  1. What version of Delve are you using (dlv version)?

    $ dlv version
    Delve Debugger
    Version: 1.22.1
    Build: $Id: 0c3470054da6feac5f6dcf3e3e5144a64f7a9a48
  2. What version of Go are you using? (go version)?

    $ go version
    go version go1.22.2 linux/amd64
  3. What operating system and processor architecture are you using?

    Linux x86_64
  4. What did you do? I set a breakpoint at an existing source code line

    $ dlv exec ./tmp/app
    (dlv) ls main.main
    Showing /path/to/main.go:10 (PC: 0x145837c)
     5: 
     6:     "github.com/my/local/package"
     7:     _ "google.golang.org/grpc/encoding/gzip"
     8: )
     9: 
    10: func main() {
    11:     if err := app.Run(); err != nil {
    12:         stdlog.Fatal(err)
    13:     }
    14: }
    (dlv) b main.main:11
  5. What did you expect to see? I expected to see a success response (e.g. Breakpoint 1 set at 0x1458388 for main.main() ./app/main.go:11)

  6. What did you see instead? An error message that the breakpoint could not be set, but it was for the wrong line number.

    Command failed: could not find statement at /path/to/main.go:21, please use a line with a statement
aarzilli commented 3 weeks ago

When you say b main.main:11 you mean the 11th line of function main.main. Since main.main starts at line 10 that will be line 21 of the file main.go where main.main is defined.

Closing, working as intended.