1 # Copyright 2010 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Override its functions
17 load_config gdbserver.exp
19 proc port_open { port } {
20 set fi [open "/proc/net/tcp" "r"]
21 fconfigure $fi -translation binary
25 # 0: 00000000:07D0 00000000:0000 0A 00000000:00000000 00:00000000 00000000 500 ...
27 set port_hex4 [format "%04X" $port]
28 return [regexp -line "^ *\[0-9\]+: 0100007F:${port_hex4} 00000000:0000 0A " $data]
31 # OPTIONS and ARGUMENTS are ignored now.
32 proc gdbserver_start { options arguments } {
37 verbose -log "gdbserver_start options=$options arguments=$arguments"
39 if [port_open $port] {
40 error "Port $port is already allocated"
43 # FIXME: IPv6 wrt /proc/net/tcp.
44 set cmd "nc -l 127.0.0.1 $port <>/proc/ugdb >&0"
46 regsub -all { } $cmd {\ } cmd
47 set cmd "bash -c $cmd"
48 set server_spawn_id [remote_spawn target $cmd]
50 for {set i 0} {$i < $timeout} {incr i} {
51 if [port_open $port] {
57 error "Port $port is still closed"
60 # It should be "extended-remote" but gdbserver_start_extended prepends
61 # another "extended-" string.
62 return [list "remote" "localhost:$port"]
65 load_lib mi-support.exp
67 proc mi_gdb_start { args } {
68 set retval [default_mi_gdb_start $args]
73 set test "-gdb-set debug remote 1"
74 gdb_test_multiple $test $test {
75 -re "\\\^done\r\n$mi_gdb_prompt$" {
87 set retval [default_gdb_start]
90 gdb_test "set debug remote 1"