From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 73320 invoked by alias); 13 Aug 2015 10:40:00 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 73302 invoked by uid 9674); 13 Aug 2015 10:39:59 -0000 Date: Thu, 13 Aug 2015 10:40:00 -0000 Message-ID: <20150813103959.73239.qmail@sourceware.org> From: jkratoch@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] jankratochvil/gdbserverbuildid: sticky X-Git-Refname: refs/heads/jankratochvil/gdbserverbuildid X-Git-Reftype: branch X-Git-Oldrev: ae009c1b5c62233bc52c92bb13829fbdf3f738d7 X-Git-Newrev: f975d18d3004c9e94572ae7ffd4f999f87f80789 X-SW-Source: 2015-q3/txt/msg00028.txt.bz2 List-Id: The branch, jankratochvil/gdbserverbuildid has been updated discards ae009c1b5c62233bc52c92bb13829fbdf3f738d7 (commit) discards 4ed402d23c9bc7587d6ebeb98aac1c89f0e2996c (commit) discards d6adbe2e2ea7cafa38a43192c558dc5fb986e9e2 (commit) discards 62c380d107f284c732691bc1cf483c7001bf0575 (commit) discards f2c851971ab84f0b66b2512e00116d0cec15abe7 (commit) discards 63c8894843b98d28081a1a4ac9b22416ef139048 (commit) discards 01a167f13792d059fa27d18054793c3ed3adb2b3 (commit) discards f2e33a76348337f91f9be5a54f328e3c070a869b (commit) discards 388cf8787adb0db1a5751311181c5ae6ff2fcab8 (commit) discards 27854d1c85f0c689fec9e6c7617d09fb2c78be3a (commit) discards f53fe5034f3b652e3bd4424eb9c3641cf057b37e (commit) discards f3fb5a6526fe3ffdc2314290507a209acae2a5f1 (commit) discards 1f28d772f900f8963ffaed2b7c37edfcd40efc92 (commit) discards 486a40586c5f428a13048cef5c1575ebb9f18b61 (commit) discards 18d4031ae35ae4a5dcb03f5eeba6cd43fa713700 (commit) discards 0501d9df3ad566c9d66fb814584852dbd0930739 (commit) discards b21b3a3f00a0dd80ee641d7aa12e950e977303c1 (commit) discards 80432f849322811c259a05c8bd9a638a73e88cd5 (commit) via f975d18d3004c9e94572ae7ffd4f999f87f80789 (commit) via 5d9fe80e2f8fa1f5be7ebac7fbc949ecf9ef5bff (commit) via 7c5f60122e4d26c473e20e6fdfe359afeaefb47d (commit) via 56b758842d2db86be20e6a5ca38b523dd26d548f (commit) via c94619a21113490af5ec998d7f1d24e371fa9640 (commit) via 49969d8c4672a677f52fe60457969cd897dd53df (commit) via 77a40858ba8b6554da1090ffdd0d20cf0c70f6a1 (commit) via a0e710b8adadb856bf39f5c5a9f275f84dd9a3ba (commit) via 045fcf62670e30bdc5d8af524046d3bb3f9221eb (commit) via 1ea2fe5053ab1113dfb672c680ccff1be2f290b9 (commit) via 5fd3c99615b2ab8c9aa8abc21337be115fcd37cd (commit) via 7ac5e9d57bc417c75c97f51f7c44fa55ee9c169b (commit) via c4e403dfad6c919454ef5d2663712853b6bcbae8 (commit) via d0d477a45c5d4ecdc2820d4d0414056d3023ae13 (commit) via ca83807584ebd8716a66f7088dd05271002e99d9 (commit) via 4f5d6aa4fce87c00f74b0f205535ebcec7302e27 (commit) via 12e1597a9084f5d4f122d00a011870ef00c92334 (commit) via 6e55ed2607f6efdc058a5b6605914e6f92193189 (commit) from ae009c1b5c62233bc52c92bb13829fbdf3f738d7 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit f975d18d3004c9e94572ae7ffd4f999f87f80789 Author: Jan Kratochvil Date: Wed Aug 12 18:05:45 2015 +0200 sticky Message-Id: <1433754079-10395-1-git-send-email-gbenson@redhat.com> Philippe Waroquiers wrote: > On Fri, 2015-06-05 at 12:22 +0100, Gary Benson wrote: > > Built and regtested on RHEL6.6 x86_64. > I tested with the last SVN version of the Valgrind gdbserver (that > supports qXfer:exec-file:read+). > > The patch introduces a regression: > with the patch, GDB does not anymore automatically load the > exec-file. > > I bypassed this problem by ignoring fake_pid_p in remote.c: > --- a/gdb/remote.c > +++ b/gdb/remote.c > @@ -1624,9 +1624,13 @@ remote_add_inferior (int fake_pid_p, int pid, int > attached, > inf->attach_flag = attached; > inf->fake_pid_p = fake_pid_p; > > - /* If no main executable is currently open then attempt to > - open the file that was executed to create this inferior. */ > - if (try_open_exec && get_exec_file (0) == NULL) > + /* Attempt to open the file that was executed to create this > + inferior. If the user has explicitly specified executable > + and/or symbol files then warn the user if their choices do > + not match. Otherwise, set exec_file and symfile_objfile to > + the new file. */ > + printf("fake_pid_p %d\n", fake_pid_p); > + if (try_open_exec)// && !fake_pid_p) > exec_file_locate_attach (pid, 1); > > Effectively, the printf shows that with Valgrind gdbsrv, > fake_pid_p value is 1. > > When ignoring fake_pid_p, GDB can properly attach > to different Valgrind gdbsrv, and changes of executable > as expected. Ah, it seems I mailed a bad patch, my apologies! I was working on two fixes that touched the same line, and it looks like I rebased them in the wrong order. This updated patch has been created against the latest gdb/master (80fb91378c91a8239817a5ab2b1c3e346109db25). Could you please try your tests again? Thanks, Gary --- On attach, GDB will only attempt to determine the main executable's filename if one is not already set. This causes problems if you attach to one process and then attach to another: GDB will not attempt to discover the main executable on the second attach. If the two processes have different main executable files then the symbols will now be wrong. This is PR gdb/17626. In GDB some filenames are supplied by the user (e.g. using the "file" or "symbol-file" commands) and some are determined by GDB (e.g. while processing an "attach" command). This commit updates GDB to track which filenames were supplied by the user. When GDB might attempt to determine an executable filename and one is already set, filenames determined by GDB may be overridden but user-supplied filenames will not. gdb/ChangeLog: PR gdb/17626 * progspace.h (struct program_space) : New field. : Likewise. (symfile_objfile_is_user_supplied): New macro. * exec.h (exec_file_is_user_supplied): Likewise. * exec.c (exec_close): Clear exec_file_is_user_supplied. (exec_file_locate_attach): Remove get_exec_file check. Do not replace user-supplied executable or symbol files. Warn if user-supplied executable or symbol files do not match discovered file. (exec_file_command): Set exec_file_is_user_supplied. * symfile.c (symbol_file_clear): Clear symfile_objfile_is_user_supplied. (symbol_file_command): Set symfile_objfile_is_user_supplied. * inferior.c (add_inferior_command): Set exec_file_is_user_supplied and symfile_objfile_is_user_supplied. * main.c (captured_main): Likewise. * infcmd.c (attach_command_post_wait): Always call exec_file_locate_attach. Only call reopen_exec_file and reread_symbols if exec_file_is_user_supplied. * remote.c (remote_add_inferior): Remove get_exec_file check around exec_file_locate_attach. commit 5d9fe80e2f8fa1f5be7ebac7fbc949ecf9ef5bff Author: Jan Kratochvil Date: Wed Aug 12 18:05:44 2015 +0200 mainbuildid commit 7c5f60122e4d26c473e20e6fdfe359afeaefb47d Author: Jan Kratochvil Date: Wed Aug 12 18:05:44 2015 +0200 hexallocate commit 56b758842d2db86be20e6a5ca38b523dd26d548f Author: Jan Kratochvil Date: Wed Aug 12 18:05:44 2015 +0200 locatetest commit c94619a21113490af5ec998d7f1d24e371fa9640 Author: Jan Kratochvil Date: Sun Jul 12 20:59:03 2015 +0200 Tests for validate symbol file using build-id New testcase. gdb/testsuite/ChangeLog 2015-07-15 Aleksandar Ristovski Date: Wed Aug 12 18:05:43 2015 +0200 buildidwarn commit 77a40858ba8b6554da1090ffdd0d20cf0c70f6a1 Author: Jan Kratochvil Date: Wed Aug 12 18:05:43 2015 +0200 buildidsolibbfdopen commit a0e710b8adadb856bf39f5c5a9f275f84dd9a3ba Author: Jan Kratochvil Date: Wed Aug 12 18:05:43 2015 +0200 buildidverify commit 045fcf62670e30bdc5d8af524046d3bb3f9221eb Author: Jan Kratochvil Date: Wed Aug 12 18:05:43 2015 +0200 buildidsolibsearch commit 1ea2fe5053ab1113dfb672c680ccff1be2f290b9 Author: Jan Kratochvil Date: Wed Aug 12 18:05:43 2015 +0200 buildidtofile commit 5fd3c99615b2ab8c9aa8abc21337be115fcd37cd Author: Jan Kratochvil Date: Wed Aug 12 18:05:42 2015 +0200 buildidproto commit 7ac5e9d57bc417c75c97f51f7c44fa55ee9c169b Author: Jan Kratochvil Date: Wed Aug 12 18:05:42 2015 +0200 buildidtobfd commit c4e403dfad6c919454ef5d2663712853b6bcbae8 Author: Jan Kratochvil Date: Wed Aug 12 18:05:42 2015 +0200 buildidforcemove commit d0d477a45c5d4ecdc2820d4d0414056d3023ae13 Author: Jan Kratochvil Date: Wed Aug 12 18:05:42 2015 +0200 buildidfreefix commit ca83807584ebd8716a66f7088dd05271002e99d9 Author: Jan Kratochvil Date: Wed Aug 12 18:05:41 2015 +0200 openpsymfile commit 4f5d6aa4fce87c00f74b0f205535ebcec7302e27 Author: Jan Kratochvil Date: Wed Aug 12 18:05:41 2015 +0200 openpsolib commit 12e1597a9084f5d4f122d00a011870ef00c92334 Author: Jan Kratochvil Date: Wed Aug 12 18:05:41 2015 +0200 openp commit 6e55ed2607f6efdc058a5b6605914e6f92193189 Author: Jan Kratochvil Date: Wed Aug 12 18:05:41 2015 +0200 filelib ----------------------------------------------------------------------- Summary of changes: gdb/build-id.c | 2 +- gdb/defs.h | 6 +++++ gdb/exec.c | 4 +- gdb/nto-tdep.c | 2 +- gdb/solib.c | 32 ++++++++++++++-------------- gdb/source.c | 63 +++++++++++++++++++++++++++++++++++-------------------- gdb/source.h | 2 +- 7 files changed, 67 insertions(+), 44 deletions(-) First 500 lines of diff: diff --git a/gdb/build-id.c b/gdb/build-id.c index 037d710..d3986bc 100644 --- a/gdb/build-id.c +++ b/gdb/build-id.c @@ -148,7 +148,7 @@ build_id_to_file (size_t build_id_len, const bfd_byte *build_id, s += sprintf (s, "%02x", (unsigned) *data++); strcpy (s, suffix); - result = file_location_from_filename (link, is_bfd, build_id_len, build_id); + result = file_location_from_filename (link, (is_bfd ? OPF_IS_BFD : OPF_NONE), build_id_len, build_id); if (file_location_is_valid (&result)) { do_cleanups (back_to); diff --git a/gdb/defs.h b/gdb/defs.h index 2e91d83..0011635 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -318,9 +318,15 @@ extern const char *pc_prefix (CORE_ADDR); /* See openp function definition for their description. */ enum openp_flags { + OPF_NONE = 0, OPF_TRY_CWD_FIRST = (1 << 0), OPF_SEARCH_IN_PATH = (1 << 1), OPF_IS_BFD = (1 << 2), + + /* bfd_get_filename can be incorrect then, use only if you keep your + original filename separate from resulting bfd. + Returned file_location.filename is not canonicalized. */ + OPF_BFD_CANONICAL = (1 << 3), }; extern int openp (const char *, enum openp_flags, const char *, char **); diff --git a/gdb/exec.c b/gdb/exec.c index 68ebc31..4d0e646 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -234,14 +234,14 @@ exec_file_attach (const char *filename, int from_tty) struct target_section *sections = NULL, *sections_end = NULL; char **matching; - exec_bfd = openp_bfd (getenv ("PATH"), OPF_TRY_CWD_FIRST, filename); + exec_bfd = openp_bfd (getenv ("PATH"), OPF_TRY_CWD_FIRST | OPF_BFD_CANONICAL, filename); #if defined(__GO32__) || defined(_WIN32) || defined(__CYGWIN__) if (exec_bfd == NULL) { char *exename = alloca (strlen (filename) + 5); strcat (strcpy (exename, filename), ".exe"); - exec_bfd = openp_bfd (getenv ("PATH"), OPF_TRY_CWD_FIRST, exename); + exec_bfd = openp_bfd (getenv ("PATH"), OPF_TRY_CWD_FIRST | OPF_BFD_CANONICAL, exename); } #endif if (exec_bfd == NULL) diff --git a/gdb/nto-tdep.c b/gdb/nto-tdep.c index 5bb0e7f..e923222 100644 --- a/gdb/nto-tdep.c +++ b/gdb/nto-tdep.c @@ -135,7 +135,7 @@ nto_find_and_open_solib (char *solib, size_t build_idsz, const gdb_byte *build_i file_location_free (&file); xsnprintf (arch_path, arch_len, "/%s", solib); - return file_location_from_filename (arch_path, 1 /* is_bfd */, build_idsz, build_id); + return file_location_from_filename (arch_path, OPF_IS_BFD, build_idsz, build_id); } void diff --git a/gdb/solib.c b/gdb/solib.c index acb2eb1..d6ec58e 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -152,7 +152,7 @@ show_solib_search_path (struct ui_file *file, int from_tty, */ static struct file_location -solib_find_3 (char *in_pathname, int is_bfd, int is_solib, const char *sysroot, size_t build_idsz, const gdb_byte *build_id) +solib_find_3 (char *in_pathname, enum openp_flags opts, int is_solib, const char *sysroot, size_t build_idsz, const gdb_byte *build_id) { const struct target_so_ops *ops = solib_ops (target_gdbarch ()); char *temp_pathname; @@ -251,7 +251,7 @@ solib_find_3 (char *in_pathname, int is_bfd, int is_solib, const char *sysroot, } /* Now see if we can open it. */ - file = file_location_from_filename (temp_pathname, is_bfd, build_idsz, build_id); + file = file_location_from_filename (temp_pathname, opts, build_idsz, build_id); if (file_location_is_valid (&file)) { do_cleanups (old_chain); @@ -279,7 +279,7 @@ solib_find_3 (char *in_pathname, int is_bfd, int is_solib, const char *sysroot, in_pathname + 2, (char *) NULL); xfree (drive); - file = file_location_from_filename (temp_pathname, is_bfd, build_idsz, build_id); + file = file_location_from_filename (temp_pathname, opts, build_idsz, build_id); if (file_location_is_valid (&file)) { do_cleanups (old_chain); @@ -299,7 +299,7 @@ solib_find_3 (char *in_pathname, int is_bfd, int is_solib, const char *sysroot, need_dir_separator ? SLASH_STRING : "", in_pathname + 2, (char *) NULL); - file = file_location_from_filename (temp_pathname, is_bfd, build_idsz, build_id); + file = file_location_from_filename (temp_pathname, opts, build_idsz, build_id); if (file_location_is_valid (&file)) { do_cleanups (old_chain); @@ -316,7 +316,7 @@ solib_find_3 (char *in_pathname, int is_bfd, int is_solib, const char *sysroot, if (build_idsz != 0) { - file = build_id_to_file (build_idsz, build_id, "", is_bfd); + file = build_id_to_file (build_idsz, build_id, "", (opts & OPF_IS_BFD) != 0); if (file_location_is_valid (&file)) { do_cleanups (old_chain); @@ -344,7 +344,7 @@ solib_find_3 (char *in_pathname, int is_bfd, int is_solib, const char *sysroot, solib_search_path (if any). */ if (is_solib && solib_search_path != NULL) { - file = openp_file (solib_search_path, OPF_TRY_CWD_FIRST | (is_bfd ? OPF_IS_BFD : 0), in_pathname, build_idsz, build_id); + file = openp_file (solib_search_path, OPF_TRY_CWD_FIRST | opts, in_pathname, build_idsz, build_id); if (file_location_is_valid (&file)) { file.filename = gdb_realpath_and_xfree (file.filename); @@ -359,7 +359,7 @@ solib_find_3 (char *in_pathname, int is_bfd, int is_solib, const char *sysroot, from the opened path. */ if (is_solib && solib_search_path != NULL) { - file = openp_file (solib_search_path, OPF_TRY_CWD_FIRST | (is_bfd ? OPF_IS_BFD : 0), target_lbasename (fskind, in_pathname), build_idsz, build_id); + file = openp_file (solib_search_path, OPF_TRY_CWD_FIRST | opts, target_lbasename (fskind, in_pathname), build_idsz, build_id); if (file_location_is_valid (&file)) { file.filename = gdb_realpath_and_xfree (file.filename); @@ -381,7 +381,7 @@ solib_find_3 (char *in_pathname, int is_bfd, int is_solib, const char *sysroot, /* If not found, next search the inferior's $PATH environment variable. */ if (sysroot == NULL) { - file = openp_file (get_in_environ (current_inferior ()->environment, "PATH"), OPF_TRY_CWD_FIRST | (is_bfd ? OPF_IS_BFD : 0), in_pathname, build_idsz, build_id); + file = openp_file (get_in_environ (current_inferior ()->environment, "PATH"), OPF_TRY_CWD_FIRST | opts, in_pathname, build_idsz, build_id); if (file_location_is_valid (&file)) { file.filename = gdb_realpath_and_xfree (file.filename); @@ -394,7 +394,7 @@ solib_find_3 (char *in_pathname, int is_bfd, int is_solib, const char *sysroot, inferior's $LD_LIBRARY_PATH environment variable. */ if (is_solib && sysroot == NULL) { - file = openp_file (get_in_environ (current_inferior ()->environment, "LD_LIBRARY_PATH"), OPF_TRY_CWD_FIRST | (is_bfd ? OPF_IS_BFD : 0), in_pathname, build_idsz, build_id); + file = openp_file (get_in_environ (current_inferior ()->environment, "LD_LIBRARY_PATH"), OPF_TRY_CWD_FIRST | opts, in_pathname, build_idsz, build_id); if (file_location_is_valid (&file)) { file.filename = gdb_realpath_and_xfree (file.filename); @@ -408,7 +408,7 @@ solib_find_3 (char *in_pathname, int is_bfd, int is_solib, const char *sysroot, } static struct file_location -solib_find_2 (char *in_pathname, int is_bfd, int is_solib, size_t build_idsz, const gdb_byte *build_id) +solib_find_2 (char *in_pathname, enum openp_flags opts, int is_solib, size_t build_idsz, const gdb_byte *build_id) { VEC (char_ptr) *sysroot_vec; struct cleanup *back_to; @@ -421,7 +421,7 @@ solib_find_2 (char *in_pathname, int is_bfd, int is_solib, size_t build_idsz, co for (ix = 0; VEC_iterate (char_ptr, sysroot_vec, ix, sysroot); ++ix) { - file = solib_find_3 (in_pathname, is_bfd, is_solib, sysroot, build_idsz, build_id); + file = solib_find_3 (in_pathname, opts, is_solib, sysroot, build_idsz, build_id); if (file_location_is_valid (&file)) { do_cleanups (back_to); @@ -438,7 +438,7 @@ static char * solib_find_1 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, int *fd, int is_solib) { - struct file_location file = solib_find_2 (in_pathname, 0 /* is_bfd */, is_solib, build_idsz, build_id); + struct file_location file = solib_find_2 (in_pathname, OPF_NONE, is_solib, build_idsz, build_id); char *retval; if (!file_location_is_valid (&file)) @@ -502,7 +502,7 @@ exec_file_find (char *in_pathname, int *fd) above. */ static struct file_location -solib_find_file (char *in_pathname, int is_bfd, size_t build_idsz, const gdb_byte *build_id) +solib_find_file (char *in_pathname, enum openp_flags opts, size_t build_idsz, const gdb_byte *build_id) { const char *solib_symbols_extension = gdbarch_solib_symbols_extension (target_gdbarch ()); @@ -530,14 +530,14 @@ solib_find_file (char *in_pathname, int is_bfd, size_t build_idsz, const gdb_byt } } - return solib_find_2 (in_pathname, is_bfd, 1 /* is_solib */, build_idsz, build_id); + return solib_find_2 (in_pathname, opts, 1 /* is_solib */, build_idsz, build_id); } char * solib_find (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, int *fd) { - struct file_location file = solib_find_file (in_pathname, 0 /* is_bfd */, build_idsz, build_id); + struct file_location file = solib_find_file (in_pathname, OPF_NONE, build_idsz, build_id); char *retval; if (!file_location_is_valid (&file)) @@ -598,7 +598,7 @@ solib_bfd_open (char *pathname, size_t build_idsz, const gdb_byte *build_id) const struct bfd_arch_info *b; /* Search for shared library file. */ - file = solib_find_file (pathname, 1 /* is_bfd */, build_idsz, build_id); + file = solib_find_file (pathname, OPF_IS_BFD, build_idsz, build_id); if (!file_location_is_valid (&file)) { /* Return failure if the file could not be found, so that we can diff --git a/gdb/source.c b/gdb/source.c index 3c35075..827699d 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -782,7 +782,7 @@ file_location_is_valid (const struct file_location *file) } struct file_location -file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz, const gdb_byte *build_id) +file_location_from_filename (const char *filename, enum openp_flags opts, size_t build_idsz, const gdb_byte *build_id) { struct file_location file; int load_via_target = 0; @@ -824,7 +824,7 @@ file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz } else { - /* WRITE_FILES is ignored if !IS_BFD. */ + /* WRITE_FILES is ignored if !OPF_IS_BFD. */ file.fd = gdb_open_cloexec (filename, O_RDONLY | O_BINARY, 0); if (file.fd == -1) @@ -835,7 +835,7 @@ file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz } } - if (build_idsz == 0 && !is_bfd) + if (build_idsz == 0 && (opts & OPF_IS_BFD) == 0) { discard_cleanups (back_to); return file; @@ -843,31 +843,47 @@ file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz if (load_via_target) { - const int do_close = is_bfd; + const int do_close = (opts & OPF_IS_BFD) != 0; gdb_assert (strcmp (filename, file.filename + strlen (TARGET_SYSROOT_PREFIX)) == 0); file.abfd = gdb_bfd_open_from_target (file.filename, gnutarget, file.fd, do_close); if (do_close && file.abfd != NULL) file.fd = -1; } - else if (write_files) - { - file.abfd = gdb_bfd_fopen (filename, gnutarget, FOPEN_RUB, file.fd); - file.fd = -1; - } else { - char *canonical; + if (write_files) + file.abfd = gdb_bfd_fopen (filename, gnutarget, FOPEN_RUB, file.fd); + else if ((opts & OPF_BFD_CANONICAL) == 0) + file.abfd = gdb_bfd_open (filename, gnutarget, file.fd); + else + { + char *canonical; - /* gdb_bfd_open (and its variants) prefers canonicalized - pathname for better BFD caching. */ - struct cleanup *canonical_cleanup; + /* gdb_bfd_open (and its variants) prefers canonicalized + pathname for better BFD caching. */ + struct cleanup *canonical_cleanup; + + canonical = gdb_realpath (filename); + canonical_cleanup = make_cleanup (xfree, canonical); + file.abfd = gdb_bfd_open (canonical, gnutarget, file.fd); + do_cleanups (canonical_cleanup); + } + if ((opts & OPF_IS_BFD) != 0) + file.fd = -1; + else + { + file.fd = dup (file.fd); + if (file.fd == -1) + { + int save_errno = errno; - canonical = gdb_realpath (filename); - canonical_cleanup = make_cleanup (xfree, canonical); - file.abfd = gdb_bfd_open (canonical, gnutarget, file.fd); - file.fd = -1; - do_cleanups (canonical_cleanup); + do_cleanups (back_to); + file_location_enoent (&file); + file.file_errno = save_errno; + return file; + } + } } if (file.abfd == NULL) @@ -879,7 +895,7 @@ file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz if (build_idsz == 0) { - gdb_assert (is_bfd); + gdb_assert ((opts & OPF_IS_BFD) != 0); discard_cleanups (back_to); return file; } @@ -891,7 +907,7 @@ file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz return file; } - if (!is_bfd) + if ((opts & OPF_IS_BFD) == 0) { gdb_bfd_unref (file.abfd); file.abfd = NULL; @@ -936,7 +952,7 @@ file_location_to_bfd (struct file_location file) bfd * filename_to_bfd (const char *filename) { - return file_location_to_bfd (file_location_from_filename (filename, 1 /* is_bfd */, 0 /* build_idsz */, NULL /* build_id */)); + return file_location_to_bfd (file_location_from_filename (filename, OPF_IS_BFD, 0 /* build_idsz */, NULL /* build_id */)); } int @@ -1014,6 +1030,7 @@ openp_file (const char *path, enum openp_flags opts, const char *string, size_t struct file_location file; gdb_assert (string != NULL); + gdb_assert ((opts & (OPF_IS_BFD | OPF_BFD_CANONICAL)) != OPF_BFD_CANONICAL); /* A file with an empty name cannot possibly exist. Report a failure without further checking. @@ -1039,7 +1056,7 @@ openp_file (const char *path, enum openp_flags opts, const char *string, size_t { filename = alloca (strlen (string) + 1); strcpy (filename, string); - file = file_location_from_filename (filename, (opts & OPF_IS_BFD) != 0, build_idsz, build_id); + file = file_location_from_filename (filename, opts, build_idsz, build_id); if (file_location_is_valid (&file)) return file; file_location_free (&file); @@ -1136,7 +1153,7 @@ openp_file (const char *path, enum openp_flags opts, const char *string, size_t if (is_target_filename (filename) || is_regular_file (filename)) { - file = file_location_from_filename (filename, (opts & OPF_IS_BFD) != 0, build_idsz, build_id); + file = file_location_from_filename (filename, opts, build_idsz, build_id); if (file_location_is_valid (&file)) { do_cleanups (back_to); diff --git a/gdb/source.h b/gdb/source.h index 7571cef..e079cf0 100644 --- a/gdb/source.h +++ b/gdb/source.h @@ -116,7 +116,7 @@ extern void file_location_free (struct file_location *file); extern int file_location_is_valid (const struct file_location *file); -extern struct file_location file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz, const gdb_byte *build_id); +extern struct file_location file_location_from_filename (const char *filename, enum openp_flags opts, size_t build_idsz, const gdb_byte *build_id); extern bfd *file_location_to_bfd (struct file_location file); hooks/post-receive -- Repository for Project Archer.