24

The title pretty much says it all.

The only way I know how to set one is either during the runtime of the program or just before with breakpoint main.main

Is there a way I can do this by line number like breakpoint ./otherfile.go:200?

benbot
  • 1,217
  • 1
  • 12
  • 28
  • Not really an answer, but you can try to use a UI, visual studio code's [Go](https://github.com/Microsoft/vscode-go) plugin has excellent support for delve. – OneOfOne Mar 08 '16 at 01:51
  • I'm running on linux so... so visual studio for me :( – benbot Mar 08 '16 at 03:50
  • I think `break ./otherfile.go:200` should work. If not this is probably a bug. See https://github.com/derekparker/delve/wiki/Location-specifiers – kostya Mar 08 '16 at 04:08
  • vscode runs great on Linux, I'm using it on Arch Linux right now. https://code.visualstudio.com/ – OneOfOne Mar 08 '16 at 04:33
  • Really?!? I haven't looked at visual studio years. When did they add Linux support? – benbot Mar 08 '16 at 14:33
  • 1
    It's not Visual Studio, it's Visual Studio Code - think Atom... or Sublime text editor - https://code.visualstudio.com/ – Lars May 04 '16 at 17:19

2 Answers2

40

In your Source code type

  runtime.Breakpoint()

type in the CLI

dlv test

and then

continue

The program will stop in the line of code where you set the breakpoint.

Alejandro Serret
  • 1,139
  • 15
  • 16
  • I was just about to open up a question asking for something that's similar to `debugger` in node. I'm glad this exists in go too. – shriek Feb 23 '17 at 13:12
11

The following is valid in delve:

(dlv) break <breakpoint_name> <filename_pattern>:<line_number>

If you have ambiguous filenames, say main.go spread all over your sources and possibly vendor directory, just make you make it look "unique" to delve (filename_pattern is not your exact file location). For example:

(dlv) break myLoopingStuff project_name/loops.go:30
(dlv) condition myLoopingStuff thing == someOther.thing
Wari Wahab
  • 123
  • 1
  • 5