Q:

How to set a breakpoint for a specific goroutine?

I'm trying to debug a simple golang program, but don't have a clue how to set a breakpoint on specific goroutine in the delve debugger.
Here's an example:
package main

import "fmt"

func adder(a int, b int, res_chan chan int) {
    c := a + b
    res_chan <- c
}

func main() {
    chan1 := make(chan int)
    chan2 := make(chan int)

    go adder(0, 1, chan1)
    go adder(0, 2, chan2)

    res1 := <-chan1
    res2 := <-chan2

    fmt.Printf("Channel 1: %d\nChannel 2: %d\n", res1, res2)
}

I do dlv debug:
Type 'help' for list of commands.

Set a breakpoint on the goroutine, and here I'm intuitively assume that the debugger will stop twice (on each goroutine called):
(dlv) b main.adder
Breakpoint 1 set at 0x49dd1f for main.adder() ./adder.go:5
(dlv) c
> main.adder() ./adder.go:5 (hits goroutine(18):1 total:2) (PC: 0x49dd1f)
> main.adder() ./adder.go:5 (hits goroutine(19):1 total:2) (PC: 0x49dd1f)
     1: package main
     2:
     3: import "fmt"
     4:
=>   5: func adder(a int, b int, res_chan chan int) {
     6:         c := a + b
     7:         res_chan <- c
     8: }
     9:
    10: func main() {
(dlv) s
> main.adder() ./adder.go:6 (PC: 0x49dd2d)
     1: package main
     2:
     3: import "fmt"
     4:
     5: func adder(a int, b int, res_chan chan int) {
=>   6:         c := a + b
     7:         res_chan <- c
     8: }
     9:
    10: func main() {
    11:         chan1 := make(chan int)
(dlv) 
> main.adder() ./adder.go:7 (PC: 0x49dd3c)
     2:
     3: import "fmt"
     4:
     5: func adder(a int, b int, res_chan chan int) {
     6:         c := a + b
=>   7:         res_chan <- c
     8: }
     9:
    10: func main() {
    11:         chan1 := make(chan int)
    12:         chan2 := make(chan int)

Check the value of c variable:
(dlv) p c
2

Continue execution:
(dlv) c
Channel 1: 1
Channel 2: 2
Process 8112 has exited with status 0

Exit the debugger:
(dlv) q
Process 8112 has exited with status 0

So, the goroutine with result 1 wasn't hit by debugger.
How can I debug code execution in the goroutine resulted 1?

A:

I've used breakpoint with condition:
Run dlv debug:
Type 'help' for list of commands.

Set a breakpoint on a line, where goroutine could be indentified by some condition. On the 7 line variable c will be already evaluated, so we could build a condition on it.
Set a breakpoint on the 7th line:
(dlv) b adder.go:7
Breakpoint 1 set at 0x49dd3c for main.adder() ./adder.go:7

List all breakpoints for clearness:
(dlv) breakpoints
Breakpoint unrecovered-panic at 0x42a870 for runtime.startpanic() /home/dmytriv/.soft/go/src/runtime/panic.go:591 (0)
        print runtime.curg._panic.arg
Breakpoint 1 at 0x49dd3c for main.adder() ./adder.go:7 (0)

Set a condition for breakpoint 1:
(dlv) cond 1 c == 1

Continue execution:
(dlv) c

Here the breakpoint is hit:
> main.adder() ./adder.go:7 (hits goroutine(5):1 total:1) (PC: 0x49dd3c)
     2:
     3: import "fmt"
     4:
     5: func adder(a int, b int, res_chan chan int) {
     6:         c := a + b
=>   7:         res_chan <- c
     8: }
     9:
    10: func main() {
    11:         chan1 := make(chan int)
    12:         chan2 := make(chan int)

Check the value of c variable:
(dlv) p c
1

Continue:
(dlv) c
Channel 1: 1
Channel 2: 2
Process 10096 has exited with status 0

Exit debugger:
(dlv) q
Process 10096 has exited with status 0

