+2017-08-22 Tom Tromey <tom@tromey.com>
+
+ * compile/compile.c (compile_file_command): Use
+ gdb::unique_xmalloc_ptr, std::string.
+ * utils.c (gdb_abspath): Change return type.
+ * source.c (openp): Update.
+ * objfiles.c (allocate_objfile): Update.
+ * main.c (set_gdb_data_directory): Update.
+ * utils.h (gdb_abspath): Return a gdb::unique_xmalloc_ptr.
+
2017-08-22 Zhouyi Zhou <zhouzhouyi@gmail.com>
* cli-cmds.c (list_commands): List actual code around more than
compile_file_command (char *arg, int from_tty)
{
enum compile_i_scope_types scope = COMPILE_I_SIMPLE_SCOPE;
- char *buffer;
- struct cleanup *cleanup;
scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0);
error (_("Unknown argument specified."));
arg = skip_spaces (arg);
- arg = gdb_abspath (arg);
- cleanup = make_cleanup (xfree, arg);
- buffer = xstrprintf ("#include \"%s\"\n", arg);
- make_cleanup (xfree, buffer);
- eval_compile_command (NULL, buffer, scope, NULL);
- do_cleanups (cleanup);
+ gdb::unique_xmalloc_ptr<char> abspath = gdb_abspath (arg);
+ std::string buffer = string_printf ("#include \"%s\"\n", abspath.get ());
+ eval_compile_command (NULL, buffer.c_str (), scope, NULL);
}
/* Handle the input from the 'compile code' command. The
isn't canonical, but that's ok. */
if (!IS_ABSOLUTE_PATH (gdb_datadir))
{
- char *abs_datadir = gdb_abspath (gdb_datadir);
+ gdb::unique_xmalloc_ptr<char> abs_datadir = gdb_abspath (gdb_datadir);
xfree (gdb_datadir);
- gdb_datadir = abs_datadir;
+ gdb_datadir = abs_datadir.release ();
}
}
objfile_alloc_data (objfile);
+ gdb::unique_xmalloc_ptr<char> name_holder;
if (name == NULL)
{
gdb_assert (abfd == NULL);
gdb_assert ((flags & OBJF_NOT_FILENAME) != 0);
- expanded_name = xstrdup ("<<anonymous objfile>>");
+ expanded_name = "<<anonymous objfile>>";
}
else if ((flags & OBJF_NOT_FILENAME) != 0
|| is_target_filename (name))
- expanded_name = xstrdup (name);
+ expanded_name = name;
else
- expanded_name = gdb_abspath (name);
+ {
+ name_holder = gdb_abspath (name);
+ expanded_name = name_holder.get ();
+ }
objfile->original_name
= (char *) obstack_copy0 (&objfile->objfile_obstack,
expanded_name,
strlen (expanded_name));
- xfree (expanded_name);
/* Update the per-objfile information that comes from the bfd, ensuring
that any data that is reference is saved in the per-objfile data
else if ((opts & OPF_RETURN_REALPATH) != 0)
*filename_opened = gdb_realpath (filename);
else
- *filename_opened = gdb_abspath (filename);
+ *filename_opened = gdb_abspath (filename).release ();
}
errno = last_errno;
/* Return PATH in absolute form, performing tilde-expansion if necessary.
PATH cannot be NULL or the empty string.
- This does not resolve symlinks however, use gdb_realpath for that.
- Space for the result is allocated with malloc.
- If the path is already absolute, it is strdup'd.
- If there is a problem computing the absolute path, the path is returned
- unchanged (still strdup'd). */
+ This does not resolve symlinks however, use gdb_realpath for that. */
-char *
+gdb::unique_xmalloc_ptr<char>
gdb_abspath (const char *path)
{
gdb_assert (path != NULL && path[0] != '\0');
if (path[0] == '~')
- return tilde_expand (path);
+ return gdb::unique_xmalloc_ptr<char> (tilde_expand (path));
if (IS_ABSOLUTE_PATH (path))
- return xstrdup (path);
+ return gdb::unique_xmalloc_ptr<char> (xstrdup (path));
/* Beware the // my son, the Emacs barfs, the botch that catch... */
- return concat (current_directory,
- IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1])
- ? "" : SLASH_STRING,
- path, (char *) NULL);
+ return gdb::unique_xmalloc_ptr<char>
+ (concat (current_directory,
+ IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1])
+ ? "" : SLASH_STRING,
+ path, (char *) NULL));
}
ULONGEST
extern char *gdb_realpath_keepfile (const char *);
-extern char *gdb_abspath (const char *);
+extern gdb::unique_xmalloc_ptr<char> gdb_abspath (const char *);
extern int gdb_filename_fnmatch (const char *pattern, const char *string,
int flags);