Commit | Line | Data |
---|---|---|
462f72c5 SM |
1 | # Copyright 2020 Free Software Foundation, Inc. |
2 | ||
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. | |
7 | # | |
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. | |
12 | # | |
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/>. | |
15 | ||
16 | # Let the user override the path to the simavr binary with the SIMAVR_PATH | |
17 | # environment variable. | |
18 | ||
19 | if { [info exists ::env(SIMAVR_PATH)] } { | |
20 | set simavr_path $::env(SIMAVR_PATH) | |
21 | } else { | |
22 | set simavr_path simavr | |
23 | } | |
24 | ||
25 | # Let the user override the simulated AVR chip with the SIMAVR_PATH environment | |
26 | # variable. | |
27 | # | |
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`). | |
31 | ||
32 | if { [info exists ::env(SIMAVR_MCU)] } { | |
33 | set simavr_mcu $::env(SIMAVR_MCU) | |
34 | } else { | |
35 | set simavr_mcu atmega2560 | |
36 | } | |
37 | ||
38 | set simavr_last_load_file "" | |
39 | set simavr_spawn_id "" | |
40 | ||
41 | set_board_info compiler avr-gcc | |
42 | set_board_info c++compiler avr-g++ | |
43 | ||
44 | set_board_info cflags "-mmcu=${simavr_mcu}" | |
45 | set_board_info ldflags "-mmcu=${simavr_mcu}" | |
46 | ||
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 | |
55 | ||
56 | proc gdb_load { file } { | |
57 | global simavr_last_load_file | |
58 | global simavr_spawn_id | |
59 | global simavr_mcu | |
60 | global simavr_path | |
61 | global gdb_prompt | |
62 | ||
63 | if { $file == "" } { | |
64 | set file $simavr_last_load_file | |
65 | } else { | |
66 | set simavr_last_load_file $file | |
67 | } | |
68 | ||
69 | gdb_file_cmd $file | |
70 | ||
71 | # Close any previous simavr instance. | |
72 | if { $simavr_spawn_id != "" } { | |
73 | close -i $simavr_spawn_id | |
74 | set simavr_spawn_id "" | |
75 | } | |
76 | ||
77 | # Run simavr. | |
78 | set cmd "spawn -noecho ${simavr_path} --mcu ${simavr_mcu} -g $file" | |
79 | verbose -log "Spawning simavr: $cmd" | |
80 | eval $cmd | |
81 | set simavr_spawn_id $spawn_id | |
82 | gdb_expect { | |
83 | -i $simavr_spawn_id -re ".*avr_gdb_init listening on port 1234" {} | |
84 | timeout { error "unable to start simavr" } | |
85 | } | |
86 | ||
87 | # Connect to simavr. | |
88 | send_gdb "target remote :1234\n" | |
89 | gdb_expect { | |
90 | -re ".*Remote debugging using :1234.*\[\r\n\]+$gdb_prompt $" {} | |
91 | timeout { error "unable to connect to simavr stub" } | |
92 | } | |
93 | ||
94 | return 0 | |
95 | } |