aboutsummaryrefslogtreecommitdiff
path: root/gdb/source.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2022-04-13 17:31:02 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2022-04-18 15:48:03 -0400
commit7ab2607f97e5deaeae91018edf3ef5b4255a842c (patch)
treef1fea75412b59b147691af35019eb6d940f062b0 /gdb/source.c
parente0c34637019b0a070780b57b50d9026c0aca16f4 (diff)
downloadgdb-7ab2607f97e5deaeae91018edf3ef5b4255a842c.zip
gdb-7ab2607f97e5deaeae91018edf3ef5b4255a842c.tar.gz
gdb-7ab2607f97e5deaeae91018edf3ef5b4255a842c.tar.bz2
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/source.c')
-rw-r--r--gdb/source.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/gdb/source.c b/gdb/source.c
index e901657..9d9ff4b 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;