mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-27 03:54:41 +08:00
gdb: make inferior::m_cwd an std::string
Same idea as the previous patch, but for m_cwd. To keep things consistent across the board, change get_inferior_cwd as well, which is shared with GDBserver. So update the related GDBserver code too. Change-Id: Ia2c047fda738d45f3d18bc999eb67ceb8400ce4e
This commit is contained in:
parent
fd2dec2a45
commit
11bd012ed2
14
gdb/infcmd.c
14
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 ());
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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 ());
|
||||
|
@ -28,8 +28,10 @@ std::list<thread_info *> all_threads;
|
||||
|
||||
struct thread_info *current_thread;
|
||||
|
||||
/* The current working directory used to start the inferior. */
|
||||
static const char *current_inferior_cwd = NULL;
|
||||
/* The current working directory used to start the inferior.
|
||||
|
||||
Empty if not specified. */
|
||||
static std::string current_inferior_cwd;
|
||||
|
||||
struct thread_info *
|
||||
add_thread (ptid_t thread_id, void *target_data)
|
||||
@ -235,7 +237,7 @@ switch_to_process (process_info *proc)
|
||||
|
||||
/* See gdbsupport/common-inferior.h. */
|
||||
|
||||
const char *
|
||||
const std::string &
|
||||
get_inferior_cwd ()
|
||||
{
|
||||
return current_inferior_cwd;
|
||||
@ -244,11 +246,7 @@ get_inferior_cwd ()
|
||||
/* See inferiors.h. */
|
||||
|
||||
void
|
||||
set_inferior_cwd (const char *cwd)
|
||||
set_inferior_cwd (std::string cwd)
|
||||
{
|
||||
xfree ((void *) current_inferior_cwd);
|
||||
if (cwd != NULL)
|
||||
current_inferior_cwd = xstrdup (cwd);
|
||||
else
|
||||
current_inferior_cwd = NULL;
|
||||
current_inferior_cwd = std::move (cwd);
|
||||
}
|
||||
|
@ -154,8 +154,8 @@ void *thread_target_data (struct thread_info *);
|
||||
struct regcache *thread_regcache_data (struct thread_info *);
|
||||
void set_thread_regcache_data (struct thread_info *, struct regcache *);
|
||||
|
||||
/* Set the inferior current working directory. If CWD is NULL, unset
|
||||
/* Set the inferior current working directory. If CWD is empty, unset
|
||||
the directory. */
|
||||
void set_inferior_cwd (const char *cwd);
|
||||
void set_inferior_cwd (std::string cwd);
|
||||
|
||||
#endif /* GDBSERVER_INFERIORS_H */
|
||||
|
@ -949,17 +949,17 @@ handle_general_set (char *own_buf)
|
||||
{
|
||||
std::string path = hex2str (p);
|
||||
|
||||
set_inferior_cwd (path.c_str ());
|
||||
|
||||
if (remote_debug)
|
||||
debug_printf (_("[Set the inferior's current directory to %s]\n"),
|
||||
path.c_str ());
|
||||
|
||||
set_inferior_cwd (std::move (path));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* An empty argument means that we should clear out any
|
||||
previously set cwd for the inferior. */
|
||||
set_inferior_cwd (NULL);
|
||||
set_inferior_cwd ("");
|
||||
|
||||
if (remote_debug)
|
||||
debug_printf (_("\
|
||||
|
@ -32,9 +32,10 @@ extern const char *get_exec_wrapper ();
|
||||
otherwise return 0 in that case. */
|
||||
extern const char *get_exec_file (int err);
|
||||
|
||||
/* Return the inferior's current working directory. If nothing has
|
||||
been set, then return NULL. */
|
||||
extern const char *get_inferior_cwd ();
|
||||
/* Return the inferior's current working directory.
|
||||
|
||||
If it is not set, the string is empty. */
|
||||
extern const std::string &get_inferior_cwd ();
|
||||
|
||||
/* Whether to start up the debuggee under a shell.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user