aboutsummaryrefslogtreecommitdiff
path: root/gdb/symfile.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-07-31 15:49:21 -0600
committerTom Tromey <tom@tromey.com>2017-08-05 15:52:49 -0600
commitee0c32930c355b73172b2bef987e2a48ea909b12 (patch)
tree0264ee39289e77f768f898ca1dd0109bf92d0b58 /gdb/symfile.c
parentfdffd6f4118652bdfdff383943f13664af4b9a45 (diff)
downloadgdb-ee0c32930c355b73172b2bef987e2a48ea909b12.zip
gdb-ee0c32930c355b73172b2bef987e2a48ea909b12.tar.gz
gdb-ee0c32930c355b73172b2bef987e2a48ea909b12.tar.bz2
Use gdb::unique_xmalloc_ptr when calling tilde_expand
This patch changes most sites calling tilde_expand to use gdb::unique_xmalloc_ptr, rather than a cleanup. It also changes scan_expression_with_cleanup to return a unique pointer, because the patch was already touching code in that area. Regression tested on the buildbot. ChangeLog 2017-08-05 Tom Tromey <tom@tromey.com> * compile/compile-object-load.c (compile_object_load): Use gdb::unique_xmalloc_ptr. * cli/cli-dump.c (scan_filename): Rename from scan_filename_with_cleanup. Change return type. (scan_expression): Rename from scan_expression_with_cleanup. Change return type. (dump_memory_to_file, dump_value_to_file, restore_command): Use gdb::unique_xmalloc_ptr. Update. * cli/cli-cmds.c (find_and_open_script): Use gdb::unique_xmalloc_ptr. * tracefile-tfile.c (tfile_open): Use gdb::unique_xmalloc_ptr. * symmisc.c (maintenance_print_symbols) (maintenance_print_msymbols): Use gdb::unique_xmalloc_ptr. * symfile.c (symfile_bfd_open, generic_load) (add_symbol_file_command, remove_symbol_file_command): Use gdb::unique_xmalloc_ptr. * source.c (openp): Use gdb::unique_xmalloc_ptr. * psymtab.c (maintenance_print_psymbols): Use gdb::unique_xmalloc_ptr. * corelow.c (core_open): Use gdb::unique_xmalloc_ptr. * breakpoint.c (save_breakpoints): Use gdb::unique_xmalloc_ptr. * solib.c (solib_map_sections): Use gdb::unique_xmalloc_ptr. (reload_shared_libraries_1): Likewise.
Diffstat (limited to 'gdb/symfile.c')
-rw-r--r--gdb/symfile.c53
1 files changed, 19 insertions, 34 deletions
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 67a3976..3e2df9b 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1714,32 +1714,28 @@ symfile_bfd_open (const char *name)
if (!is_target_filename (name))
{
- char *expanded_name, *absolute_name;
+ char *absolute_name;
- expanded_name = tilde_expand (name); /* Returns 1st new malloc'd copy. */
+ gdb::unique_xmalloc_ptr<char> expanded_name (tilde_expand (name));
/* Look down path for it, allocate 2nd new malloc'd copy. */
desc = openp (getenv ("PATH"),
OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH,
- expanded_name, O_RDONLY | O_BINARY, &absolute_name);
+ expanded_name.get (), O_RDONLY | O_BINARY, &absolute_name);
#if defined(__GO32__) || defined(_WIN32) || defined (__CYGWIN__)
if (desc < 0)
{
- char *exename = (char *) alloca (strlen (expanded_name) + 5);
+ char *exename = (char *) alloca (strlen (expanded_name.get ()) + 5);
- strcat (strcpy (exename, expanded_name), ".exe");
+ strcat (strcpy (exename, expanded_name.get ()), ".exe");
desc = openp (getenv ("PATH"),
OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH,
exename, O_RDONLY | O_BINARY, &absolute_name);
}
#endif
if (desc < 0)
- {
- make_cleanup (xfree, expanded_name);
- perror_with_name (expanded_name);
- }
+ perror_with_name (expanded_name.get ());
- xfree (expanded_name);
make_cleanup (xfree, absolute_name);
name = absolute_name;
}
@@ -2055,7 +2051,6 @@ static void print_transfer_performance (struct ui_file *stream,
void
generic_load (const char *args, int from_tty)
{
- char *filename;
struct cleanup *old_cleanups;
struct load_section_data cbdata;
struct load_progress_data total_progress;
@@ -2074,8 +2069,7 @@ generic_load (const char *args, int from_tty)
gdb_argv argv (args);
- filename = tilde_expand (argv[0]);
- make_cleanup (xfree, filename);
+ gdb::unique_xmalloc_ptr<char> filename (tilde_expand (argv[0]));
if (argv[1] != NULL)
{
@@ -2093,16 +2087,13 @@ generic_load (const char *args, int from_tty)
}
/* Open the file for loading. */
- gdb_bfd_ref_ptr loadfile_bfd (gdb_bfd_open (filename, gnutarget, -1));
+ gdb_bfd_ref_ptr loadfile_bfd (gdb_bfd_open (filename.get (), gnutarget, -1));
if (loadfile_bfd == NULL)
- {
- perror_with_name (filename);
- return;
- }
+ perror_with_name (filename.get ());
if (!bfd_check_format (loadfile_bfd.get (), bfd_object))
{
- error (_("\"%s\" is not an object file: %s"), filename,
+ error (_("\"%s\" is not an object file: %s"), filename.get (),
bfd_errmsg (bfd_get_error ()));
}
@@ -2212,7 +2203,7 @@ static void
add_symbol_file_command (char *args, int from_tty)
{
struct gdbarch *gdbarch = get_current_arch ();
- char *filename = NULL;
+ gdb::unique_xmalloc_ptr<char> filename;
char *arg;
int section_index = 0;
int argcnt = 0;
@@ -2254,8 +2245,7 @@ add_symbol_file_command (char *args, int from_tty)
if (argcnt == 0)
{
/* The first argument is the file name. */
- filename = tilde_expand (arg);
- make_cleanup (xfree, filename);
+ filename.reset (tilde_expand (arg));
}
else if (argcnt == 1)
{
@@ -2312,7 +2302,8 @@ add_symbol_file_command (char *args, int from_tty)
loaded. Abort now if this address hasn't been provided by the
user. */
if (section_index < 1)
- error (_("The address where %s has been loaded is missing"), filename);
+ error (_("The address where %s has been loaded is missing"),
+ filename.get ());
/* Print the prompt for the query below. And save the arguments into
a sect_addr_info structure to be passed around to other
@@ -2320,7 +2311,8 @@ add_symbol_file_command (char *args, int from_tty)
statements because hex_string returns a local static
string. */
- printf_unfiltered (_("add symbol table from file \"%s\" at\n"), filename);
+ printf_unfiltered (_("add symbol table from file \"%s\" at\n"),
+ filename.get ());
section_addrs = alloc_section_addr_info (section_index);
make_cleanup (xfree, section_addrs);
for (i = 0; i < section_index; i++)
@@ -2350,7 +2342,7 @@ add_symbol_file_command (char *args, int from_tty)
if (from_tty && (!query ("%s", "")))
error (_("Not confirmed."));
- objf = symbol_file_add (filename, add_flags, section_addrs, flags);
+ objf = symbol_file_add (filename.get (), add_flags, section_addrs, flags);
add_target_sections_of_objfile (objf);
@@ -2367,7 +2359,6 @@ static void
remove_symbol_file_command (char *args, int from_tty)
{
struct objfile *objf = NULL;
- struct cleanup *my_cleanups;
struct program_space *pspace = current_program_space;
dont_repeat ();
@@ -2375,8 +2366,6 @@ remove_symbol_file_command (char *args, int from_tty)
if (args == NULL)
error (_("remove-symbol-file: no symbol file provided"));
- my_cleanups = make_cleanup (null_cleanup, NULL);
-
gdb_argv argv (args);
if (strcmp (argv[0], "-a") == 0)
@@ -2403,20 +2392,18 @@ remove_symbol_file_command (char *args, int from_tty)
else if (argv[0] != NULL)
{
/* Interpret the current argument as a file name. */
- char *filename;
if (argv[1] != NULL)
error (_("Junk after %s"), argv[0]);
- filename = tilde_expand (argv[0]);
- make_cleanup (xfree, filename);
+ gdb::unique_xmalloc_ptr<char> filename (tilde_expand (argv[0]));
ALL_OBJFILES (objf)
{
if ((objf->flags & OBJF_USERLOADED) != 0
&& (objf->flags & OBJF_SHARED) != 0
&& objf->pspace == pspace
- && filename_cmp (filename, objfile_name (objf)) == 0)
+ && filename_cmp (filename.get (), objfile_name (objf)) == 0)
break;
}
}
@@ -2431,8 +2418,6 @@ remove_symbol_file_command (char *args, int from_tty)
free_objfile (objf);
clear_symtab_users (0);
-
- do_cleanups (my_cleanups);
}
/* Re-read symbols if a symbol-file has changed. */