当前位置: 首页 > news >正文

[Arduino UNO]使用simavr和gdb-avr 调试arduino IDEblink参考代码

因为摸玩arduino uno时,发现很多老外写的library库代码还挺复杂,要是能像IDE里单步调试就爽了,查了一下有simavr软件,自己从github下载后编译和使用了一下,不得其所,这时看到debian自带了simavr和gdb-avr,全部安装后,终于能单步运行起来,步骤大概如下:

1.在debian下编译出Blink参考代码后,一般在 ~/.cache/arduino/sketches/ 的位置:

image

其中elf是需要调试的文件,已经带了调试信息:

nisy@localhost:~/.cache/arduino/sketches/E924F509621C67E30DD83726452B9FA9$ file Blink.ino.elf
Blink.ino.elf: ELF 32-bit LSB executable, Atmel AVR 8-bit, version 1 (SYSV), statically linked, with debug_info, not stripped

然后参考 man simavr文件中的描述:

EXAMPLESAVR GDB DEBUGGINGRun the AVR firmware simulation:simavr -g -m atmega328p -f 16000000 firmware.elfstart avr-gdb and optionally enable tui for better source code readability:avr-gdb(gdb) tui enableload the elf formatted firmware and connect to the running simulation:(gdb) file firmware.elf(gdb) target remote :1234set a break point and go ahead, debug:(gdb) break main(gdb) continue(gdb) next(gdb) next

类似地敲入:

nisy@localhost:~/.cache/arduino/sketches/E924F509621C67E30DD83726452B9FA9$ simavr -g -m atmega328p -f 16000000 Blink.ino.elf 
Loaded 924 .text at address 0x0
Loaded 0 .data
avr_gdb_init listening on port 1234

同样启动avr-gdb,如man操作即可。