Skip to content

Commit 4cc1cdf

Browse files
aykevldeadprogram
authored andcommitted
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.
1 parent bb27bbc commit 4cc1cdf

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

main.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,14 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
348348
switch gdbInterface {
349349
case "msd", "command", "":
350350
if len(config.Target.Emulator) != 0 {
351-
// Assume QEMU as an emulator.
352351
if config.Target.Emulator[0] == "mgba" {
353352
gdbInterface = "mgba"
353+
} else if config.Target.Emulator[0] == "simavr" {
354+
gdbInterface = "simavr"
354355
} else if strings.HasPrefix(config.Target.Emulator[0], "qemu-system-") {
355356
gdbInterface = "qemu"
356357
} else {
358+
// Assume QEMU as an emulator.
357359
gdbInterface = "qemu-user"
358360
}
359361
} else if openocdInterface != "" && config.Target.OpenOCDTarget != "" {
@@ -429,6 +431,14 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
429431
daemon = exec.Command(config.Target.Emulator[0], args...)
430432
daemon.Stdout = os.Stdout
431433
daemon.Stderr = os.Stderr
434+
case "simavr":
435+
gdbCommands = append(gdbCommands, "target remote :1234")
436+
437+
// Run in an emulator.
438+
args := append(config.Target.Emulator[1:], "-g", result.Binary)
439+
daemon = exec.Command(config.Target.Emulator[0], args...)
440+
daemon.Stdout = os.Stdout
441+
daemon.Stderr = os.Stderr
432442
case "msd":
433443
return errors.New("gdb is not supported for drag-and-drop programmable devices")
434444
default:

targets/avr.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
"extra-files": [
1616
"src/internal/task/task_stack_avr.S",
1717
"src/runtime/gc_avr.S"
18-
]
18+
],
19+
"gdb": "avr-gdb"
1920
}

0 commit comments

Comments
 (0)