aboutsummaryrefslogtreecommitdiff
path: root/gdb/remote.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/remote.c')
-rw-r--r--gdb/remote.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/gdb/remote.c b/gdb/remote.c
index 2249533..3347dd8 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -73,6 +73,7 @@
#include "record-btrace.h"
#include <algorithm>
#include "common/scoped_restore.h"
+#include "environ.h"
/* Temp hacks for tracepoint encoding migration. */
static char *target_buf;
@@ -1430,6 +1431,9 @@ enum {
PACKET_QCatchSyscalls,
PACKET_QProgramSignals,
PACKET_QStartupWithShell,
+ PACKET_QEnvironmentHexEncoded,
+ PACKET_QEnvironmentReset,
+ PACKET_QEnvironmentUnset,
PACKET_qCRC,
PACKET_qSearch_memory,
PACKET_vAttach,
@@ -4637,6 +4641,12 @@ static const struct protocol_feature remote_protocol_features[] = {
PACKET_QProgramSignals },
{ "QStartupWithShell", PACKET_DISABLE, remote_supported_packet,
PACKET_QStartupWithShell },
+ { "QEnvironmentHexEncoded", PACKET_DISABLE, remote_supported_packet,
+ PACKET_QEnvironmentHexEncoded },
+ { "QEnvironmentReset", PACKET_DISABLE, remote_supported_packet,
+ PACKET_QEnvironmentReset },
+ { "QEnvironmentUnset", PACKET_DISABLE, remote_supported_packet,
+ PACKET_QEnvironmentUnset },
{ "QStartNoAckMode", PACKET_DISABLE, remote_supported_packet,
PACKET_QStartNoAckMode },
{ "multiprocess", PACKET_DISABLE, remote_supported_packet,
@@ -9556,6 +9566,57 @@ extended_remote_run (const std::string &args)
}
}
+/* Helper function to send set/unset environment packets. ACTION is
+ either "set" or "unset". PACKET is either "QEnvironmentHexEncoded"
+ or "QEnvironmentUnsetVariable". VALUE is the variable to be
+ sent. */
+
+static void
+send_environment_packet (struct remote_state *rs,
+ const char *action,
+ const char *packet,
+ const char *value)
+{
+ /* Convert the environment variable to an hex string, which
+ is the best format to be transmitted over the wire. */
+ std::string encoded_value = bin2hex ((const gdb_byte *) value,
+ strlen (value));
+
+ xsnprintf (rs->buf, get_remote_packet_size (),
+ "%s:%s", packet, encoded_value.c_str ());
+
+ putpkt (rs->buf);
+ getpkt (&rs->buf, &rs->buf_size, 0);
+ if (strcmp (rs->buf, "OK") != 0)
+ warning (_("Unable to %s environment variable '%s' on remote."),
+ action, value);
+}
+
+/* Helper function to handle the QEnvironment* packets. */
+
+static void
+extended_remote_environment_support (struct remote_state *rs)
+{
+ if (packet_support (PACKET_QEnvironmentReset) != PACKET_DISABLE)
+ {
+ putpkt ("QEnvironmentReset");
+ getpkt (&rs->buf, &rs->buf_size, 0);
+ if (strcmp (rs->buf, "OK") != 0)
+ warning (_("Unable to reset environment on remote."));
+ }
+
+ gdb_environ *e = &current_inferior ()->environment;
+
+ if (packet_support (PACKET_QEnvironmentHexEncoded) != PACKET_DISABLE)
+ for (const std::string &el : e->user_set_env ())
+ send_environment_packet (rs, "set", "QEnvironmentHexEncoded",
+ el.c_str ());
+
+ if (packet_support (PACKET_QEnvironmentUnset) != PACKET_DISABLE)
+ for (const std::string &el : e->user_unset_env ())
+ send_environment_packet (rs, "unset", "QEnvironmentUnset", el.c_str ());
+}
+
/* In the extended protocol we want to be able to do things like
"run" and have them basically work as expected. So we need
a special create_inferior function. We support changing the
@@ -9596,6 +9657,8 @@ Remote replied unexpectedly while setting startup-with-shell: %s"),
rs->buf);
}
+ extended_remote_environment_support (rs);
+
/* Now restart the remote server. */
run_worked = extended_remote_run (args) != -1;
if (!run_worked)
@@ -14067,6 +14130,19 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL,
add_packet_config_cmd (&remote_protocol_packets[PACKET_QStartupWithShell],
"QStartupWithShell", "startup-with-shell", 0);
+ add_packet_config_cmd (&remote_protocol_packets
+ [PACKET_QEnvironmentHexEncoded],
+ "QEnvironmentHexEncoded", "environment-hex-encoded",
+ 0);
+
+ add_packet_config_cmd (&remote_protocol_packets[PACKET_QEnvironmentReset],
+ "QEnvironmentReset", "environment-reset",
+ 0);
+
+ add_packet_config_cmd (&remote_protocol_packets[PACKET_QEnvironmentUnset],
+ "QEnvironmentUnset", "environment-unset",
+ 0);
+
add_packet_config_cmd (&remote_protocol_packets[PACKET_qSymbol],
"qSymbol", "symbol-lookup", 0);