Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] New board file remote-stdio-gdbserver.exp
@ 2013-05-10 21:47 Sterling Augustine
  2013-05-13 21:24 ` Doug Evans
  0 siblings, 1 reply; 5+ messages in thread
From: Sterling Augustine @ 2013-05-10 21:47 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 521 bytes --]

Hello,

Enclosed is a new board file that enables testing using stdio via
gdbserver on a remote server. This is useful if, for example, firewall
policies disallow gdbserver from opening a port to listen on.

It follows Doug Evans' native-stdio-gdbserver.exp fairly closely. I
had originally tried to combine the two, but it got kind of ugly.

It's use is documented at the top of the file.

OK for trunk?

Sterling

2013-05-10  Sterling Augustine  <saugustine@google.com>

	* boards/remote-stdio-gdbserver.exp: New file.

[-- Attachment #2: remote-stdio-gdbserver.exp --]
[-- Type: application/octet-stream, Size: 6258 bytes --]

# Copyright 2011-2013 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This file is a dejagnu "board file" and is used to run the testsuite
# with a remotehost and gdbserver using stdio for communicating through
# ssh. Certain firewalls prevent gdbserver from using the usual mechanism of
# listening on a remote port, so use stdio via ssh instead.
#
# To use this file:
# bash$ cd ${build_dir}/gdb
# bash$ make check RUNTESTFLAGS="--target_board=remote-stdio-gdbserver \
#    REMOTE_USERNAME=... REMOTE_HOSTNAME=... REMOTE_PORTNUM=... \
#    [REMOTE_TMPDIR=${remote_dir}] [REMOTE_GDBSERVER=${remote_gdbserver}]"

load_generic_config "gdbserver"
process_multilib_options ""

# The default compiler for this target.
set_board_info compiler  "[find_gcc]"

set_board_info rsh_prog /usr/bin/ssh
set_board_info rcp_prog /usr/bin/scp

# Test machine info. The generic_config gdbserver reads some of these
# values from board_info, so this file must set them there.
if [info exists REMOTE_USERNAME] {
    set_board_info username $REMOTE_USERNAME
} else {
    set_board_info username unspecified_username
}
if [info exists REMOTE_HOSTNAME] {
    set_board_info hostname $REMOTE_HOSTNAME
} else {
    set_board_info hostname unspecified_hostname
}
if [info exists REMOTE_PORTNUM] {
    set_board_info portnum $REMOTE_PORTNUM
}

# Some remote machines don't have writable home directories.
if [info exists REMOTE_TMPDIR] {
    set_board_info remotedir $REMOTE_TMPDIR
}
set_board_info isremote 1

if [info exists REMOTE_GDBSERVER] {
    set_board_info gdb_server_prog $REMOTE_GDBSERVER
} else {
    set_board_info gdb_server_prog "/usr/bin/gdbserver"
}

# This gdbserver can only run a process once per session.
set_board_info gdb,do_reload_on_run 1

# There's no support for argument-passing (yet).
set_board_info noargs 1

# Can't do input (or output) in the current gdbserver.
set_board_info gdb,noinferiorio 1

# gdbserver does not intercept target file operations and perform them
# on the host.
set_board_info gdb,nofileio 1

# Hack into sockethost to pass our peculiar remote connection string.
set_board_info sockethost "stdio"
set_board_info gdb,socketport ""
set_board_info gdb,get_remote_address ${board}_get_remote_address
set_board_info use_gdb_stub 1

# We will be using the standard GDB remote protocol.
set_board_info gdb_protocol "remote"

# The argument to pass to "target remote".
# We build this once we know how the testsuite will start gdbserver.
set stdio_gdbserver_template "| @RSH_CMD@ @GDBSERVER_PROG@ @ARGS@ stdio @PROG_AND_ARGS@"

# Used to pass a value between ${board}_spawn and ${board}_get_remote_address.
set stdio_gdbserver_command "--unset--"

proc ${board}_get_remote_address { host port } {
    global stdio_gdbserver_command
    return $stdio_gdbserver_command
}

proc ${board}_build_remote_cmd { cmd } {
    global stdio_gdbserver_template

    # First parse $cmd, picking out the various pieces.
    set gdbserver_prog [lindex $cmd 0]
    set args ""
    set len [llength $cmd]

    for { set i 1 } { $i < $len } { incr i } {
	set elm [lindex $cmd $i]
	switch $elm {
	    --multi {
		set args "$args $elm"
	    }
	    --once {
		set args "$args $elm"
	    }
	    default {
		break
	    }
	}
    }

    if {[board_info [target_info name] exists rsh_prog]} {
	set rsh_cmd [board_info [target_info name] rsh_prog]
	if {[board_info [target_info name] exists username]} {
	    append rsh_cmd " -l [board_info [target_info name] username]"
	}
	if {[board_info [target_info name] exists hostname]} {
	    append rsh_cmd " [board_info [target_info name] hostname]"
	}
	if {[board_info [target_info name] exists portnum]} {
	    append rsh_cmd ":[board_info [target_info name] portnum]"
	}
    } else {
	set rsh_cmd ""
    }

    set prog_and_args [lrange $cmd $i end]

    set buf $stdio_gdbserver_template

    regsub {@RSH_CMD@} $buf $rsh_cmd buf
    regsub {@GDBSERVER_PROG@} $buf $gdbserver_prog buf
    regsub {@ARGS@} $buf $args buf
    regsub {@PROG_AND_ARGS@} $buf $prog_and_args buf

    return $buf
}

proc ${board}_spawn { board cmd } {
    global board_info

    verbose -log "${board}_spawn: $board $cmd"

    # Convert the command to start gdbserver to something to pass to
    # "target remote | ..." and save it for later retrieval by
    # ${board}_get_remote_address.
    global stdio_gdbserver_command
    set stdio_gdbserver_command [${board}_build_remote_cmd $cmd]
    verbose -log "gdbserver_command: $stdio_gdbserver_command"

    set baseboard [lindex [split $board "/"] 0]

    # We don't spawn gdbserver here, that is done by the subsequent
    # "target remote | ..." command.
    set board_info($baseboard,isremote) 0
    # Pretend as if we've started gdbserver, provide the test harness
    # with what it's waiting for.
    set result [remote_spawn $board "echo Listening on stdio"]
    set board_info($baseboard,isremote) 1

    return $result
}

proc ${board}_exec { hostname program args } {
    global board_info

    set baseboard [lindex [split $hostname "/"] 0]

    set board_info($baseboard,isremote) 0
    set result [remote_exec $hostname $program $args]
    set board_info($baseboard,isremote) 1

    return $result
}

proc ${board}_download { board host dest } {
    if {[board_info [target_info name] exists remotedir]} {
	set remotedir "[board_info [target_info name] remotedir]/"
	return [standard_download $board $host "$remotedir$dest"]
    }
    return $host
}

proc ${board}_upload {dest srcfile args} {
    return $srcfile
}

proc ${board}_file { dest op args } {
    if { $op == "delete" } {
	return 0
    }
    return [eval [list standard_file $dest $op] $args]
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] New board file remote-stdio-gdbserver.exp
  2013-05-10 21:47 [PATCH] New board file remote-stdio-gdbserver.exp Sterling Augustine
@ 2013-05-13 21:24 ` Doug Evans
  2013-05-21 17:50   ` Sterling Augustine
  0 siblings, 1 reply; 5+ messages in thread
From: Doug Evans @ 2013-05-13 21:24 UTC (permalink / raw)
  To: Sterling Augustine; +Cc: gdb-patches

On Fri, May 10, 2013 at 2:47 PM, Sterling Augustine
<saugustine@google.com> wrote:
> Hello,
>
> Enclosed is a new board file that enables testing using stdio via
> gdbserver on a remote server. This is useful if, for example, firewall
> policies disallow gdbserver from opening a port to listen on.
>
> It follows Doug Evans' native-stdio-gdbserver.exp fairly closely. I
> had originally tried to combine the two, but it got kind of ugly.
>
> It's use is documented at the top of the file.
>
> OK for trunk?
>
> Sterling
>
> 2013-05-10  Sterling Augustine  <saugustine@google.com>
>
>         * boards/remote-stdio-gdbserver.exp: New file.

Since there is a fair bit of commonality, another way to go is to
begin your file with

load_board_description "native-stdio-gdbserver"

and then add or override the bits you need.
Factoring out bits in native-stdio-gdbserver.exp so that they can be
overridden may be needed.
For proc ${board}_download you could just redefine it in your file
(seems simplest).

I think I'd prefer that if it works for you.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] New board file remote-stdio-gdbserver.exp
  2013-05-13 21:24 ` Doug Evans
