diff options
author | Tom Tromey <tom@tromey.com> | 2017-11-10 13:47:05 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-02-14 08:09:53 -0700 |
commit | e0cc99a62f9ceb9a0db0b5bc28711fd8c82a6151 (patch) | |
tree | 4401d76103521d42ed82b58cf22eb6fe77abdbf2 /gdb/solib.c | |
parent | b46a8d7c1d50c06e641af99b58301db0499111b9 (diff) | |
download | gdb-e0cc99a62f9ceb9a0db0b5bc28711fd8c82a6151.zip gdb-e0cc99a62f9ceb9a0db0b5bc28711fd8c82a6151.tar.gz gdb-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/solib.c')
-rw-r--r-- | gdb/solib.c | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/gdb/solib.c b/gdb/solib.c index 67a490e..41fba90 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -152,7 +152,7 @@ solib_find_1 (const char *in_pathname, int *fd, int is_solib) { const struct target_so_ops *ops = solib_ops (target_gdbarch ()); int found_file = -1; - char *temp_pathname = NULL; + gdb::unique_xmalloc_ptr<char> temp_pathname; const char *fskind = effective_target_file_system_kind (); const char *sysroot = gdb_sysroot; int prefix_len, orig_prefix_len; @@ -214,7 +214,7 @@ solib_find_1 (const char *in_pathname, int *fd, int is_solib) */ if (!IS_TARGET_ABSOLUTE_PATH (fskind, in_pathname) || sysroot == NULL) - temp_pathname = xstrdup (in_pathname); + temp_pathname.reset (xstrdup (in_pathname)); else { int need_dir_separator; @@ -240,23 +240,21 @@ solib_find_1 (const char *in_pathname, int *fd, int is_solib) || strcmp (TARGET_SYSROOT_PREFIX, sysroot) == 0); /* Cat the prefixed pathname together. */ - temp_pathname = concat (sysroot, - need_dir_separator ? SLASH_STRING : "", - in_pathname, (char *) NULL); + temp_pathname.reset (concat (sysroot, + need_dir_separator ? SLASH_STRING : "", + in_pathname, (char *) NULL)); } /* Handle files to be accessed via the target. */ - if (is_target_filename (temp_pathname)) + if (is_target_filename (temp_pathname.get ())) { if (fd != NULL) *fd = -1; - return gdb::unique_xmalloc_ptr<char> (temp_pathname); + return temp_pathname; } /* Now see if we can open it. */ - found_file = gdb_open_cloexec (temp_pathname, O_RDONLY | O_BINARY, 0); - if (found_file < 0) - xfree (temp_pathname); + found_file = gdb_open_cloexec (temp_pathname.get (), O_RDONLY | O_BINARY, 0); /* If the search in gdb_sysroot failed, and the path name has a drive spec (e.g, c:/foo), try stripping ':' from the drive spec, @@ -268,33 +266,30 @@ solib_find_1 (const char *in_pathname, int *fd, int is_solib) && HAS_TARGET_DRIVE_SPEC (fskind, in_pathname)) { int need_dir_separator = !IS_DIR_SEPARATOR (in_pathname[2]); - char *drive = savestring (in_pathname, 1); + char drive[2] = { in_pathname[0], '\0' }; - temp_pathname = concat (sysroot, - SLASH_STRING, - drive, - need_dir_separator ? SLASH_STRING : "", - in_pathname + 2, (char *) NULL); - xfree (drive); + temp_pathname.reset (concat (sysroot, + SLASH_STRING, + drive, + need_dir_separator ? SLASH_STRING : "", + in_pathname + 2, (char *) NULL)); - found_file = gdb_open_cloexec (temp_pathname, O_RDONLY | O_BINARY, 0); + found_file = gdb_open_cloexec (temp_pathname.get (), + O_RDONLY | O_BINARY, 0); if (found_file < 0) { - xfree (temp_pathname); - /* If the search in gdb_sysroot still failed, try fully stripping the drive spec, and trying once more in the sysroot before giving up. c:/foo/bar.dll ==> /sysroot/foo/bar.dll. */ - temp_pathname = concat (sysroot, - need_dir_separator ? SLASH_STRING : "", - in_pathname + 2, (char *) NULL); + temp_pathname.reset (concat (sysroot, + need_dir_separator ? SLASH_STRING : "", + in_pathname + 2, (char *) NULL)); - found_file = gdb_open_cloexec (temp_pathname, O_RDONLY | O_BINARY, 0); - if (found_file < 0) - xfree (temp_pathname); + found_file = gdb_open_cloexec (temp_pathname.get (), + O_RDONLY | O_BINARY, 0); } } @@ -304,7 +299,7 @@ solib_find_1 (const char *in_pathname, int *fd, int is_solib) needs to be freed. */ if (found_file < 0) - temp_pathname = NULL; + temp_pathname.reset (NULL); /* If the search in gdb_sysroot failed, and the path name is absolute at this point, make it relative. (openp will try and open the @@ -366,7 +361,7 @@ solib_find_1 (const char *in_pathname, int *fd, int is_solib) else *fd = found_file; - return gdb::unique_xmalloc_ptr<char> (temp_pathname); + return temp_pathname; } /* Return the full pathname of the main executable, or NULL if not @@ -407,10 +402,7 @@ exec_file_find (const char *in_pathname, int *fd) (If that fails, we'll just fall back on the original filename. Not much more we can do...) */ - char *full_path = NULL; - if (source_full_path_of (in_pathname, &full_path)) - result.reset (full_path); - else + if (!source_full_path_of (in_pathname, &result)) result.reset (xstrdup (in_pathname)); if (fd != NULL) *fd = -1; |