From 4cc1cdf672820e419a68fa4165923a5d94bbb0e4 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 14 Apr 2020 23:10:31 +0200 Subject: [PATCH] main: support gdb debugging with AVR Be able to run `tinygo gdb -target=arduino examples/serial` and debug a program with the power of a real debugger. Note that this only works on LLVM 11 because older versions have a bug in the AVR backend that cause it to produce invalid debug information: https://reviews.llvm.org/D74213. --- main.go | 12 +++++++++++- targets/avr.json | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 30e8ee6b..c562dc5e 100644 --- a/main.go +++ b/main.go @@ -348,12 +348,14 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro switch gdbInterface { case "msd", "command", "": if len(config.Target.Emulator) != 0 { - // Assume QEMU as an emulator. if config.Target.Emulator[0] == "mgba" { gdbInterface = "mgba" + } else if config.Target.Emulator[0] == "simavr" { + gdbInterface = "simavr" } else if strings.HasPrefix(config.Target.Emulator[0], "qemu-system-") { gdbInterface = "qemu" } else { + // Assume QEMU as an emulator. gdbInterface = "qemu-user" } } else if openocdInterface != "" && config.Target.OpenOCDTarget != "" { @@ -429,6 +431,14 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro daemon = exec.Command(config.Target.Emulator[0], args...) daemon.Stdout = os.Stdout daemon.Stderr = os.Stderr + case "simavr": + gdbCommands = append(gdbCommands, "target remote :1234") + + // Run in an emulator. + args := append(config.Target.Emulator[1:], "-g", result.Binary) + daemon = exec.Command(config.Target.Emulator[0], args...) + daemon.Stdout = os.Stdout + daemon.Stderr = os.Stderr case "msd": return errors.New("gdb is not supported for drag-and-drop programmable devices") default: diff --git a/targets/avr.json b/targets/avr.json index fdae4b8b..31c2d9a7 100644 --- a/targets/avr.json +++ b/targets/avr.json @@ -15,5 +15,6 @@ "extra-files": [ "src/internal/task/task_stack_avr.S", "src/runtime/gc_avr.S" - ] + ], + "gdb": "avr-gdb" }