binutils-gdb/gdb/nat
Sergio Durigan Junior d092c5a246 Implement "set cwd" command on GDB
This commit adds new "set/show cwd" commands, which are used to
set/show the current working directory of the inferior that will be
started.

The idea here is that "set cwd" will become the de facto way of
setting the inferior's cwd.  Currently, the user can use "cd" for
that, but there are side effects: with "cd", GDB also switches to
another directory, and that can impact the loading of scripts and
other files.  With "set cwd", we separate the logic into a new
command.

To maintain backward compatibility, if the user issues a "cd" command
but doesn't use "set cwd", then the inferior's cwd will still be
changed according to what the user specified.  However, "set cwd" has
precedence over "cd", so it can always be used to override it.

"set cwd" works in the following way:

- If the user sets the inferior's cwd by using "set cwd", then this
  directory is saved into current_inferior ()->cwd and is used when
  the inferior is started (see below).

- If the user doesn't set the inferior's cwd by using "set cwd", but
  rather use the "cd" command as before, then this directory is
  inherited by the inferior because GDB will have chdir'd into it.

On Unix-like hosts, the way the directory is changed before the
inferior execution is by expanding the user set directory before the
fork, and then "chdir" after the call to fork/vfork on
"fork_inferior", but before the actual execution.  On Windows, the
inferior cwd set by the user is passed directly to the CreateProcess
call, which takes care of the actual chdir for us.

This way, we'll make sure that GDB's cwd is not affected by the user
set cwd.

gdb/ChangeLog:
2017-10-04  Sergio Durigan Junior  <sergiodj@redhat.com>

	* NEWS (New commands): Mention "set/show cwd".
	* cli/cli-cmds.c (_initialize_cli_cmds): Mention "set cwd" on
	"cd" command's help text.
	* common/common-inferior.h (get_inferior_cwd): New prototype.
	* infcmd.c (inferior_cwd_scratch): New global variable.
	(set_inferior_cwd): New function.
	(get_inferior_cwd): Likewise.
	(set_cwd_command): Likewise.
	(show_cwd_command): Likewise.
	(_initialize_infcmd): Add "set/show cwd" commands.
	* inferior.h (class inferior) <cwd>: New field.
	* nat/fork-inferior.c: Include "gdb_tilde_expand.h".
	(fork_inferior): Change inferior's cwd before its execution.
	* windows-nat.c (windows_create_inferior): Pass inferior's cwd
	to CreateProcess.

gdb/gdbserver/ChangeLog:
2017-10-04  Sergio Durigan Junior  <sergiodj@redhat.com>

	* inferiors.c (current_inferior_cwd): New global variable.
	(get_inferior_cwd): New function.
	* inferiors.h (struct process_info) <cwd>: New field.

gdb/doc/ChangeLog:
2017-10-04  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.texinfo (Starting your Program) <The working directory.>:
	Mention new "set cwd" command.
	(Working Directory) <Your Program's Working Directory>:
	Rephrase to explain that "set cwd" exists and is the default
	way to change the inferior's cwd.

gdb/testsuite/ChangeLog:
2017-10-04  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.base/set-cwd.c: New file.
	* gdb.base/set-cwd.exp: Likewise.
2017-10-04 01:59:30 -04:00
..
aarch64-linux-hw-point.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
aarch64-linux-hw-point.h Include break-common.h in nat/aarch64-linux-hw-point.h 2017-01-06 14:33:01 +00:00
aarch64-linux.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
aarch64-linux.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
amd64-linux-siginfo.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
amd64-linux-siginfo.h Include signal.h in nat/amd64-linux-siginfo.h 2017-01-06 14:33:01 +00:00
fork-inferior.c Implement "set cwd" command on GDB 2017-10-04 01:59:30 -04:00
fork-inferior.h Add ATTRIBUTE_PRINTF to trace_start_error 2017-06-17 23:19:25 +02:00
gdb_ptrace.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gdb_thread_db.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
glibc_thread_db.h Move shared native target specific code to gdb/nat 2014-06-20 14:06:48 +01:00
linux-btrace.c Introduce and use gdb_file_up 2017-08-03 07:58:52 -06:00
linux-btrace.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
linux-namespaces.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
linux-namespaces.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
linux-nat.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
linux-osdata.c Introduce and use gdb_file_up 2017-08-03 07:58:52 -06:00
linux-osdata.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
linux-personality.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
linux-personality.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
linux-procfs.c Rename _const functions to use overloading instead 2017-09-11 15:46:12 -06:00
linux-procfs.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
linux-ptrace.c nat/linux-ptrace.c: add missing gdb_byte* cast 2017-06-18 23:29:03 +02:00
linux-ptrace.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
linux-waitpid.c linux-waitpid: Get rid of format string warning 2017-09-21 15:19:40 +02:00
linux-waitpid.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
mips-linux-watch.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
mips-linux-watch.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
ppc-linux.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
ppc-linux.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
x86-cpuid.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
x86-dregs.c x86-dregs: Print debug registers one per line 2017-06-25 12:40:10 +02:00
x86-dregs.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
x86-gcc-cpuid.h Sync up x86-gcc-cpuid.h with cpuid.h from gcc-6 branch. 2017-02-17 11:43:39 +01:00
x86-linux-dregs.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
x86-linux-dregs.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
x86-linux.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
x86-linux.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00