remote-stdio-gdbserver.exp revision 1.1
1# Copyright 2011-2014 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# with a remotehost and gdbserver using stdio for communicating through
18# ssh. Certain firewalls prevent gdbserver from using the usual mechanism of
19# listening on a remote port, so use stdio via ssh instead.
20#
21# To use this file:
22# bash$ cd ${build_dir}/gdb
23# bash$ make check RUNTESTFLAGS="--target_board=remote-stdio-gdbserver \
24#    REMOTE_USERNAME=... REMOTE_HOSTNAME=... REMOTE_PORTNUM=... \
25#    [REMOTE_TMPDIR=${remote_dir}] [GDBSERVER=${remote_gdbserver}]"
26
27load_board_description "native-stdio-gdbserver"
28
29# Test machine info. The generic_config gdbserver reads some of these
30# values from board_info, so this file must set them there.
31if [info exists REMOTE_USERNAME] {
32    set_board_info username $REMOTE_USERNAME
33} else {
34    set_board_info username unspecified_username
35}
36if [info exists REMOTE_HOSTNAME] {
37    set_board_info hostname $REMOTE_HOSTNAME
38} else {
39    set_board_info hostname unspecified_hostname
40}
41
42# The two programs have different syntax to set the remote port, so
43# set it as part of the program name rather than in get_remote_login.
44
45if [info exists REMOTE_PORTNUM] {
46    set_board_info portnum $REMOTE_PORTNUM
47    set_board_info rsh_prog "/usr/bin/ssh -p$REMOTE_PORTNUM"
48    set_board_info rcp_prog "/usr/bin/scp -P$REMOTE_PORTNUM"
49} else {
50    set_board_info rsh_prog /usr/bin/ssh
51    set_board_info rcp_prog /usr/bin/scp
52}
53
54# Some remote machines don't have writable home directories.
55if [info exists REMOTE_TMPDIR] {
56    set_board_info remotedir $REMOTE_TMPDIR
57}
58
59unset_board_info gdb_server_prog
60set_board_info gdb_server_prog "/usr/bin/gdbserver"
61
62# Used to pass a value between ${board}_spawn and ${board}_get_remote_address.
63set stdio_gdbserver_command "--unset--"
64
65proc get_remote_login { } {
66    set result ""
67    if {[board_info [target_info name] exists username]} {
68	append result "[board_info [target_info name] username]@"
69    }
70    if {[board_info [target_info name] exists hostname]} {
71	append result "[board_info [target_info name] hostname]"
72    }
73    return $result
74}
75
76proc ${board}_build_remote_cmd { cmd } {
77    set stdio_gdbserver_template "| @RSH_CMD@ @GDBSERVER_PROG@ @ARGS@ stdio @PROG_AND_ARGS@"
78
79    # First parse $cmd, picking out the various pieces.
80    set gdbserver_prog [lindex $cmd 0]
81    set args ""
82    set len [llength $cmd]
83
84    for { set i 1 } { $i < $len } { incr i } {
85	set elm [lindex $cmd $i]
86	switch $elm {
87	    --multi {
88		set args "$args $elm"
89	    }
90	    --once {
91		set args "$args $elm"
92	    }
93	    default {
94		break
95	    }
96	}
97    }
98
99    set prog_and_args [lrange $cmd $i end]
100
101    set buf $stdio_gdbserver_template
102
103    set rsh_cmd "[board_info [target_info name] rsh_prog] [get_remote_login]"
104    regsub {@RSH_CMD@} $buf $rsh_cmd buf
105    regsub {@GDBSERVER_PROG@} $buf $gdbserver_prog buf
106    regsub {@ARGS@} $buf $args buf
107    regsub {@PROG_AND_ARGS@} $buf $prog_and_args buf
108
109    return $buf
110}
111
112proc ${board}_download { board host dest } {
113    if { [board_info [target_info name] exists remotedir] } {
114	set remotedir "[board_info [target_info name] remotedir]/"
115    } else {
116	set remotedir ""
117    }
118    return [standard_download $board $host "$remotedir$dest"]
119}
120
121proc ${board}_upload {dest srcfile args} {
122    return [standard_upload $dest $srcfile $args]
123}
124
125proc ${board}_file { dest op args } {
126    if { $op == "delete" } {
127	return [remote_exec [get_remote_login] "rm -f $args"]
128    }
129    return [eval [list standard_file $dest $op] $args]
130}
131