diff options
author | Sergio Durigan Junior <sergiodj@redhat.com> | 2017-09-11 01:13:50 -0400 |
---|---|---|
committer | Sergio Durigan Junior <sergiodj@redhat.com> | 2017-10-04 01:59:30 -0400 |
commit | d092c5a2465ece3435131ae6fef1ccb6e70986cb (patch) | |
tree | 17bc555baf4ff5b156be5ab410797b4c526e6a6c /gdb/doc | |
parent | 7da0a8867419fc4a2a64d49cc71a14bd145cebff (diff) | |
download | gdb-d092c5a2465ece3435131ae6fef1ccb6e70986cb.zip gdb-d092c5a2465ece3435131ae6fef1ccb6e70986cb.tar.gz gdb-d092c5a2465ece3435131ae6fef1ccb6e70986cb.tar.bz2 |
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.
Diffstat (limited to 'gdb/doc')
-rw-r--r-- | gdb/doc/ChangeLog | 8 | ||||
-rw-r--r-- | gdb/doc/gdb.texinfo | 55 |
2 files changed, 50 insertions, 13 deletions
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 3e74640..4ded14a 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,11 @@ +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. + 2017-09-25 Andreas Arnez <arnez@linux.vnet.ibm.com> * gdb.texinfo (S/390 and System z Features): Document the new diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 9905ff6..a68107d 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -2057,8 +2057,9 @@ environment} to change parts of the environment that affect your program. @xref{Environment, ,Your Program's Environment}. @item The @emph{working directory.} -Your program inherits its working directory from @value{GDBN}. You can set -the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}. +You can set your program's working directory with the command +@kbd{set cwd}. If you do not set any working directory with this +command, your program will inherit @value{GDBN}'s working directory. @xref{Working Directory, ,Your Program's Working Directory}. @item The @emph{standard input and output.} @@ -2434,23 +2435,51 @@ variables to files that are only run when you sign on, such as @section Your Program's Working Directory @cindex working directory (of your program) -Each time you start your program with @code{run}, it inherits its -working directory from the current working directory of @value{GDBN}. -The @value{GDBN} working directory is initially whatever it inherited -from its parent process (typically the shell), but you can specify a new -working directory in @value{GDBN} with the @code{cd} command. - -The @value{GDBN} working directory also serves as a default for the commands -that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to -Specify Files}. +Each time you start your program with @code{run}, the inferior will be +initialized with the current working directory specified by the +@kbd{set cwd} command. If no directory has been specified by this +command, then the inferior will inherit @value{GDBN}'s current working +directory as its working directory. + +@table @code +@kindex set cwd +@cindex change inferior's working directory +@anchor{set cwd command} +@item set cwd @r{[}@var{directory}@r{]} +Set the inferior's working directory to @var{directory}, which will be +@code{glob}-expanded in order to resolve tildes (@file{~}). If no +argument has been specified, the command clears the setting and resets +it to an empty state. This setting has no effect on @value{GDBN}'s +working directory, and it only takes effect the next time you start +the inferior. The @file{~} in @var{directory} is a short for the +@dfn{home directory}, usually pointed to by the @env{HOME} environment +variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN} +uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as +fallback. + +You can also change @value{GDBN}'s current working directory by using +the @code{cd} command. +@xref{cd command} + +@kindex show cwd +@cindex show inferior's working directory +@item show cwd +Show the inferior's working directory. If no directory has been +specified by @kbd{set cwd}, then the default inferior's working +directory is the same as @value{GDBN}'s working directory. -@table @code @kindex cd -@cindex change working directory +@cindex change @value{GDBN}'s working directory +@anchor{cd command} @item cd @r{[}@var{directory}@r{]} Set the @value{GDBN} working directory to @var{directory}. If not given, @var{directory} uses @file{'~'}. +The @value{GDBN} working directory serves as a default for the +commands that specify files for @value{GDBN} to operate on. +@xref{Files, ,Commands to Specify Files}. +@xref{set cwd command} + @kindex pwd @item pwd Print the @value{GDBN} working directory. |