]>
Commit | Line | Data |
---|---|---|
3666a048 | 1 | # Copyright 2020-2021 Free Software Foundation, Inc. |
462f72c5 SM |
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 != "" } { | |
df5b8876 SM |
73 | verbose -log "simavr: closing previous spawn id $simavr_spawn_id" |
74 | if [catch { close -i $simavr_spawn_id } != 0] { | |
75 | warning "simavr: failed to close connection to previous simavr instance" | |
76 | } | |
77 | ||
78 | wait -i $simavr_spawn_id | |
462f72c5 SM |
79 | set simavr_spawn_id "" |
80 | } | |
81 | ||
82 | # Run simavr. | |
83 | set cmd "spawn -noecho ${simavr_path} --mcu ${simavr_mcu} -g $file" | |
84 | verbose -log "Spawning simavr: $cmd" | |
85 | eval $cmd | |
86 | set simavr_spawn_id $spawn_id | |
df5b8876 SM |
87 | |
88 | verbose -log "simavr: simavr spawned with spawn id $simavr_spawn_id, pid [exp_pid $simavr_spawn_id]" | |
89 | ||
90 | # Wait for "listening on port" message of simavr. | |
91 | expect { | |
462f72c5 | 92 | -i $simavr_spawn_id -re ".*avr_gdb_init listening on port 1234" {} |
df5b8876 SM |
93 | timeout { |
94 | verbose -log "simavr: timeout, closing simavr spawn id" | |
95 | close -i $simavr_spawn_id | |
96 | verbose -log "simavr: timeout, waiting for simavr process exit" | |
97 | wait -i $simavr_spawn_id | |
98 | set simavr_spawn_id "" | |
99 | error "unable to start simavr: timeout" | |
100 | } | |
101 | eof { | |
102 | verbose -log "simavr: eof, waiting for simavr process exit" | |
103 | wait -i $simavr_spawn_id | |
104 | set simavr_spawn_id "" | |
105 | error "unable to start simavr: eof" | |
106 | } | |
462f72c5 SM |
107 | } |
108 | ||
109 | # Connect to simavr. | |
110 | send_gdb "target remote :1234\n" | |
111 | gdb_expect { | |
112 | -re ".*Remote debugging using :1234.*\[\r\n\]+$gdb_prompt $" {} | |
df5b8876 SM |
113 | timeout { |
114 | verbose -log "simavr: unable to connect to simavr, closing simavr spawn id" | |
115 | close -i $simavr_spawn_id | |
116 | verbose -log "simavr: unable to connect to simavr, waiting for simavr process exit" | |
117 | wait -i $simavr_spawn_id | |
118 | set simavr_spawn_id "" | |
119 | error "unable to connect to simavr stub" | |
120 | } | |
462f72c5 SM |
121 | } |
122 | ||
123 | return 0 | |
124 | } |