]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: add overloads of gdb_tilde_expand
authorAndrew Burgess <aburgess@redhat.com>
Wed, 19 Jun 2024 10:13:14 +0000 (11:13 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 27 Jun 2024 14:15:26 +0000 (15:15 +0100)
Like the previous commit, add two overloads of gdb_tilde_expand, one
takes std::string and other takes gdb::unique_xmalloc_ptr<char>.  Make
use of these overloads throughout GDB and gdbserver.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/completer.c
gdb/nat/fork-inferior.c
gdbserver/win32-low.cc
gdbsupport/gdb_tilde_expand.h

index bd5118f53c5797086974d7617bc3bb5817dd31e3..1008ec23ba523a23de8590fe45689c4a87c01328 100644 (file)
@@ -236,7 +236,7 @@ filename_completer (struct cmd_list_element *ignore,
         trailing '/' ourselves now.  */
       if (!tracker.from_readline ())
        {
-         std::string expanded = gdb_tilde_expand (p_rl.get ());
+         std::string expanded = gdb_tilde_expand (p_rl);
          struct stat finfo;
          const bool isdir = (stat (expanded.c_str (), &finfo) == 0
                              && S_ISDIR (finfo.st_mode));
index 2fd9cba52ee076da2a2779c03cae457780ab43f7..41765b102bc0a74ea5cd5586b2c25bdeb6e5d1a3 100644 (file)
@@ -321,7 +321,7 @@ fork_inferior (const char *exec_file, const std::string &allargs, char **env,
     {
       /* Expand before forking because between fork and exec, the child
         process may only execute async-signal-safe operations.  */
-      inferior_cwd = gdb_tilde_expand (inferior_cwd.c_str ());
+      inferior_cwd = gdb_tilde_expand (inferior_cwd);
     }
 
   /* If there's any initialization of the target layers that must
index f672e542d1bc1b0febe7f8b9e7e5cf1812a9c2ca..41eed201c101e11347042c11b5cb7580b6ba29c1 100644 (file)
@@ -501,7 +501,7 @@ create_process (const char *program, char *args,
                        /* current directory */
                        (inferior_cwd.empty ()
                         ? NULL
-                        : gdb_tilde_expand (inferior_cwd.c_str ()).c_str()),
+                        : gdb_tilde_expand (inferior_cwd).c_str()),
                        get_client_state ().disable_randomization,
                        &si,               /* start info */
                        pi);               /* proc info */
index fbd410dd1337d49a2c57309159231dad1bfea727..f16f3a405ee9bf4523dd0bd66543fb0eab23ee40 100644 (file)
 #ifndef COMMON_GDB_TILDE_EXPAND_H
 #define COMMON_GDB_TILDE_EXPAND_H
 
-/* Perform tilde expansion on DIR, and return the full path.  */
-extern std::string gdb_tilde_expand (const char *dir);
+/* Perform tilde expansion on PATH, and return the full path.  */
+extern std::string gdb_tilde_expand (const char *path);
+
+/* Overload of gdb_tilde_expand that takes std::string.  */
+static inline std::string
+gdb_tilde_expand (const std::string &path)
+{
+  return gdb_tilde_expand (path.c_str ());
+}
+
+/* Overload of gdb_tilde_expand that takes gdb::unique_xmalloc_ptr<char>.  */
+static inline std::string
+gdb_tilde_expand (const gdb::unique_xmalloc_ptr<char> &path)
+{
+  return gdb_tilde_expand (path.get ());
+}
 
 #endif /* COMMON_GDB_TILDE_EXPAND_H */