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
?
To set a breakpoint in source code, click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.
Breakpoints break before executing the line on which they are placed.
They work by patching the code you are trying to execute with an instruction that triggers a debug event in some fashion. This is accomplished by injecting a breakpoint instruction or when that is not supported by inserting an instruction that causes a fault that halts the core.
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.
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
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