aboutsummaryrefslogtreecommitdiff
path: root/gdb/doc
diff options
context:
space:
mode:
authorSergio Durigan Junior <sergiodj@redhat.com>2017-06-29 15:06:07 -0400
committerSergio Durigan Junior <sergiodj@redhat.com>2017-08-31 17:22:10 -0400
commit0a2dde4a321d2f7bd2ded9a558b9ae92892de0e2 (patch)
tree509bbdba32cf8c4c63140e36a8b02df75dcbac38 /gdb/doc
parente4f2723003859dc6b33ca0dadbc4a7659ebf1643 (diff)
downloadgdb-0a2dde4a321d2f7bd2ded9a558b9ae92892de0e2.zip
gdb-0a2dde4a321d2f7bd2ded9a558b9ae92892de0e2.tar.gz
gdb-0a2dde4a321d2f7bd2ded9a558b9ae92892de0e2.tar.bz2
Implement the ability to set/unset environment variables to GDBserver when starting the inferior
This patch implements the ability to set/unset environment variables on the remote target, mimicking what GDB already offers to the user. There are two features present here: user-set and user-unset environment variables. User-set environment variables are only the variables that are explicitly set by the user, using the 'set environment' command. This means that variables that were already present in the environment when starting GDB/GDBserver are not transmitted/considered by this feature. User-unset environment variables are variables that are explicitly unset by the user, using the 'unset environment' command. The idea behind this patch is to store user-set and user-unset environment variables in two separate sets, both part of gdb_environ. Then, when extended_remote_create_inferior is preparing to start the inferior, it will iterate over the two sets and set/unset variables accordingly. Three new packets are introduced: - QEnvironmentHexEncoded, which is used to set environment variables, and contains an hex-encoded string in the format "VAR=VALUE" (VALUE can be empty if the user set a variable with a null value, by doing 'set environment VAR='). - QEnvironmentUnset, which is used to unset environment variables, and contains an hex-encoded string in the format "VAR". - QEnvironmentReset, which is always the first packet to be transmitted, and is used to reset the environment, i.e., discard any changes made by the user on previous runs. The QEnvironmentHexEncoded packet is inspired on LLDB's extensions to the RSP. Details about it can be seen here: <https://raw.githubusercontent.com/llvm-mirror/lldb/master/docs/lldb-gdb-remote.txt> I decided not to implement the QEnvironment packet because it is considered deprecated by LLDB. This packet, on LLDB, serves the same purpose of QEnvironmentHexEncoded, but sends the information using a plain text, non-hex-encoded string. The other two packets are new. This patch also includes updates to the documentation, testsuite, and unit tests, without introducing regressions. gdb/ChangeLog: 2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com> * NEWS (Changes since GDB 8.0): Add entry mentioning new support for setting/unsetting environment variables on the remote target. (New remote packets): Add entries for QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset. * common/environ.c (gdb_environ::operator=): Extend method to handle m_user_set_env_list and m_user_unset_env_list. (gdb_environ::clear): Likewise. (match_var_in_string): Change type of first parameter from 'char *' to 'const char *'. (gdb_environ::set): Extend method to handle m_user_set_env_list and m_user_unset_env_list. (gdb_environ::unset): Likewise. (gdb_environ::clear_user_set_env): New method. (gdb_environ::user_set_envp): Likewise. (gdb_environ::user_unset_envp): Likewise. * common/environ.h (gdb_environ): Handle m_user_set_env_list and m_user_unset_env_list on move constructor/assignment. (unset): Add new default parameter 'update_unset_list = true'. (clear_user_set_env): New method. (user_set_envp): Likewise. (user_unset_envp): Likewise. (m_user_set_env_list): New std::set. (m_user_unset_env_list): Likewise. * common/rsp-low.c (hex2str): New function. (bin2hex): New overload for bin2hex function. * common/rsp-low.c (hex2str): New prototype. (str2hex): New overload prototype. * remote.c: Include "environ.h". Add QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset. (remote_protocol_features): Add QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset packets. (send_environment_packet): New function. (extended_remote_environment_support): Likewise. (extended_remote_create_inferior): Call extended_remote_environment_support. (_initialize_remote): Add QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset packet configs. * unittests/environ-selftests.c (gdb_selftest_env_var): New variable. (test_vector_initialization): New function. (test_init_from_host_environ): Likewise. (test_reinit_from_host_environ): Likewise. (test_set_A_unset_B_unset_A_cannot_find_A_can_find_B): Likewise. (test_unset_set_empty_vector): Likewise. (test_vector_clear): Likewise. (test_std_move): Likewise. (test_move_constructor): (test_self_move): Likewise. (test_set_unset_reset): Likewise. (run_tests): Rewrite in terms of the functions above. gdb/gdbserver/ChangeLog: 2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com> * server.c (handle_general_set): Handle QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset packets. (handle_query): Inform remote that QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset are supported. gdb/doc/ChangeLog: 2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.texinfo (set environment): Add @anchor. Explain that environment variables set by the user are sent to GDBserver. (unset environment): Likewise, but for unsetting variables. (Connecting) <Remote Packet>: Add "environment-hex-encoded", "QEnvironmentHexEncoded", "environment-unset", "QEnvironmentUnset", "environment-reset" and "QEnvironmentReset" to the table. (Remote Protocol) <QEnvironmentHexEncoded, QEnvironmentUnset, QEnvironmentReset>: New item, explaining the packet. gdb/testsuite/ChangeLog: 2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.base/share-env-with-gdbserver.c: New file. * gdb.base/share-env-with-gdbserver.exp: Likewise.
Diffstat (limited to 'gdb/doc')
-rw-r--r--gdb/doc/ChangeLog11
-rw-r--r--gdb/doc/gdb.texinfo116
2 files changed, 127 insertions, 0 deletions
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index bf82730..106d545 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,14 @@
+2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com>
+
+ * gdb.texinfo (set environment): Add @anchor. Explain that
+ environment variables set by the user are sent to GDBserver.
+ (unset environment): Likewise, but for unsetting variables.
+ (Connecting) <Remote Packet>: Add "environment-hex-encoded",
+ "QEnvironmentHexEncoded", "environment-unset", "QEnvironmentUnset",
+ "environment-reset" and "QEnvironmentReset" to the table.
+ (Remote Protocol) <QEnvironmentHexEncoded, QEnvironmentUnset,
+ QEnvironmentReset>: New item, explaining the packet.
+
2017-08-23 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.texinfo (Compiling and Injecting Code): Add to subsection
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index d977b23..874cdeb 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -2363,6 +2363,7 @@ print the names and values of all environment variables to be given to
your program. You can abbreviate @code{environment} as @code{env}.
@kindex set environment
+@anchor{set environment}
@item set environment @var{varname} @r{[}=@var{value}@r{]}
Set environment variable @var{varname} to @var{value}. The value
changes for your program (and the shell @value{GDBN} uses to launch
@@ -2391,12 +2392,21 @@ If necessary, you can avoid that by using the @samp{env} program as a
wrapper instead of using @code{set environment}. @xref{set
exec-wrapper}, for an example doing just that.
+Environment variables that are set by the user are also transmitted to
+@command{gdbserver} to be used when starting the remote inferior.
+@pxref{QEnvironmentHexEncoded}.
+
@kindex unset environment
+@anchor{unset environment}
@item unset environment @var{varname}
Remove variable @var{varname} from the environment to be passed to your
program. This is different from @samp{set env @var{varname} =};
@code{unset environment} removes the variable from the environment,
rather than assigning it an empty value.
+
+Environment variables that are unset by the user are also unset on
+@command{gdbserver} when starting the remote inferior.
+@pxref{QEnvironmentUnset}.
@end table
@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
@@ -20849,6 +20859,18 @@ are:
@tab @code{QStartupWithShell}
@tab @code{set startup-with-shell}
+@item @code{environment-hex-encoded}
+@tab @code{QEnvironmentHexEncoded}
+@tab @code{set environment}
+
+@item @code{environment-unset}
+@tab @code{QEnvironmentUnset}
+@tab @code{unset environment}
+
+@item @code{environment-reset}
+@tab @code{QEnvironmentReset}
+@tab @code{Reset the inferior environment (i.e., unset user-set variables)}
+
@item @code{conditional-breakpoints-packet}
@tab @code{Z0 and Z1}
@tab @code{Support for target-side breakpoint condition evaluation}
@@ -36604,6 +36626,100 @@ actually support starting the inferior using a shell.
Use of this packet is controlled by the @code{set startup-with-shell}
command; @pxref{set startup-with-shell}.
+@item QEnvironmentHexEncoded:@var{hex-value}
+@anchor{QEnvironmentHexEncoded}
+@cindex set environment variable, remote request
+@cindex @samp{QEnvironmentHexEncoded} packet
+On UNIX-like targets, it is possible to set environment variables that
+will be passed to the inferior during the startup process. This
+packet is used to inform @command{gdbserver} of an environment
+variable that has been defined by the user on @value{GDBN} (@pxref{set
+environment}).
+
+The packet is composed by @var{hex-value}, an hex encoded
+representation of the @var{name=value} format representing an
+environment variable. The name of the environment variable is
+represented by @var{name}, and the value to be assigned to the
+environment variable is represented by @var{value}. If the variable
+has no value (i.e., the value is @code{null}), then @var{value} will
+not be present.
+
+This packet is only available in extended mode (@pxref{extended
+mode}).
+
+Reply:
+@table @samp
+@item OK
+The request succeeded.
+@end table
+
+This packet is not probed by default; the remote stub must request it,
+by supplying an appropriate @samp{qSupported} response
+(@pxref{qSupported}). This should only be done on targets that
+actually support passing environment variables to the starting
+inferior.
+
+This packet is related to the @code{set environment} command;
+@pxref{set environment}.
+
+@item QEnvironmentUnset:@var{hex-value}
+@anchor{QEnvironmentUnset}
+@cindex unset environment variable, remote request
+@cindex @samp{QEnvironmentUnset} packet
+On UNIX-like targets, it is possible to unset environment variables
+before starting the inferior in the remote target. This packet is
+used to inform @command{gdbserver} of an environment variable that has
+been unset by the user on @value{GDBN} (@pxref{unset environment}).
+
+The packet is composed by @var{hex-value}, an hex encoded
+representation of the name of the environment variable to be unset.
+
+This packet is only available in extended mode (@pxref{extended
+mode}).
+
+Reply:
+@table @samp
+@item OK
+The request succeeded.
+@end table
+
+This packet is not probed by default; the remote stub must request it,
+by supplying an appropriate @samp{qSupported} response
+(@pxref{qSupported}). This should only be done on targets that
+actually support passing environment variables to the starting
+inferior.
+
+This packet is related to the @code{unset environment} command;
+@pxref{unset environment}.
+
+@item QEnvironmentReset
+@anchor{QEnvironmentReset}
+@cindex reset environment, remote request
+@cindex @samp{QEnvironmentReset} packet
+On UNIX-like targets, this packet is used to reset the state of
+environment variables in the remote target before starting the
+inferior. In this context, reset means unsetting all environment
+variables that were previously set by the user (i.e., were not
+initially present in the environment). It is sent to
+@command{gdbserver} before the @samp{QEnvironmentHexEncoded}
+(@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
+(@pxref{QEnvironmentUnset}) packets.
+
+This packet is only available in extended mode (@pxref{extended
+mode}).
+
+Reply:
+@table @samp
+@item OK
+The request succeeded.
+@end table
+
+This packet is not probed by default; the remote stub must request it,
+by supplying an appropriate @samp{qSupported} response
+(@pxref{qSupported}). This should only be done on targets that
+actually support passing environment variables to the starting
+inferior.
+
@item qfThreadInfo
@itemx qsThreadInfo
@cindex list active threads, remote request