diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2022-04-13 17:31:02 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2022-04-18 15:48:03 -0400 |
commit | 7ab2607f97e5deaeae91018edf3ef5b4255a842c (patch) | |
tree | f1fea75412b59b147691af35019eb6d940f062b0 /gdb | |
parent | e0c34637019b0a070780b57b50d9026c0aca16f4 (diff) | |
download | binutils-gdb-7ab2607f97e5deaeae91018edf3ef5b4255a842c.tar.gz |
gdbsupport: make gdb_abspath return an std::string
I'm trying to switch these functions to use std::string instead of char
arrays, as much as possible. Some callers benefit from it (can avoid
doing a copy of the result), while others suffer (have to make one more
copy).
Change-Id: Iced49b8ee2f189744c5072a3b217aab5af17a993
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/compile/compile.c | 4 | ||||
-rw-r--r-- | gdb/corelow.c | 2 | ||||
-rw-r--r-- | gdb/dwarf2/index-cache.c | 4 | ||||
-rw-r--r-- | gdb/main.c | 7 | ||||
-rw-r--r-- | gdb/objfiles.c | 4 | ||||
-rw-r--r-- | gdb/source.c | 19 | ||||
-rw-r--r-- | gdb/top.c | 10 | ||||
-rw-r--r-- | gdb/tracefile-tfile.c | 2 |
8 files changed, 21 insertions, 31 deletions
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 2a1f0f1bd6b..5cbb341b383 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -297,8 +297,8 @@ compile_file_command (const char *args, int from_tty) error (_("You must provide a filename for this command.")); args = skip_spaces (args); - gdb::unique_xmalloc_ptr<char> abspath = gdb_abspath (args); - std::string buffer = string_printf ("#include \"%s\"\n", abspath.get ()); + std::string abspath = gdb_abspath (args); + std::string buffer = string_printf ("#include \"%s\"\n", abspath.c_str ()); eval_compile_command (NULL, buffer.c_str (), scope, NULL); } diff --git a/gdb/corelow.c b/gdb/corelow.c index a23dc81c5af..8c33fb7ebb2 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -469,7 +469,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 = gdb_abspath (filename.get ()); + filename = make_unique_xstrdup (gdb_abspath (filename.get ()).c_str ()); flags = O_BINARY | O_LARGEFILE; if (write_files) diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c index 18e60cbd78c..fb827e04e59 100644 --- a/gdb/dwarf2/index-cache.c +++ b/gdb/dwarf2/index-cache.c @@ -298,9 +298,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. */ - gdb::unique_xmalloc_ptr<char> abs - = gdb_abspath (index_cache_directory.c_str ()); - index_cache_directory = abs.get (); + index_cache_directory = gdb_abspath (index_cache_directory.c_str ()); global_index_cache.set_directory (index_cache_directory); } diff --git a/gdb/main.c b/gdb/main.c index 8c0807ff83b..ec2b7b01752 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -133,12 +133,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::unique_xmalloc_ptr<char> abs_datadir - = gdb_abspath (gdb_datadir.c_str ()); - - gdb_datadir = abs_datadir.get (); - } + gdb_datadir = gdb_abspath (gdb_datadir.c_str ()); } /* Relocate a file or directory. PROGNAME is the name by which gdb diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 0c71e0bd6a9..849c6d73cab 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -331,7 +331,7 @@ objfile::objfile (bfd *abfd, const char *name, objfile_flags flags_) objfile_alloc_data (this); - gdb::unique_xmalloc_ptr<char> name_holder; + std::string name_holder; if (name == NULL) { gdb_assert (abfd == NULL); @@ -344,7 +344,7 @@ objfile::objfile (bfd *abfd, const char *name, objfile_flags flags_) else { name_holder = gdb_abspath (name); - expanded_name = name_holder.get (); + expanded_name = name_holder.c_str (); } original_name = obstack_strdup (&objfile_obstack, expanded_name); diff --git a/gdb/source.c b/gdb/source.c index e9016573333..9d9ff4bbc3e 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -537,15 +537,15 @@ add_path (const char *dirname, char **which_path, int parse_separators) for (const gdb::unique_xmalloc_ptr<char> &name_up : dir_vec) { - char *name = name_up.get (); + const char *name = name_up.get (); char *p; struct stat st; - gdb::unique_xmalloc_ptr<char> new_name_holder; + std::string new_name_holder; /* Spaces and tabs will have been removed by buildargv(). NAME is the start of the directory. P is the '\0' following the end. */ - p = name + strlen (name); + p = name_up.get () + strlen (name); while (!(IS_DIR_SEPARATOR (*name) && p <= name + 1) /* "/" */ #ifdef HAVE_DOS_BASED_FILE_SYSTEM @@ -589,16 +589,18 @@ add_path (const char *dirname, char **which_path, int parse_separators) if (name[0] == '\0') goto skip_dup; if (name[0] == '~') - new_name_holder.reset (tilde_expand (name)); + new_name_holder + = gdb::unique_xmalloc_ptr<char[]> (tilde_expand (name)).get (); #ifdef HAVE_DOS_BASED_FILE_SYSTEM else if (IS_ABSOLUTE_PATH (name) && p == name + 2) /* "d:" => "d:." */ - new_name_holder.reset (concat (name, ".", (char *) NULL)); + new_name_holder = std::string (name) + "."; #endif else if (!IS_ABSOLUTE_PATH (name) && name[0] != '$') new_name_holder = gdb_abspath (name); else - new_name_holder.reset (savestring (name, p - name)); - name = new_name_holder.get (); + new_name_holder = std::string (name, p - name); + + name = new_name_holder.c_str (); /* Unless it's a variable, check existence. */ if (name[0] != '$') @@ -950,7 +952,8 @@ done: else if ((opts & OPF_RETURN_REALPATH) != 0) *filename_opened = gdb_realpath (filename); else - *filename_opened = gdb_abspath (filename); + *filename_opened + = make_unique_xstrdup (gdb_abspath (filename).c_str ()); } errno = last_errno; diff --git a/gdb/top.c b/gdb/top.c index e776ac2d70e..1cfffbeee7e 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -2167,12 +2167,7 @@ set_history_filename (const char *args, that was read. */ if (!history_filename.empty () && !IS_ABSOLUTE_PATH (history_filename.c_str ())) - { - gdb::unique_xmalloc_ptr<char> temp - (gdb_abspath (history_filename.c_str ())); - - history_filename = temp.get (); - } + history_filename = gdb_abspath (history_filename.c_str ()); } /* Whether we're in quiet startup mode. */ @@ -2444,7 +2439,6 @@ _initialize_top () const char *fname = ".gdb_history"; #endif - gdb::unique_xmalloc_ptr<char> temp (gdb_abspath (fname)); - history_filename = temp.get (); + history_filename = gdb_abspath (fname); } } diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c index 107236330d1..f84ad2f4a3f 100644 --- a/gdb/tracefile-tfile.c +++ b/gdb/tracefile-tfile.c @@ -471,7 +471,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 = gdb_abspath (filename.get ()); + filename = make_unique_xstrdup (gdb_abspath (filename.get ()).c_str ()); flags = O_BINARY | O_LARGEFILE; flags |= O_RDONLY; |