]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/boards/simavr.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / boards / simavr.exp
1 # Copyright 2020-2024 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 # As of version 10, GCC produces stabs by default for AVR. Force it to use
48 # DWARF.
49 set_board_info debug_flags "-gdwarf-4"
50
51 set_board_info use_gdb_stub 1
52 set_board_info gdb_protocol "remote"
53 set_board_info gdb,do_reload_on_run 1
54 set_board_info noargs 1
55 set_board_info gdb,noinferiorio 1
56 set_board_info gdb,nofileio 1
57 set_board_info gdb,noresults 1
58 set_board_info gdb,nosignals 1
59
60 proc gdb_load { file } {
61 global simavr_last_load_file
62 global simavr_spawn_id
63 global simavr_mcu
64 global simavr_path
65 global gdb_prompt
66
67 if { $file == "" } {
68 set file $simavr_last_load_file
69 } else {
70 set simavr_last_load_file $file
71 }
72
73 gdb_file_cmd $file
74
75 # Close any previous simavr instance.
76 if { $simavr_spawn_id != "" } {
77 verbose -log "simavr: closing previous spawn id $simavr_spawn_id"
78 if [catch { close -i $simavr_spawn_id } != 0] {
79 warning "simavr: failed to close connection to previous simavr instance"
80 }
81
82 wait -i $simavr_spawn_id
83 set simavr_spawn_id ""
84 }
85
86 # Run simavr.
87 set cmd "spawn -noecho ${simavr_path} --mcu ${simavr_mcu} -g $file"
88 verbose -log "Spawning simavr: $cmd"
89 eval $cmd
90 set simavr_spawn_id $spawn_id
91
92 verbose -log "simavr: simavr spawned with spawn id $simavr_spawn_id, pid [exp_pid $simavr_spawn_id]"
93
94 # Wait for "listening on port" message of simavr.
95 expect {
96 -i $simavr_spawn_id -re ".*avr_gdb_init listening on port 1234" {}
97 timeout {
98 verbose -log "simavr: timeout, closing simavr spawn id"
99 close -i $simavr_spawn_id
100 verbose -log "simavr: timeout, waiting for simavr process exit"
101 wait -i $simavr_spawn_id
102 set simavr_spawn_id ""
103 error "unable to start simavr: timeout"
104 }
105 eof {
106 verbose -log "simavr: eof, waiting for simavr process exit"
107 wait -i $simavr_spawn_id
108 set simavr_spawn_id ""
109 error "unable to start simavr: eof"
110 }
111 }
112
113 # Connect to simavr.
114 send_gdb "target remote :1234\n"
115 gdb_expect {
116 -re ".*Remote debugging using :1234.*\[\r\n\]+$gdb_prompt $" {}
117 timeout {
118 verbose -log "simavr: unable to connect to simavr, closing simavr spawn id"
119 close -i $simavr_spawn_id
120 verbose -log "simavr: unable to connect to simavr, waiting for simavr process exit"
121 wait -i $simavr_spawn_id
122 set simavr_spawn_id ""
123 error "unable to connect to simavr stub"
124 }
125 }
126
127 return 0
128 }