1# Copyright 2011-2013 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# This file is a dejagnu "board file" and is used to run the testsuite
17# natively with gdbserver using stdio for comms.
18#
19# To use this file:
20# bash$ touch ${my_dejagnu_dir}/my-dejagnu.exp
21# bash$ export DEJAGNU=${my_dejagnu_dir}/my-dejagnu.exp
22# bash$ mkdir ${my_dejagnu_dir}/boards
23# bash$ cp ${src_dir}/gdb/testsuite/boards/native-stdio-gdbserver.exp \
24#   ${my_dejagnu_dir}/boards
25# bash$ cd ${build_dir}/gdb
26# bash$ make check RUNTESTFLAGS="--target_board=native-stdio-gdbserver"
27
28load_generic_config "gdbserver"
29process_multilib_options ""
30
31# The default compiler for this target.
32set_board_info compiler "[find_gcc]"
33
34# This gdbserver can only run a process once per session.
35set_board_info gdb,do_reload_on_run 1
36
37# There's no support for argument-passing (yet).
38set_board_info noargs 1
39
40# Can't do input (or output) in the current gdbserver.
41set_board_info gdb,noinferiorio 1
42
43# gdbserver does not intercept target file operations and perform them
44# on the host.
45set_board_info gdb,nofileio 1
46
47# Hack into sockethost to pass our peculiar remote connection string.
48set_board_info sockethost "stdio"
49set_board_info gdb,socketport ""
50set_board_info gdb,get_remote_address ${board}_get_remote_address
51set_board_info use_gdb_stub 1
52
53# We will be using the standard GDB remote protocol.
54set_board_info gdb_protocol "remote"
55# Test the copy of gdbserver in the build directory.
56set_board_info gdb_server_prog "../gdbserver/gdbserver"
57
58# The argument to pass to "target remote".
59# We build this once we know how the testsuite will start gdbserver.
60set stdio_gdbserver_template "| @GDBSERVER_PROG@ @ARGS@ stdio @PROG_AND_ARGS@"
61
62# Used to pass a value between ${board}_spawn and ${board}_get_remote_address.
63set stdio_gdbserver_command "--unset--"
64
65proc ${board}_get_remote_address { host port } {
66    global stdio_gdbserver_command
67    return $stdio_gdbserver_command
68}
69
70proc ${board}_build_remote_cmd { cmd } {
71    global stdio_gdbserver_template
72
73    # First parse $cmd, picking out the various pieces.
74    set gdbserver_prog [lindex $cmd 0]
75    set args ""
76    set len [llength $cmd]
77
78    for { set i 1 } { $i < $len } { incr i } {
79	set elm [lindex $cmd $i]
80	switch $elm {
81	    --multi {
82		set args "$args $elm"
83	    }
84	    --once {
85		set args "$args $elm"
86	    }
87	    default {
88		break
89	    }
90	}
91    }
92
93    set prog_and_args [lrange $cmd $i end]
94
95    set buf $stdio_gdbserver_template
96
97    regsub {@GDBSERVER_PROG@} $buf $gdbserver_prog buf
98    regsub {@ARGS@} $buf $args buf
99    regsub {@PROG_AND_ARGS@} $buf $prog_and_args buf
100
101    return $buf
102}
103
104proc ${board}_spawn { board cmd } {
105    global board_info
106
107    verbose -log "${board}_spawn: $board $cmd"
108
109    # Convert the command to start gdbserver to something to pass to
110    # "target remote | ..." and save it for later retrieval by
111    # ${board}_get_remote_address.
112    global stdio_gdbserver_command
113    set stdio_gdbserver_command [${board}_build_remote_cmd $cmd]
114    verbose -log "gdbserver_command: $stdio_gdbserver_command"
115
116    set baseboard [lindex [split $board "/"] 0]
117
118    # We don't spawn gdbserver here, that is done by the subsequent
119    # "target remote | ..." command.
120    set board_info($baseboard,isremote) 0
121    # Pretend as if we've started gdbserver, provide the test harness
122    # with what it's waiting for.
123    set result [remote_spawn $board "echo Listening on stdio"]
124    set board_info($baseboard,isremote) 1
125
126    return $result
127}
128
129proc ${board}_exec { hostname program args } {
130    global board_info
131
132    set baseboard [lindex [split $hostname "/"] 0]
133
134    set board_info($baseboard,isremote) 0
135    set result [remote_exec $hostname $program $args]
136    set board_info($baseboard,isremote) 1
137
138    return $result
139}
140
141proc ${board}_download { board host dest } {
142    return $host
143}
144
145proc ${board}_upload {dest srcfile args} {
146    return $srcfile
147}
148
149proc ${board}_file { dest op args } {
150    if { $op == "delete" } {
151	return 0
152    }
153    return [eval [list standard_file $dest $op] $args]
154}
155