@ 2013-05-21 17:50   ` Sterling Augustine
  2013-05-21 17:54     ` Doug Evans
  0 siblings, 1 reply; 5+ messages in thread
From: Sterling Augustine @ 2013-05-21 17:50 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 631 bytes --]

On Mon, May 13, 2013 at 2:24 PM, Doug Evans <dje@google.com> wrote:

> Since there is a fair bit of commonality, another way to go is to
> begin your file with
>
> load_board_description "native-stdio-gdbserver"
>
> and then add or override the bits you need.
> Factoring out bits in native-stdio-gdbserver.exp so that they can be
> overridden may be needed.
> For proc ${board}_download you could just redefine it in your file
> (seems simplest).
>
> I think I'd prefer that if it works for you.

Done. OK for trunk?

2013-05-10  Sterling Augustine  <saugustine@google.com>

        * boards/remote-stdio-gdbserver.exp: New file.

[-- Attachment #2: remote-stdio-gdbserver.exp --]
[-- Type: application/octet-stream, Size: 4033 bytes --]

# Copyright 2011-2013 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This file is a dejagnu "board file" and is used to run the testsuite
# with a remotehost and gdbserver using stdio for communicating through
# ssh. Certain firewalls prevent gdbserver from using the usual mechanism of
# listening on a remote port, so use stdio via ssh instead.
#
# To use this file:
# bash$ cd ${build_dir}/gdb
# bash$ make check RUNTESTFLAGS="--target_board=remote-stdio-gdbserver \
#    REMOTE_USERNAME=... REMOTE_HOSTNAME=... REMOTE_PORTNUM=... \
#    [REMOTE_TMPDIR=${remote_dir}] [GDBSERVER=${remote_gdbserver}]"

load_board_description "native-stdio-gdbserver"

set_board_info rsh_prog /usr/bin/ssh
set_board_info rcp_prog /usr/bin/scp

# Test machine info. The generic_config gdbserver reads some of these
# values from board_info, so this file must set them there.
if [info exists REMOTE_USERNAME] {
    set_board_info username $REMOTE_USERNAME
} else {
    set_board_info username unspecified_username
}
if [info exists REMOTE_HOSTNAME] {
    set_board_info hostname $REMOTE_HOSTNAME
} else {
    set_board_info hostname unspecified_hostname
}
if [info exists REMOTE_PORTNUM] {
    set_board_info portnum $REMOTE_PORTNUM
}

# Some remote machines don't have writable home directories.
if [info exists REMOTE_TMPDIR] {
    set_board_info remotedir $REMOTE_TMPDIR
}

unset_board_info gdb_server_prog
set_board_info gdb_server_prog "/usr/bin/gdbserver"

# Used to pass a value between ${board}_spawn and ${board}_get_remote_address.
set stdio_gdbserver_command "--unset--"

proc get_remote_login { } {
    set result ""
    if {[board_info [target_info name] exists username]} {
	append result "[board_info [target_info name] username]@"
    }
    if {[board_info [target_info name] exists hostname]} {
	append result "[board_info [target_info name] hostname]"
    }
    if {[board_info [target_info name] exists portnum]} {
	append result ":[board_info [target_info name] portnum]"
    }
    return $result
}

proc ${board}_build_remote_cmd { cmd } {
    set stdio_gdbserver_template "| @RSH_CMD@ @GDBSERVER_PROG@ @ARGS@ stdio @PROG_AND_ARGS@"

    # First parse $cmd, picking out the various pieces.
    set gdbserver_prog [lindex $cmd 0]
    set args ""
    set len [llength $cmd]

    for { set i 1 } { $i < $len } { incr i } {
	set elm [lindex $cmd $i]
	switch $elm {
	    --multi {
		set args "$args $elm"
	    }
	    --once {
		set args "$args $elm"
	    }
	    default {
		break
	    }
	}
    }

    set prog_and_args [lrange $cmd $i end]

    set buf $stdio_gdbserver_template

    set rsh_cmd "[board_info [target_info name] rsh_prog] [get_remote_login]"
    regsub {@RSH_CMD@} $buf $rsh_cmd buf
    regsub {@GDBSERVER_PROG@} $buf $gdbserver_prog buf
    regsub {@ARGS@} $buf $args buf
    regsub {@PROG_AND_ARGS@} $buf $prog_and_args buf

    return $buf
}

proc ${board}_download { board host dest } {
    if { [board_info [target_info name] exists remotedir] } {
	set remotedir "[board_info [target_info name] remotedir]/"
    } else {
	set remotedir ""
    }
    return [standard_download $board $host "$remotedir$dest"]
}

proc ${board}_upload {dest srcfile args} {
    return [standard_upload $dest $srcfile $args]
}

proc ${board}_file { dest op args } {
    if { $op == "delete" } {
	return [remote_exec [get_remote_login] "rm -f $args"]
    }
    return [eval [list standard_file $dest $op] $args]
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] New board file remote-stdio-gdbserver.exp
  2013-05-21 17:50   ` Sterling Augustine
@ 2013-05-21 17:54     ` Doug Evans
  2013-05-21 17:59       ` Sterling Augustine
  0 siblings, 1 reply; 5+ messages in thread
From: Doug Evans @ 2013-05-21 17:54 UTC (permalink / raw)
  To: Sterling Augustine; +Cc: gdb-patches

On Tue, May 21, 2013 at 10:49 AM, Sterling Augustine
<saugustine@google.com> wrote:
> On Mon, May 13, 2013 at 2:24 PM, Doug Evans <dje@google.com> wrote:
>
>> Since there is a fair bit of commonality, another way to go is to
>> begin your file with
>>
>> load_board_description "native-stdio-gdbserver"
>>
>> and then add or override the bits you need.
>> Factoring out bits in native-stdio-gdbserver.exp so that they can be
>> overridden may be needed.
>> For proc ${board}_download you could just redefine it in your file
>> (seems simplest).
>>
>> I think I'd prefer that if it works for you.
>
> Done. OK for trunk?
>
> 2013-05-10  Sterling Augustine  <saugustine@google.com>
>
>         * boards/remote-stdio-gdbserver.exp: New file.

Ok by me.
Thanks!


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] New board file remote-stdio-gdbserver.exp
  2013-05-21 17:54     ` Doug Evans
@ 2013-05-21 17:59       ` Sterling Augustine
  0 siblings, 0 replies; 5+ messages in thread
From: Sterling Augustine @ 2013-05-21 17:59 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches

On Tue, May 21, 2013 at 10:54 AM, Doug Evans <dje@google.com> wrote:
>> Done. OK for trunk?
>>
>> 2013-05-10  Sterling Augustine  <saugustine@google.com>
>>
>>         * boards/remote-stdio-gdbserver.exp: New file.
>
> Ok by me.
> Thanks!

And committed.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-05-21 17:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-10 21:47 [PATCH] New board file remote-stdio-gdbserver.exp Sterling Augustine
2013-05-13 21:24 ` Doug Evans
2013-05-21 17:50   ` Sterling Augustine
2013-05-21 17:54     ` Doug Evans
2013-05-21 17:59       ` Sterling Augustine

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox