diff options
author | Tom Tromey <tom@tromey.com> | 2017-08-03 16:53:22 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-08-22 09:30:12 -0600 |
commit | 14278e1fdbe045df184d6dd546ff6a1e9e3c3797 (patch) | |
tree | 9d736376600a484749b60ce7fe0902ae52650d68 /gdb/exec.c | |
parent | 4971c9a74b47103582834e46d0185390379e60b3 (diff) | |
download | gdb-14278e1fdbe045df184d6dd546ff6a1e9e3c3797.zip gdb-14278e1fdbe045df184d6dd546ff6a1e9e3c3797.tar.gz gdb-14278e1fdbe045df184d6dd546ff6a1e9e3c3797.tar.bz2 |
Change gdb_realpath to return a unique_xmalloc_ptr
This changes gdb_realpath to return a unique_xmalloc_ptr and fixes up
the callers. This allows removing some cleanups. This change by
itself caused xfullpath.exp to fail; and attempting to fix that ran
into various problems (like .get() being optimized out); so this patch
also rewrites xfullpath.exp to be a C++ selftest instead.
ChangeLog
2017-08-22 Tom Tromey <tom@tromey.com>
* exec.c (exec_file_attach): Update.
* linux-thread-db.c (try_thread_db_load): Update.
* guile/scm-safe-call.c (gdbscm_safe_source_script): Update.
* utils.c (gdb_realpath): Change return type.
(gdb_realpath_keepfile): Update.
(gdb_realpath_check_trailer, gdb_realpath_tests): New functions.
(_initialize_utils): Register the new self test.
* source.c (openp): Update.
(find_and_open_source): Update.
* nto-tdep.c (nto_find_and_open_solib): Update.
* main.c (set_gdb_data_directory): Update.
(captured_main_1): Update.
* dwarf2read.c (dwarf2_get_dwz_file): Update
(dw2_map_symbol_filenames): Update.
* auto-load.c (auto_load_safe_path_vec_update): Update.
(filename_is_in_auto_load_safe_path_vec): Change type of
"filename_realp".
(auto_load_objfile_script): Update.
(file_is_auto_load_safe): Update. Use std::string.
* utils.h (gdb_realpath): Return a gdb::unique_xmalloc_ptr.
testsuite/ChangeLog
2017-08-22 Tom Tromey <tom@tromey.com>
* gdb.gdb/xfullpath.exp: Remove.
Diffstat (limited to 'gdb/exec.c')
-rw-r--r-- | gdb/exec.c | 27 |
1 files changed, 11 insertions, 16 deletions
@@ -249,16 +249,12 @@ exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty) void exec_file_attach (const char *filename, int from_tty) { - struct cleanup *cleanups; - /* First, acquire a reference to the current exec_bfd. We release this at the end of the function; but acquiring it now lets the BFD cache return it if this call refers to the same file. */ gdb_bfd_ref (exec_bfd); gdb_bfd_ref_ptr exec_bfd_holder (exec_bfd); - cleanups = make_cleanup (null_cleanup, NULL); - /* Remove any previous exec file. */ exec_close (); @@ -274,7 +270,7 @@ exec_file_attach (const char *filename, int from_tty) else { int load_via_target = 0; - char *scratch_pathname, *canonical_pathname; + const char *scratch_pathname, *canonical_pathname; int scratch_chan; struct target_section *sections = NULL, *sections_end = NULL; char **matching; @@ -287,6 +283,7 @@ exec_file_attach (const char *filename, int from_tty) load_via_target = 1; } + gdb::unique_xmalloc_ptr<char> canonical_storage, scratch_storage; if (load_via_target) { /* gdb_bfd_fopen does not support "target:" filenames. */ @@ -295,19 +292,18 @@ exec_file_attach (const char *filename, int from_tty) "not supported for %s sysroots"), TARGET_SYSROOT_PREFIX); - scratch_pathname = xstrdup (filename); - make_cleanup (xfree, scratch_pathname); - + scratch_pathname = filename; scratch_chan = -1; - canonical_pathname = scratch_pathname; } else { + char *temp_pathname; + scratch_chan = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, filename, write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY, - &scratch_pathname); + &temp_pathname); #if defined(__GO32__) || defined(_WIN32) || defined(__CYGWIN__) if (scratch_chan < 0) { @@ -318,18 +314,19 @@ exec_file_attach (const char *filename, int from_tty) exename, write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY, - &scratch_pathname); + &temp_pathname); } #endif if (scratch_chan < 0) perror_with_name (filename); - make_cleanup (xfree, scratch_pathname); + scratch_storage.reset (temp_pathname); + scratch_pathname = temp_pathname; /* gdb_bfd_open (and its variants) prefers canonicalized pathname for better BFD caching. */ - canonical_pathname = gdb_realpath (scratch_pathname); - make_cleanup (xfree, canonical_pathname); + canonical_storage = gdb_realpath (scratch_pathname); + canonical_pathname = canonical_storage.get (); } gdb_bfd_ref_ptr temp; @@ -390,8 +387,6 @@ exec_file_attach (const char *filename, int from_tty) (*deprecated_exec_file_display_hook) (filename); } - do_cleanups (cleanups); - bfd_cache_close_all (); observer_notify_executable_changed (); } |