From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 128083 invoked by alias); 27 Jul 2015 16:37:17 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 128058 invoked by uid 9674); 27 Jul 2015 16:37:16 -0000 Date: Mon, 27 Jul 2015 16:37:00 -0000 Message-ID: <20150727163716.128027.qmail@sourceware.org> From: jkratoch@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] jankratochvil/gdbserverbuildid2: openp X-Git-Refname: refs/heads/jankratochvil/gdbserverbuildid2 X-Git-Reftype: branch X-Git-Oldrev: 0dc7ee5d050052454ba752481d49f785235b49cb X-Git-Newrev: 899c90e45fd688516a2bf5c56d2df6076f80de1d X-SW-Source: 2015-q3/txt/msg00004.txt.bz2 List-Id: The branch, jankratochvil/gdbserverbuildid2 has been updated discards 0dc7ee5d050052454ba752481d49f785235b49cb (commit) via 899c90e45fd688516a2bf5c56d2df6076f80de1d (commit) via 839d94bf2fcbec69cde88238f29007a7aa7cbcb4 (commit) via 885b8f5289e40cff7c47c7117dcd88209271c566 (commit) from 0dc7ee5d050052454ba752481d49f785235b49cb (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 899c90e45fd688516a2bf5c56d2df6076f80de1d Author: Jan Kratochvil Date: Sat Jul 25 23:11:36 2015 +0200 openp commit 839d94bf2fcbec69cde88238f29007a7aa7cbcb4 Author: Jan Kratochvil Date: Tue Jul 21 16:33:53 2015 +0200 tripleparam commit 885b8f5289e40cff7c47c7117dcd88209271c566 Author: Jan Kratochvil Date: Sat Jul 25 22:48:02 2015 +0200 sysroots ----------------------------------------------------------------------- Summary of changes: gdb/gdb_bfd.c | 2 +- gdb/gdb_bfd.h | 2 + gdb/solib.c | 187 +++++++++++++++++++++++++++++++++++++++----------------- 3 files changed, 133 insertions(+), 58 deletions(-) First 500 lines of diff: diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 1781d80..6b65425 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -158,7 +158,7 @@ gdb_bfd_has_target_filename (struct bfd *abfd) /* Return the system error number corresponding to ERRNUM. */ -static int +int fileio_errno_to_host (int errnum) { switch (errnum) diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h index 8fbdf36..2ec8285 100644 --- a/gdb/gdb_bfd.h +++ b/gdb/gdb_bfd.h @@ -169,4 +169,6 @@ int gdb_bfd_count_sections (bfd *abfd); int gdb_bfd_requires_relocations (bfd *abfd); +int fileio_errno_to_host (int errnum); + #endif /* GDB_BFD_H */ diff --git a/gdb/solib.c b/gdb/solib.c index f69e212..d50f883 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -46,6 +46,8 @@ #include "filesystem.h" #include "gdb_bfd.h" #include "filestuff.h" +#include "build-id.h" +#include "gdb/fileio.h" /* Architecture-specific operations. */ @@ -157,25 +159,78 @@ struct solib_find_result char *errmsg; }; -struct solib_find_result +static const char * +solib_find_result_filename_get (const struct solib_find_result *result) +{ + if (result->abfd != NULL) + return bfd_get_filename (result->abfd); + gdb_assert (result->filename != NULL); + return result->filename; +} + +static void +solib_find_result_init (struct solib_find_result *result) +{ + memset (result, 0, sizeof (*result)); + result->fd = -1; +} + +static void +solib_find_result_free (struct solib_find_result *result) +{ + if (result->fd != -1) + { + if (is_target_filename (solib_find_result_filename_get (result))) + { + int target_errno; + + target_fileio_close (result->fd, &target_errno); + } + else + close (result->fd); + } + gdb_bfd_unref (result->abfd); + xfree (result->filename); + xfree (result->errmsg); +} + +static int +solib_find_result_is_valid (const struct solib_find_result *result) +{ + return result->abfd != NULL || result->filename != NULL; +} + +static char * +solib_find_result_convert_to_filename (struct solib_find_result result) +{ + char *retval; + + if (!solib_find_result_is_valid (&result)) + retval = NULL; + else + retval = xstrdup (solib_find_result_filename_get (&result)); + solib_find_result_free (&result); + return retval; +} + +static struct solib_find_result solib_find_result_from_filename (const char *filename, size_t build_idsz, const gdb_byte *build_id) { struct solib_find_result result; - memset (result, 0, sizeof (*result)); - result->fd = -1; + solib_find_result_init (&result); if (build_idsz) { - result.abfd = gdb_bfd_open (filename, gnutarget, fd); + result.abfd = gdb_bfd_open (filename, gnutarget, -1); if (result.abfd == NULL) { - result->errmsg = xstrdup (bfd_errmsg (bfd_get_error ())); + result.errmsg = xstrdup (bfd_errmsg (bfd_get_error ())); return result; } - if (!build_id_verify (abfd, build_id_len, build_id)) + if (!build_id_verify (result.abfd, build_idsz, build_id)) { gdb_bfd_unref (result.abfd); result.abfd = NULL; @@ -186,7 +241,7 @@ solib_find_result_from_filename (const char *filename, size_t build_idsz, { int target_errno; - result->filename = xstrdup (filename); + result.filename = xstrdup (filename); result.fd = target_fileio_open (current_inferior (), filename + strlen (TARGET_SYSROOT_PREFIX), FILEIO_O_RDONLY, 0, @@ -199,8 +254,8 @@ solib_find_result_from_filename (const char *filename, size_t build_idsz, } else { - result->filename = xstrdup (filename); - result.fd = gdb_open_cloexec (name, O_RDONLY | O_BINARY, 0); + result.filename = xstrdup (filename); + result.fd = gdb_open_cloexec (filename, O_RDONLY | O_BINARY, 0); if (result.fd == -1) { result.errmsg = xstrdup (safe_strerror (errno)); @@ -210,50 +265,16 @@ solib_find_result_from_filename (const char *filename, size_t build_idsz, return result; } -const char * -solib_find_result_filename_get (const struct solib_find_result *result) -{ - if (result->abfd != NULL) - return bfd_get_filename (result->abfd); - gdb_assert (result->filename != NULL); - return result->filename; -} - -void -solib_find_result_free (struct solib_find_result *result) -{ - if (result->fd != -1) - { - if (is_target_filename (solib_find_result_filename_get (result))) - { - int target_errno; - - target_fileio_close (result.fd, &target_errno); - } - else - close (fd); - } - gdb_bfd_unref (result->abfd); - xfree (result->filename); - xfree (result->errmsg); -} - -int -solib_find_result_is_valid (const struct solib_find_result *result) -{ - return result->abfd != NULL || result->filename != NULL; -} - static struct solib_find_result -solib_find_1 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, - int *fd, int is_solib) +solib_find_2 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, + int *fd, int is_solib, const char *sysroot_orig) { const struct target_so_ops *ops = solib_ops (target_gdbarch ()); int found_file = -1; char *temp_pathname = NULL; const char *fskind = effective_target_file_system_kind (); struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); - char *sysroot = gdb_sysroot; + char *sysroot; int prefix_len, orig_prefix_len; struct solib_find_result result; @@ -263,20 +284,20 @@ solib_find_1 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, filesystem. This ensures that the same search algorithm is used for all local files regardless of whether a "target:" prefix was used. */ - if (is_target_filename (sysroot) && target_filesystem_is_local ()) - sysroot += strlen (TARGET_SYSROOT_PREFIX); + if (is_target_filename (sysroot_orig) && target_filesystem_is_local ()) + sysroot_orig += strlen (TARGET_SYSROOT_PREFIX); /* Strip any trailing slashes from the absolute prefix. */ - prefix_len = orig_prefix_len = strlen (sysroot); + prefix_len = orig_prefix_len = strlen (sysroot_orig); - while (prefix_len > 0 && IS_DIR_SEPARATOR (sysroot[prefix_len - 1])) + while (prefix_len > 0 && IS_DIR_SEPARATOR (sysroot_orig[prefix_len - 1])) prefix_len--; if (prefix_len == 0) sysroot = NULL; else if (prefix_len != orig_prefix_len) { - sysroot = savestring (sysroot, prefix_len); + sysroot = savestring (sysroot_orig, prefix_len); make_cleanup (xfree, sysroot); } @@ -350,10 +371,10 @@ solib_find_1 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, if (fd != NULL) *fd = -1; do_cleanups (old_chain); - return temp_pathname; + return solib_find_result_from_filename (temp_pathname, build_idsz, build_id); } - result = solib_find_result_from_filename (temp_pathname); + result = solib_find_result_from_filename (temp_pathname, build_idsz, build_id); if (solib_find_result_is_valid (&result)) return result; @@ -473,7 +494,53 @@ solib_find_1 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, else *fd = found_file; - return temp_pathname; + return solib_find_result_from_filename (temp_pathname, build_idsz, build_id); +} + +static struct solib_find_result +solib_find_1 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, + int *fd, int is_solib) +{ + VEC (char_ptr) *sysroot_vec = dirnames_to_char_ptr_vec (gdb_sysroot); + struct cleanup *back_to = make_cleanup_free_char_ptr_vec (sysroot_vec); + struct solib_find_result retval; + char *sysroot; + int ix; + + /* Handle ambiguous "target:" split by dirnames_to_char_ptr_vec. */ + if (DIRNAME_SEPARATOR == ':') + for (ix = 0; ix < VEC_length (char_ptr, sysroot_vec);) + { + char *s = VEC_index (char_ptr, sysroot_vec, ix); + + if (strcmp (s, "target") != 0) + { + ++ix; + continue; + } + VEC_ordered_remove (char_ptr, sysroot_vec, ix); + xfree (s); + if (ix == VEC_length (char_ptr, sysroot_vec)) + VEC_safe_push (char_ptr, sysroot_vec, xstrdup ("target:")); + else + xfree (VEC_replace (char_ptr, sysroot_vec, ix, + concat ("target:", + VEC_index (char_ptr, sysroot_vec, ix), + NULL))); + } + + solib_find_result_init (&retval); + for (ix = 0; VEC_iterate (char_ptr, sysroot_vec, ix, sysroot); ++ix) + { + retval = solib_find_2 (in_pathname, build_idsz, build_id, fd, is_solib, + sysroot); + if (solib_find_result_is_valid (&retval)) + break; + solib_find_result_free (&retval); + } + + do_cleanups (back_to); + return retval; } /* Return the full pathname of the main executable, or NULL if not @@ -487,7 +554,8 @@ solib_find_1 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, char * exec_file_find (char *in_pathname, int *fd) { - char *result = solib_find_1 (in_pathname, 0, NULL, fd, 0); + char *result = solib_find_result_convert_to_filename + (solib_find_1 (in_pathname, 0, NULL, fd, 0)); if (result == NULL) { @@ -501,7 +569,8 @@ exec_file_find (char *in_pathname, int *fd) strcpy (new_pathname, in_pathname); strcat (new_pathname, ".exe"); - result = solib_find_1 (new_pathname, 0, NULL, fd, 0); + result = solib_find_result_convert_to_filename + (solib_find_1 (new_pathname, 0, NULL, fd, 0)); } } @@ -546,7 +615,11 @@ solib_find (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, } } - return solib_find_1 (in_pathname, build_idsz, build_id, fd, 1); + return +solib_find_result_convert_to_filename ( + solib_find_1 (in_pathname, build_idsz, build_id, fd, 1) +) + ; } /* Open and return a BFD for the shared library PATHNAME. If FD is not -1, hooks/post-receive -- Repository for Project Archer.