aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2read.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-11-10 13:47:05 -0700
committerTom Tromey <tom@tromey.com>2018-02-14 08:09:53 -0700
commite0cc99a62f9ceb9a0db0b5bc28711fd8c82a6151 (patch)
tree4401d76103521d42ed82b58cf22eb6fe77abdbf2 /gdb/dwarf2read.c
parentb46a8d7c1d50c06e641af99b58301db0499111b9 (diff)
downloadbinutils-e0cc99a62f9ceb9a0db0b5bc28711fd8c82a6151.zip
binutils-e0cc99a62f9ceb9a0db0b5bc28711fd8c82a6151.tar.gz
binutils-e0cc99a62f9ceb9a0db0b5bc28711fd8c82a6151.tar.bz2
Change openp et al to use a unique_xmalloc_ptr
This changes openp, source_full_path_of, and find_and_open_source to take a unique_xmalloc_ptr, rather than a char*, as an outgoing argument type. This simplifies the API, ownership-wise, and allows for the removal of some cleanups. gdb/ChangeLog 2018-02-14 Tom Tromey <tom@tromey.com> * symfile.c (symfile_bfd_open): Update. * source.h (openp, source_full_path_of, find_and_open_source): Change argument type to unique_xmalloc_ptr. * source.c (openp): Take a unique_xmalloc_ptr. (source_full_path_of, find_and_open_source): Likewise. (open_source_file, symtab_to_fullname): Update. * solist.h (struct target_so_ops) <find_and_open_solib>: Take a unique_xmalloc_ptr. * solib.c (solib_find_1): Use unique_xmalloc_ptr. (exec_file_find): Update. * psymtab.c (psymtab_to_fullname): Update. * nto-tdep.h (nto_find_and_open_solib): Update. * nto-tdep.c (nto_find_and_open_solib): Change temp_path to a unique_xmalloc_ptr. * exec.c (exec_file_attach): Update. * dwarf2read.c (try_open_dwop_file): Use unique_xmalloc_ptr. * cli/cli-cmds.c (find_and_open_script): Use unique_xmalloc_ptr.
Diffstat (limited to 'gdb/dwarf2read.c')
-rw-r--r--gdb/dwarf2read.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 9345343..d6d3d4a 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -12881,35 +12881,40 @@ try_open_dwop_file (struct dwarf2_per_objfile *dwarf2_per_objfile,
const char *file_name, int is_dwp, int search_cwd)
{
int desc;
- char *absolute_name;
/* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
to debug_file_directory. */
- char *search_path;
+ const char *search_path;
static const char dirname_separator_string[] = { DIRNAME_SEPARATOR, '\0' };
+ gdb::unique_xmalloc_ptr<char> search_path_holder;
if (search_cwd)
{
if (*debug_file_directory != '\0')
- search_path = concat (".", dirname_separator_string,
- debug_file_directory, (char *) NULL);
+ {
+ search_path_holder.reset (concat (".", dirname_separator_string,
+ debug_file_directory,
+ (char *) NULL));
+ search_path = search_path_holder.get ();
+ }
else
- search_path = xstrdup (".");
+ search_path = ".";
}
else
- search_path = xstrdup (debug_file_directory);
+ search_path = debug_file_directory;
openp_flags flags = OPF_RETURN_REALPATH;
if (is_dwp)
flags |= OPF_SEARCH_IN_PATH;
+
+ gdb::unique_xmalloc_ptr<char> absolute_name;
desc = openp (search_path, flags, file_name,
O_RDONLY | O_BINARY, &absolute_name);
- xfree (search_path);
if (desc < 0)
return NULL;
- gdb_bfd_ref_ptr sym_bfd (gdb_bfd_open (absolute_name, gnutarget, desc));
- xfree (absolute_name);
+ gdb_bfd_ref_ptr sym_bfd (gdb_bfd_open (absolute_name.get (),
+ gnutarget, desc));
if (sym_bfd == NULL)
return NULL;
bfd_set_cacheable (sym_bfd.get (), 1);