0

How can I set a breakpoint by sourcefile? I have the following code in a tmp.go file.

package main

func main() {
   a, b := 1, 2
   c := a + b
   println(c)

}

This works

$ dlv debug ./tmp.go
(dlv) b main.main:1
Breakpoint 1 set at 0x105395d for main.main() ./tmp.go:4

But this fails

$ dlv debug ./tmp.go
(dlv) b ./tmp.go:4
Command failed: Location "./tmp.go:4" not found

Edit: This works

$ dlv debug ./tmp.go
(dlv) b tmp.go:4
Breakpoint 1 set at 0x105395d for main.main() ./tmp.go:4

Any ideas what might be wrong with my environment?

Ben
  • 4,774
  • 5
  • 22
  • 26

1 Answers1

3

Any ideas what might be wrong with my environment?


Why should this question be closed?

off-topic because...

Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.

You didn't provide an MCVE, so we can only guess.

We have no idea what is in your main.go, so how do you expect us to know what your problem is?


For example, just a guess, with an MCVE,

main.go:

package main

func main() {
    a, b := 1, 2
    c := a + b
    println(c)
}

Playground: https://play.golang.org/p/i2D9uZnFlXn

Output:

$ go run main.go
3
$ dlv debug ./main.go
Type 'help' for list of commands.
(dlv) break main.main:4
Breakpoint 1 set at 0x454bda for main.main() ./main.go:7
(dlv) quit
$ dlv debug ./main.go
Type 'help' for list of commands.
(dlv) break main.go:4
Breakpoint 1 set at 0x454b9d for main.main() ./main.go:4
(dlv) quit
$ 

break main.main:4 and break main.go:4 are not the same thing, at ./main.go:7 and at ./main.go:4 respectively. Line numbers are relative to files, functions, etc.


peterSO
  • 158,998
  • 31
  • 281
  • 276