From 11bd012ed256688f43d71dcc531c2f105a9c55dd Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 25 Jun 2021 18:07:54 -0400 Subject: 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 --- gdbserver/inferiors.cc | 16 +++++++--------- gdbserver/inferiors.h | 4 ++-- gdbserver/server.cc | 6 +++--- 3 files changed, 12 insertions(+), 14 deletions(-) (limited to 'gdbserver') diff --git a/gdbserver/inferiors.cc b/gdbserver/inferiors.cc index 0a09de7..32f8478 100644 --- a/gdbserver/inferiors.cc +++ b/gdbserver/inferiors.cc @@ -28,8 +28,10 @@ std::list 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); } diff --git a/gdbserver/inferiors.h b/gdbserver/inferiors.h index 3b8959a..1e0fe67 100644 --- a/gdbserver/inferiors.h +++ b/gdbserver/inferiors.h @@ -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 */ diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 32dcc05..193c3d9 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -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 (_("\ -- cgit v1.1