diff --git a/main.go b/main.go index 07ea71ec..20f4f356 100644 --- a/main.go +++ b/main.go @@ -299,7 +299,11 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro case "msd", "command", "": if len(config.Target.Emulator) != 0 { // Assume QEMU as an emulator. - gdbInterface = "qemu" + if config.Target.Emulator[0] == "mgba" { + gdbInterface = "mgba" + } else { + gdbInterface = "qemu" + } } else if openocdInterface != "" && config.Target.OpenOCDTarget != "" { gdbInterface = "openocd" } else if config.Target.JLinkDevice != "" { @@ -395,6 +399,26 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro // Maybe we should send a .Kill() after x seconds? daemon.Wait() }() + case "mgba": + gdbCommands = append(gdbCommands, "target remote :2345") + + // Run in an emulator. + args := append(config.Target.Emulator[1:], tmppath, "-g") + daemon := exec.Command(config.Target.Emulator[0], args...) + daemon.Stdout = os.Stdout + daemon.Stderr = os.Stderr + + // 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 "msd": return errors.New("gdb is not supported for drag-and-drop programmable devices") default: diff --git a/targets/gameboy-advance.json b/targets/gameboy-advance.json index efad489c..2ef4f8d1 100644 --- a/targets/gameboy-advance.json +++ b/targets/gameboy-advance.json @@ -26,5 +26,6 @@ "extra-files": [ "targets/gameboy-advance.s" ], - "emulator": ["mgba-qt"] + "gdb": "gdb-multiarch", + "emulator": ["mgba", "-3"] }