diff options
author | Sergio Durigan Junior <sergiodj@redhat.com> | 2018-02-09 18:54:41 -0500 |
---|---|---|
committer | Sergio Durigan Junior <sergiodj@redhat.com> | 2018-02-28 11:37:10 -0500 |
commit | 25e3c82c0e927398e759e2d5e35623012b8683f7 (patch) | |
tree | 018618bdacb202d8edba887996bb1348848b7df4 /gdb/testsuite | |
parent | b4987c956dfa44ca9fd8552f63e15f5fa094b2a4 (diff) | |
download | gdb-25e3c82c0e927398e759e2d5e35623012b8683f7.zip gdb-25e3c82c0e927398e759e2d5e35623012b8683f7.tar.gz gdb-25e3c82c0e927398e759e2d5e35623012b8683f7.tar.bz2 |
Make gdbserver work with filename-only binaries
Simon mentioned on IRC that, after the startup-with-shell feature has
been implemented on gdbserver, it is not possible to specify a
filename-only binary, like:
$ gdbserver :1234 a.out
/bin/bash: line 0: exec: a.out: not found
During startup program exited with code 127.
Exiting
This happens on systems where the current directory "." is not listed
in the PATH environment variable. Although including "." in the PATH
variable is a possible workaround, this can be considered a regression
because before startup-with-shell it was possible to use only the
filename (due to reason that gdbserver used "exec*" directly).
The idea of the patch is to verify if the program path provided by the
user (or by the remote protocol) contains a directory separator
character. If it doesn't, it means we're dealing with a filename-only
binary, so we call "gdb_abspath" to properly expand it and transform
it into a full path. Otherwise, we leave the program path untouched.
This mimicks the behaviour seen on GDB (look at "openp" and
"attach_inferior", for example).
I am also submitting a testcase which exercises the scenario described
above. This test requires gdbserver to be executed in a different CWD
than the original, so I also created a helper function, "with_cwd" (on
testsuite/lib/gdb.exp), which takes care of cd'ing into and out of the
specified dir.
Built and regtested on BuildBot, without regressions.
gdb/ChangeLog:
2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com>
Simon Marchi <simon.marchi@polymtl.ca>
* common/common-utils.c: Include "sys/stat.h".
(is_regular_file): Move here from "source.c"; change return
type to "bool".
* common/common-utils.h (is_regular_file): New prototype.
* common/pathstuff.c (contains_dir_separator): New function.
* common/pathstuff.h (contains_dir_separator): New prototype.
* source.c: Don't include "sys/stat.h".
(is_regular_file): Move to "common/common-utils.c".
gdb/gdbserver/ChangeLog:
2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com>
* server.c: Include "filenames.h" and "pathstuff.h".
(program_name): Delete variable.
(program_path): New anonymous class.
(get_exec_wrapper): Use "program_path" instead of
"program_name".
(handle_v_run): Likewise.
(captured_main): Likewise.
(process_serial_event): Likewise.
gdb/testsuite/ChangeLog:
2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.server/abspath.exp: New file.
* lib/gdb.exp (with_cwd): New procedure.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/testsuite/gdb.server/abspath.exp | 58 | ||||
-rw-r--r-- | gdb/testsuite/lib/gdb.exp | 24 |
3 files changed, 87 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 59bbc6e..63c6263 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com> + + * gdb.server/abspath.exp: New file. + * lib/gdb.exp (with_cwd): New procedure. + 2018-02-28 Simon Marchi <simon.marchi@ericsson.com> * lib/gdb.exp (gdb_is_target_1): Add prompt_regexp parameter and diff --git a/gdb/testsuite/gdb.server/abspath.exp b/gdb/testsuite/gdb.server/abspath.exp new file mode 100644 index 0000000..726ff58 --- /dev/null +++ b/gdb/testsuite/gdb.server/abspath.exp @@ -0,0 +1,58 @@ +# This testcase is part of GDB, the GNU debugger. + +# Copyright 2018 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/>. + +# Test that gdbserver performs path expansion/adjustment when we +# provide just a filename (without any path specifications) to it. + +load_lib gdbserver-support.exp + +standard_testfile normal.c + +if { [skip_gdbserver_tests] } { + return 0 +} + +# Because we're relying on being able to change our CWD before +# executing gdbserver, we just run if we're not testing with a remote +# target. +if { [is_remote target] } { + return 0 +} + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } { + return -1 +} + +# Make sure we're disconnected, in case we're testing with an +# extended-remote board, therefore already connected. +gdb_test "disconnect" ".*" + +set target_exec [gdbserver_download_current_prog] + +# Switch to where $target_exec lives, and execute gdbserver from +# there. +with_cwd "[file dirname $target_exec]" { + set target_execname [file tail $target_exec] + set res [gdbserver_start "" $target_execname] + + set gdbserver_protocol [lindex $res 0] + set gdbserver_gdbport [lindex $res 1] + gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport + + gdb_breakpoint main + gdb_test "continue" "Breakpoint $decimal.* main.*" "continue to main" +} diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 9102e54..4d48f5e 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -2054,6 +2054,30 @@ proc save_vars { vars body } { } } +# Run tests in BODY with the current working directory (CWD) set to +# DIR. When BODY is finished, restore the original CWD. Return the +# result of BODY. +# +# This procedure doesn't check if DIR is a valid directory, so you +# have to make sure of that. + +proc with_cwd { dir body } { + set saved_dir [pwd] + verbose -log "Switching to directory $dir (saved CWD: $saved_dir)." + cd $dir + + set code [catch {uplevel 1 $body} result] + + verbose -log "Switching back to $saved_dir." + cd $saved_dir + + if {$code == 1} { + global errorInfo errorCode + return -code $code -errorinfo $errorInfo -errorcode $errorCode $result + } else { + return -code $code $result + } +} # Run tests in BODY with GDB prompt and variable $gdb_prompt set to # PROMPT. When BODY is finished, restore GDB prompt and variable |