]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: add overloads of gdb_abspath
authorAndrew Burgess <aburgess@redhat.com>
Wed, 19 Jun 2024 10:12:28 +0000 (11:12 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 27 Jun 2024 14:15:25 +0000 (15:15 +0100)
Add two overloads of gdb_abspath, one which takes std::string and one
which takes gdb::unique_xmalloc_ptr<char>, then 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/bsd-kvm.c
gdb/corelow.c
gdb/dwarf2/index-cache.c
gdb/main.c
gdb/top.c
gdb/tracefile-tfile.c
gdbserver/server.cc
gdbsupport/pathstuff.h

index 7ef8c349a6e7e1ea6055a0fb91490529fa6b950f..19353eb97dcc48f9c26fa65a22539d6b447b0ae8 100644 (file)
@@ -117,7 +117,7 @@ bsd_kvm_target_open (const char *arg, int from_tty)
     {
       filename = gdb_tilde_expand (arg);
       if (!IS_ABSOLUTE_PATH (filename))
-       filename = gdb_abspath (filename.c_str ());
+       filename = gdb_abspath (filename);
     }
 
   const char *execfile = current_program_space->exec_filename ();
index 49da9be07ef99136e503aea01aaaa449666d366f..2b7a3550fc1c83734329708d5690dea037ff444a 100644 (file)
@@ -626,7 +626,7 @@ core_target_open (const char *arg, int from_tty)
   gdb::unique_xmalloc_ptr<char> filename (tilde_expand (arg));
   if (strlen (filename.get ()) != 0
       && !IS_ABSOLUTE_PATH (filename.get ()))
-    filename = make_unique_xstrdup (gdb_abspath (filename.get ()).c_str ());
+    filename = make_unique_xstrdup (gdb_abspath (filename).c_str ());
 
   flags = O_BINARY | O_LARGEFILE;
   if (write_files)
index 1720e925ee607fa3660fedfebdda17d6b10c69ec..c11b0164aa4e46f0cc902a1910869aa602b7765e 100644 (file)
@@ -324,7 +324,7 @@ set_index_cache_directory_command (const char *arg, int from_tty,
                                   cmd_list_element *element)
 {
   /* Make sure the index cache directory is absolute and tilde-expanded.  */
-  index_cache_directory = gdb_abspath (index_cache_directory.c_str ());
+  index_cache_directory = gdb_abspath (index_cache_directory);
   global_index_cache.set_directory (index_cache_directory);
 }
 
index 4dd68f3d97653fd263c1bbca284b0d9cf46990e5..e4a40c51023cd6bae8c1e45594ee2b4a7d6c2279 100644 (file)
@@ -121,7 +121,7 @@ set_gdb_data_directory (const char *new_datadir)
      "../foo" and "../foo" doesn't exist then we'll record $(pwd)/../foo which
      isn't canonical, but that's ok.  */
   if (!IS_ABSOLUTE_PATH (gdb_datadir.c_str ()))
-    gdb_datadir = gdb_abspath (gdb_datadir.c_str ());
+    gdb_datadir = gdb_abspath (gdb_datadir);
 }
 
 /* Relocate a file or directory.  PROGNAME is the name by which gdb
index 6239c190627c5bcc279ceda86edcf44a8a79d794..d6bf1d448d5b39084caa7535c78e0f1729e689d1 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -2097,7 +2097,7 @@ set_history_filename (const char *args,
      that was read.  */
   if (!history_filename.empty ()
       && !IS_ABSOLUTE_PATH (history_filename.c_str ()))
-    history_filename = gdb_abspath (history_filename.c_str ());
+    history_filename = gdb_abspath (history_filename);
 }
 
 /* Whether we're in quiet startup mode.  */
index eb879c1797008ac2fa7bb04bfe1f607204db1b4f..4a4c4a2d32a49cf10a13cda65906c51f16497ed7 100644 (file)
@@ -467,7 +467,7 @@ tfile_target_open (const char *arg, int from_tty)
 
   gdb::unique_xmalloc_ptr<char> filename (tilde_expand (arg));
   if (!IS_ABSOLUTE_PATH (filename.get ()))
-    filename = make_unique_xstrdup (gdb_abspath (filename.get ()).c_str ());
+    filename = make_unique_xstrdup (gdb_abspath (filename).c_str ());
 
   flags = O_BINARY | O_LARGEFILE;
   flags |= O_RDONLY;
index ab9a33f40fd29f862c8c9b6f8ec89720154c3cb1..30d05177452390e7807379da67ce7c3b870df441 100644 (file)
@@ -109,7 +109,7 @@ static struct {
           its name with CURRENT_DIRECTORY.  Otherwise, we leave the
           name as-is because we'll try searching for it in $PATH.  */
        if (is_regular_file (m_path.c_str (), &reg_file_errno))
-         m_path = gdb_abspath (m_path.c_str ());
+         m_path = gdb_abspath (m_path);
       }
   }
 
index 170a2c5e724bdec18638112a7e3593bada614b2e..a61ce23efde5c09884396d67337e8126db6be2c8 100644 (file)
@@ -56,6 +56,22 @@ extern std::string gdb_realpath_keepfile (const char *filename);
 
 extern std::string gdb_abspath (const char *path);
 
+/* Overload of gdb_abspath which takes std::string.  */
+
+static inline std::string
+gdb_abspath (const std::string &path)
+{
+  return gdb_abspath (path.c_str ());
+}
+
+/* Overload of gdb_abspath which takes gdb::unique_xmalloc_ptr<char>.  */
+
+static inline std::string
+gdb_abspath (const gdb::unique_xmalloc_ptr<char> &path)
+{
+  return gdb_abspath (path.get ());
+}
+
 /* If the path in CHILD is a child of the path in PARENT, return a
    pointer to the first component in the CHILD's pathname below the
    PARENT.  Otherwise, return NULL.  */