1 # Copyright 2020 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Let the user override the path to the simavr binary with the SIMAVR_PATH
17 # environment variable.
19 if { [info exists ::env(SIMAVR_PATH)] } {
20 set simavr_path $::env(SIMAVR_PATH)
22 set simavr_path simavr
25 # Let the user override the simulated AVR chip with the SIMAVR_PATH environment
28 # The value passed here must be supported by avr-gcc (see the -mmcu flag in the
29 # `AVR Options` section of the gcc(1) man page) and by simavr (see output of
30 # `simavr --list-cores`).
32 if { [info exists ::env(SIMAVR_MCU)] } {
33 set simavr_mcu $::env(SIMAVR_MCU)
35 set simavr_mcu atmega2560
38 set simavr_last_load_file ""
39 set simavr_spawn_id ""
41 set_board_info compiler avr-gcc
42 set_board_info c++compiler avr-g++
44 set_board_info cflags "-mmcu=${simavr_mcu}"
45 set_board_info ldflags "-mmcu=${simavr_mcu}"
47 set_board_info use_gdb_stub 1
48 set_board_info gdb_protocol "remote"
49 set_board_info gdb,do_reload_on_run 1
50 set_board_info noargs 1
51 set_board_info gdb,noinferiorio 1
52 set_board_info gdb,nofileio 1
53 set_board_info gdb,noresults 1
54 set_board_info gdb,nosignals 1
56 proc gdb_load { file } {
57 global simavr_last_load_file
58 global simavr_spawn_id
64 set file $simavr_last_load_file
66 set simavr_last_load_file $file
71 # Close any previous simavr instance.
72 if { $simavr_spawn_id != "" } {
73 close -i $simavr_spawn_id
74 set simavr_spawn_id ""
78 set cmd "spawn -noecho ${simavr_path} --mcu ${simavr_mcu} -g $file"
79 verbose -log "Spawning simavr: $cmd"
81 set simavr_spawn_id $spawn_id
83 -i $simavr_spawn_id -re ".*avr_gdb_init listening on port 1234" {}
84 timeout { error "unable to start simavr" }
88 send_gdb "target remote :1234\n"
90 -re ".*Remote debugging using :1234.*\[\r\n\]+$gdb_prompt $" {}
91 timeout { error "unable to connect to simavr stub" }