Skip to content

Commit 3fdd1a9

Browse files
sago35deadprogram
authored andcommitted
gdb: kill openocd if it does not exit
1 parent 869baca commit 3fdd1a9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"path/filepath"
1616
"runtime"
1717
"strings"
18+
"sync/atomic"
1819
"syscall"
1920
"time"
2021

@@ -464,8 +465,15 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
464465
}
465466
defer func() {
466467
daemon.Process.Signal(os.Interrupt)
467-
// Maybe we should send a .Kill() after x seconds?
468+
var stopped uint32
469+
go func() {
470+
time.Sleep(time.Millisecond * 100)
471+
if atomic.LoadUint32(&stopped) == 0 {
472+
daemon.Process.Kill()
473+
}
474+
}()
468475
daemon.Wait()
476+
atomic.StoreUint32(&stopped, 1)
469477
}()
470478
}
471479

0 commit comments

Comments
 (0)