Skip to content

Commit a365191

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 efdb2e8 commit a365191

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
@@ -310,10 +310,12 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
310310
switch gdbInterface {
311311
case "msd", "command", "":
312312
if len(config.Target.Emulator) != 0 {
313-
// Assume QEMU as an emulator.
314313
if config.Target.Emulator[0] == "mgba" {
315314
gdbInterface = "mgba"
315+
} else if config.Target.Emulator[0] == "simavr" {
316+
gdbInterface = "simavr"
316317
} else {
318+
// Assume QEMU as an emulator.
317319
gdbInterface = "qemu"
318320
}
319321
} else if openocdInterface != "" && config.Target.OpenOCDTarget != "" {
@@ -379,6 +381,14 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
379381
daemon = exec.Command(config.Target.Emulator[0], args...)
380382
daemon.Stdout = os.Stdout
381383
daemon.Stderr = os.Stderr
384+
case "simavr":
385+
gdbCommands = append(gdbCommands, "target remote :1234")
386+
387+
// Run in an emulator.
388+
args := append(config.Target.Emulator[1:], "-g", tmppath)
389+
daemon = exec.Command(config.Target.Emulator[0], args...)
390+
daemon.Stdout = os.Stdout
391+
daemon.Stderr = os.Stderr
382392
case "msd":
383393
return errors.New("gdb is not supported for drag-and-drop programmable devices")
384394
default:

targets/avr.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
"gc": "conservative",
77
"linker": "avr-gcc",
88
"scheduler": "none",
9+
"cflags": [
10+
"-gdwarf-4"
11+
],
912
"ldflags": [
1013
"-T", "targets/avr.ld",
1114
"-Wl,--gc-sections"
1215
],
1316
"extra-files": [
1417
"src/runtime/scheduler_avr.S"
15-
]
18+
],
19+
"gdb": "avr-gdb"
1620
}

0 commit comments

Comments
 (0)