aboutsummaryrefslogtreecommitdiffhomepage
path: root/main.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2020-01-10 17:02:30 +0100
committerRon Evans <[email protected]>2020-01-12 17:02:53 +0100
commit6841f9e245b3be5a638128bc2ecd5d67a246246b (patch)
tree2704b6b1ca15155d8277f44dd65f3ae46238439f /main.go
parentef4ede43d1bbb2dcd91f147eb3c1b2bbfb55b2dd (diff)
downloadtinygo-6841f9e245b3be5a638128bc2ecd5d67a246246b.tar.gz
tinygo-6841f9e245b3be5a638128bc2ecd5d67a246246b.zip
compiler: add support for debugging through JLinkGDBServer
Some J-Link targets aren't supported in OpenOCD (or would need some special configuration), so also give the option to use JLinkGDBServer instead.
Diffstat (limited to 'main.go')
-rw-r--r--main.go32
1 files changed, 29 insertions, 3 deletions
diff --git a/main.go b/main.go
index f9059d2db..f2df643ca 100644
--- a/main.go
+++ b/main.go
@@ -288,12 +288,13 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
gdbInterface, openocdInterface := config.Programmer()
switch gdbInterface {
case "msd", "command", "":
- if openocdInterface != "" && config.Target.OpenOCDTarget != "" {
- gdbInterface = "openocd"
- }
if len(config.Target.Emulator) != 0 {
// Assume QEMU as an emulator.
gdbInterface = "qemu"
+ } else if openocdInterface != "" && config.Target.OpenOCDTarget != "" {
+ gdbInterface = "openocd"
+ } else if config.Target.JLinkDevice != "" {
+ gdbInterface = "jlink"
}
}
@@ -331,6 +332,31 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
// Maybe we should send a .Kill() after x seconds?
daemon.Wait()
}()
+ case "jlink":
+ gdbCommands = append(gdbCommands, "target remote :2331", "load", "monitor reset halt")
+
+ // We need a separate debugging daemon for on-chip debugging.
+ daemon := exec.Command("JLinkGDBServer", "-device", config.Target.JLinkDevice)
+ if ocdOutput {
+ // Make it clear which output is from the daemon.
+ w := &ColorWriter{
+ Out: os.Stderr,
+ Prefix: "jlink: ",
+ Color: TermColorYellow,
+ }
+ daemon.Stdout = w
+ daemon.Stderr = w
+ }
+ // Make sure the daemon doesn't receive Ctrl-C that is intended for
+ // GDB (to break the currently executing program).
+ setCommandAsDaemon(daemon)
+ // Start now, and kill it on exit.
+ daemon.Start()
+ defer func() {
+ daemon.Process.Signal(os.Interrupt)
+ // Maybe we should send a .Kill() after x seconds?
+ daemon.Wait()
+ }()
case "qemu":
gdbCommands = append(gdbCommands, "target remote :1234")