# Copyright 2010 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 . # Override its functions load_config gdbserver.exp proc port_open { port } { set fi [open "/proc/net/tcp" "r"] fconfigure $fi -translation binary set data [read $fi] close $fi # 0: 00000000:07D0 00000000:0000 0A 00000000:00000000 00:00000000 00000000 500 ... set port_hex4 [format "%04X" $port] return [regexp -line "^ *\[0-9\]+: 0100007F:${port_hex4} 00000000:0000 0A " $data] } # OPTIONS and ARGUMENTS are ignored now. proc gdbserver_start { options arguments } { set port 2000 set delay 0.1 set timeout 100 verbose -log "gdbserver_start options=$options arguments=$arguments" if [port_open $port] { error "Port $port is already allocated" } # FIXME: IPv6 wrt /proc/net/tcp. set cmd "nc -l 127.0.0.1 $port <>/proc/ugdb >&0" set cmd "exec $cmd" regsub -all { } $cmd {\ } cmd set cmd "bash -c $cmd" set server_spawn_id [remote_spawn target $cmd] for {set i 0} {$i < $timeout} {incr i} { if [port_open $port] { break } sleep $delay } if {$i == $timeout} { error "Port $port is still closed" } return [list "extended-remote" "localhost:$port"] } load_lib mi-support.exp proc mi_gdb_start { args } { set retval [default_mi_gdb_start $args] if {$retval == 0} { global mi_gdb_prompt ugdb_debug set test "-gdb-set debug remote $ugdb_debug" gdb_test_multiple $test $test { -re "\\\^done\r\n$mi_gdb_prompt$" { pass $test } } } return $retval } load_lib gdb.exp proc gdb_start { } { set retval [default_gdb_start] if {$retval == 0} { global ugdb_debug gdb_test_no_output "set debug remote $ugdb_debug" gdb_test_no_output "set target-async on" gdb_test_no_output "set non-stop on" } return $retval } load_lib gdbserver-support.exp # Do not prepend the "extended-" string. proc gdbserver_start_extended { } { set res [gdbserver_start "--multi" ""] set gdbserver_protocol [lindex $res 0] set gdbserver_gdbport [lindex $res 1] return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] }