aboutsummaryrefslogtreecommitdiff
path: root/gdb/remote.c
diff options
context:
space:
mode:
authorSergio Durigan Junior <sergiodj@redhat.com>2017-09-20 19:15:40 -0400
committerSergio Durigan Junior <sergiodj@redhat.com>2017-10-04 02:01:45 -0400
commitbc3b087de2401c65c02730d346e8bea4dc0504ae (patch)
tree49dff0f07ac85554669e8f7d807a4527743e7ab5 /gdb/remote.c
parentd092c5a2465ece3435131ae6fef1ccb6e70986cb (diff)
downloadgdb-bc3b087de2401c65c02730d346e8bea4dc0504ae.zip
gdb-bc3b087de2401c65c02730d346e8bea4dc0504ae.tar.gz
gdb-bc3b087de2401c65c02730d346e8bea4dc0504ae.tar.bz2
Extend "set cwd" to work on gdbserver
This is the "natural" extension necessary for the "set cwd" command (and the whole "set the inferior's cwd" logic) to work on gdbserver. The idea here is to have a new remote packet, QSetWorkingDir (name adopted from LLDB's extension to the RSP, as can be seen at <https://raw.githubusercontent.com/llvm-mirror/lldb/master/docs/lldb-gdb-remote.txt>), which sends an hex-encoded string representing the working directory that the remote inferior will use. There is a slight difference from the packet proposed by LLDB: GDB's version will accept empty arguments, meaning that the user wants to clear the previously set working directory for the inferior (i.e., "set cwd" without arguments on GDB). For UNIX-like targets this feature is already implemented on nat/fork-inferior.c, and all gdbserver has to do is to basically implement "set_inferior_cwd" and call it whenever such packet arrives. For other targets, like Windows, it is possible to use the existing "get_inferior_cwd" function and do the necessary steps to make sure that the inferior will use the specified working directory. Aside from that, the patch consists basically of updates to the testcase (making it available on remote targets) and the documentation. No regressions found. gdb/ChangeLog: 2017-10-04 Sergio Durigan Junior <sergiodj@redhat.com> * NEWS (Changes since GDB 8.0): Add entry about new 'set-cwd-on-gdbserver' feature. (New remote packets): Add entry for QSetWorkingDir. * common/common-inferior.h (set_inferior_cwd): New prototype. * infcmd.c (set_inferior_cwd): Remove "static". (show_cwd_command): Expand text to include remote debugging. * remote.c: Add PACKET_QSetWorkingDir. (remote_protocol_features) <QSetWorkingDir>: New entry for PACKET_QSetWorkingDir. (extended_remote_set_inferior_cwd): New function. (extended_remote_create_inferior): Call "extended_remote_set_inferior_cwd". (_initialize_remote): Call "add_packet_config_cmd" for QSetWorkingDir. gdb/gdbserver/ChangeLog: 2017-10-04 Sergio Durigan Junior <sergiodj@redhat.com> * inferiors.c (set_inferior_cwd): New function. * server.c (handle_general_set): Handle QSetWorkingDir packet. (handle_query): Inform that QSetWorkingDir is supported. * win32-low.c (create_process): Pass the inferior's cwd to CreateProcess. gdb/testsuite/ChangeLog: 2017-10-04 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.base/set-cwd.exp: Make it available on native-extended-gdbserver. gdb/doc/ChangeLog: 2017-10-04 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.texinfo (Starting your Program) <The working directory.>: Mention remote debugging. (Working Directory) <Your Program's Working Directory>: Likewise. (Connecting) <Remote Packet>: Add "set-working-dir" and "QSetWorkingDir" to the table. (Remote Protocol) <QSetWorkingDir>: New item, explaining the packet.
Diffstat (limited to 'gdb/remote.c')
-rw-r--r--gdb/remote.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/gdb/remote.c b/gdb/remote.c
index 54d810f..8c47d06 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -1430,6 +1430,7 @@ enum {
PACKET_QPassSignals,
PACKET_QCatchSyscalls,
PACKET_QProgramSignals,
+ PACKET_QSetWorkingDir,
PACKET_QStartupWithShell,
PACKET_QEnvironmentHexEncoded,
PACKET_QEnvironmentReset,
@@ -4662,6 +4663,8 @@ static const struct protocol_feature remote_protocol_features[] = {
PACKET_QCatchSyscalls },
{ "QProgramSignals", PACKET_DISABLE, remote_supported_packet,
PACKET_QProgramSignals },
+ { "QSetWorkingDir", PACKET_DISABLE, remote_supported_packet,
+ PACKET_QSetWorkingDir },
{ "QStartupWithShell", PACKET_DISABLE, remote_supported_packet,
PACKET_QStartupWithShell },
{ "QEnvironmentHexEncoded", PACKET_DISABLE, remote_supported_packet,
@@ -9641,6 +9644,45 @@ extended_remote_environment_support (struct remote_state *rs)
send_environment_packet (rs, "unset", "QEnvironmentUnset", el.c_str ());
}
+/* Helper function to set the current working directory for the
+ inferior in the remote target. */
+
+static void
+extended_remote_set_inferior_cwd (struct remote_state *rs)
+{
+ if (packet_support (PACKET_QSetWorkingDir) != PACKET_DISABLE)
+ {
+ const char *inferior_cwd = get_inferior_cwd ();
+
+ if (inferior_cwd != NULL)
+ {
+ std::string hexpath = bin2hex ((const gdb_byte *) inferior_cwd,
+ strlen (inferior_cwd));
+
+ xsnprintf (rs->buf, get_remote_packet_size (),
+ "QSetWorkingDir:%s", hexpath.c_str ());
+ }
+ else
+ {
+ /* An empty inferior_cwd means that the user wants us to
+ reset the remote server's inferior's cwd. */
+ xsnprintf (rs->buf, get_remote_packet_size (),
+ "QSetWorkingDir:");
+ }
+
+ putpkt (rs->buf);
+ getpkt (&rs->buf, &rs->buf_size, 0);
+ if (packet_ok (rs->buf,
+ &remote_protocol_packets[PACKET_QSetWorkingDir])
+ != PACKET_OK)
+ error (_("\
+Remote replied unexpectedly while setting the inferior's working\n\
+directory: %s"),
+ rs->buf);
+
+ }
+}
+
/* 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
@@ -9683,6 +9725,8 @@ Remote replied unexpectedly while setting startup-with-shell: %s"),
extended_remote_environment_support (rs);
+ extended_remote_set_inferior_cwd (rs);
+
/* Now restart the remote server. */
run_worked = extended_remote_run (args) != -1;
if (!run_worked)
@@ -14190,6 +14234,9 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL,
add_packet_config_cmd (&remote_protocol_packets[PACKET_QProgramSignals],
"QProgramSignals", "program-signals", 0);
+ add_packet_config_cmd (&remote_protocol_packets[PACKET_QSetWorkingDir],
+ "QSetWorkingDir", "set-working-dir", 0);
+
add_packet_config_cmd (&remote_protocol_packets[PACKET_QStartupWithShell],
"QStartupWithShell", "startup-with-shell", 0);