binutils-gdb/gdb/testsuite/gdb.server
Sergio Durigan Junior 25e3c82c0e 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.
2018-02-28 11:37:10 -05:00
..
abspath.exp Make gdbserver work with filename-only binaries 2018-02-28 11:37:10 -05:00
connect-stopped-target.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
connect-stopped-target.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
connect-with-no-symbol-file.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
connect-with-no-symbol-file.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
connect-without-multi-process.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
connect-without-multi-process.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
ext-attach.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
ext-attach.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
ext-restart.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
ext-run.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
ext-wrapper.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
file-transfer.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
no-thread-db.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
no-thread-db.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
non-existing-program.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
normal.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
reconnect-ctrl-c.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
reconnect-ctrl-c.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
run-without-local-binary.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
server-exec-info.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
server-kill.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
server-kill.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
server-mon.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
server-run.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
server.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
solib-list-lib.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
solib-list-main.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
solib-list.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
stop-reply-no-thread.c Fix backwards compatibility with old GDBservers (PR remote/22597) 2018-01-11 00:23:04 +00:00
stop-reply-no-thread.exp Fix backwards compatibility with old GDBservers (PR remote/22597) 2018-01-11 00:23:04 +00:00
transfer.txt
unittest.exp Fix GDBserver build failure when $development is false 2018-01-08 10:09:33 +00:00
wrapper.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
wrapper.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00