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.
This commit is contained in:
Ayke van Laethem
2020-04-14 23:10:31 +02:00
parent f7f2082979
commit 43d7f48de4
2 changed files with 16 additions and 2 deletions
+11 -1
View File
@@ -310,10 +310,12 @@ 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 {
// Assume QEMU as an emulator.
gdbInterface = "qemu"
}
} else if openocdInterface != "" && config.Target.OpenOCDTarget != "" {
@@ -379,6 +381,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", tmppath)
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: