diff options
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/infcmd.c | 14 | ||||
-rw-r--r-- | gdb/inferior.h | 18 | ||||
-rw-r--r-- | gdb/nat/fork-inferior.c | 15 | ||||
-rw-r--r-- | gdb/remote.c | 9 |
4 files changed, 25 insertions, 31 deletions
diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 2d0d6cc..c027176 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -156,7 +156,7 @@ show_args_command (struct ui_file *file, int from_tty, /* See gdbsupport/common-inferior.h. */ -const char * +const std::string & get_inferior_cwd () { return current_inferior ()->cwd (); @@ -167,10 +167,7 @@ get_inferior_cwd () static void set_cwd_command (const char *args, int from_tty, struct cmd_list_element *c) { - if (*inferior_cwd_scratch == '\0') - current_inferior ()->set_cwd (nullptr); - else - current_inferior ()->set_cwd (inferior_cwd_scratch); + current_inferior ()->set_cwd (inferior_cwd_scratch); } /* Handle the 'show cwd' command. */ @@ -179,9 +176,9 @@ static void show_cwd_command (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) { - const char *cwd = current_inferior ()->cwd (); + const std::string &cwd = current_inferior ()->cwd (); - if (cwd == NULL) + if (cwd.empty ()) fprintf_filtered (gdb_stdout, _("\ You have not set the inferior's current working directory.\n\ @@ -190,7 +187,8 @@ server's cwd if remote debugging.\n")); else fprintf_filtered (gdb_stdout, _("Current working directory that will be used " - "when starting the inferior is \"%s\".\n"), cwd); + "when starting the inferior is \"%s\".\n"), + cwd.c_str ()); } diff --git a/gdb/inferior.h b/gdb/inferior.h index 72f2c29..5cd36f4 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -460,21 +460,19 @@ public: /* Set the inferior current working directory. - If CWD is NULL, unset the directory. */ - void set_cwd (const char *cwd) + If CWD is empty, unset the directory. */ + void set_cwd (std::string cwd) { - if (cwd == NULL) - m_cwd.reset (); - else - m_cwd.reset (xstrdup (cwd)); + m_cwd = std::move (cwd); } /* Get the inferior current working directory. - Return nullptr if the current working directory is not specified. */ - const char *cwd () const + Return an empty string if the current working directory is not + specified. */ + const std::string &cwd () const { - return m_cwd.get (); + return m_cwd; } /* Convenient handle (GDB inferior id). Unique across all @@ -599,7 +597,7 @@ private: /* The current working directory that will be used when starting this inferior. */ - gdb::unique_xmalloc_ptr<char> m_cwd; + std::string m_cwd; }; /* Keep a registry of per-inferior data-pointers required by other GDB diff --git a/gdb/nat/fork-inferior.c b/gdb/nat/fork-inferior.c index d280e11..c88cf4c 100644 --- a/gdb/nat/fork-inferior.c +++ b/gdb/nat/fork-inferior.c @@ -281,8 +281,6 @@ fork_inferior (const char *exec_file_arg, const std::string &allargs, char **save_our_env; int i; int save_errno; - const char *inferior_cwd; - std::string expanded_inferior_cwd; /* If no exec file handed to us, get it from the exec-file command -- with a good, common error message if none is specified. */ @@ -326,14 +324,13 @@ fork_inferior (const char *exec_file_arg, const std::string &allargs, /* Check if the user wants to set a different working directory for the inferior. */ - inferior_cwd = get_inferior_cwd (); + std::string inferior_cwd = get_inferior_cwd (); - if (inferior_cwd != NULL) + if (!inferior_cwd.empty ()) { /* Expand before forking because between fork and exec, the child process may only execute async-signal-safe operations. */ - expanded_inferior_cwd = gdb_tilde_expand (inferior_cwd); - inferior_cwd = expanded_inferior_cwd.c_str (); + inferior_cwd = gdb_tilde_expand (inferior_cwd.c_str ()); } /* If there's any initialization of the target layers that must @@ -373,10 +370,10 @@ fork_inferior (const char *exec_file_arg, const std::string &allargs, /* Change to the requested working directory if the user requested it. */ - if (inferior_cwd != NULL) + if (!inferior_cwd.empty ()) { - if (chdir (inferior_cwd) < 0) - trace_start_error_with_name (inferior_cwd); + if (chdir (inferior_cwd.c_str ()) < 0) + trace_start_error_with_name (inferior_cwd.c_str ()); } if (debug_fork) diff --git a/gdb/remote.c b/gdb/remote.c index dc3948b..552481f 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -10391,13 +10391,14 @@ remote_target::extended_remote_set_inferior_cwd () { if (packet_support (PACKET_QSetWorkingDir) != PACKET_DISABLE) { - const char *inferior_cwd = current_inferior ()->cwd (); + const std::string &inferior_cwd = current_inferior ()->cwd (); remote_state *rs = get_remote_state (); - if (inferior_cwd != NULL) + if (!inferior_cwd.empty ()) { - std::string hexpath = bin2hex ((const gdb_byte *) inferior_cwd, - strlen (inferior_cwd)); + std::string hexpath + = bin2hex ((const gdb_byte *) inferior_cwd.data (), + inferior_cwd.size ()); xsnprintf (rs->buf.data (), get_remote_packet_size (), "QSetWorkingDir:%s", hexpath.c_str ()); |