Skip to content

Commit 41ac276

Browse files
committed
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 d382f3a commit 41ac276

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
"linker": "avr-gcc",
99
"scheduler": "none",
1010
"default-stack-size": 256,
11+
"cflags": [
12+
"-gdwarf-4"
13+
],
1114
"ldflags": [
1215
"-T", "targets/avr.ld",
1316
"-Wl,--gc-sections"
1417
],
1518
"extra-files": [
1619
"src/runtime/gc_avr.S",
1720
"src/runtime/scheduler_avr.S"
18-
]
21+
],
22+
"gdb": "avr-gdb"
1923
}

0 commit comments

Comments
 (0)