From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 52771 invoked by alias); 28 Jul 2015 21:00:28 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 52748 invoked by uid 9674); 28 Jul 2015 21:00:27 -0000 Date: Tue, 28 Jul 2015 21:00:00 -0000 Message-ID: <20150728210027.52706.qmail@sourceware.org> From: jkratoch@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] jankratochvil/gdbserverbuildid2: buildid X-Git-Refname: refs/heads/jankratochvil/gdbserverbuildid2 X-Git-Reftype: branch X-Git-Oldrev: e0fb2d2446411b7ec5c9e073747b8418cb2681e3 X-Git-Newrev: 51282bfd4e5ef67dc87a025955cb75891ae3d638 X-SW-Source: 2015-q3/txt/msg00006.txt.bz2 List-Id: The branch, jankratochvil/gdbserverbuildid2 has been updated discards e0fb2d2446411b7ec5c9e073747b8418cb2681e3 (commit) discards f7f5ba4195fa5a37633b3ca8bd9fc33c8e30d266 (commit) discards 0093337b616b186ff5b8d9de718fe31e15329496 (commit) discards ad63586bce2bef4de340275a51ec83acecd509cf (commit) discards 5e7045a421afe153fdaf3b6303326d5941f7be3b (commit) discards 839d94bf2fcbec69cde88238f29007a7aa7cbcb4 (commit) discards 885b8f5289e40cff7c47c7117dcd88209271c566 (commit) discards 0b042ef76563fea67c0983db9d51c0c0b3b37617 (commit) via 51282bfd4e5ef67dc87a025955cb75891ae3d638 (commit) via 5c924531a91c3f3de15c78fd9391c227ada306bc (commit) via b71f23819e18a21e20dc683ed9b0f41eab41b242 (commit) via 8859bde6c6dad70f79d9f1db719529fedd0a879a (commit) via 2066d1751f88b06a202e90eb69ed8551fc1391d8 (commit) via 044da2d2298af4004094cd5fcad24fdbbde03746 (commit) via 2fc65148a99cb8b2c2889479bccb9c4f605b2c84 (commit) via 972af46ddba59d32ba903da5bd736bc6239a1958 (commit) from e0fb2d2446411b7ec5c9e073747b8418cb2681e3 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 51282bfd4e5ef67dc87a025955cb75891ae3d638 Author: Jan Kratochvil Date: Tue Jul 28 22:13:31 2015 +0200 buildid commit 5c924531a91c3f3de15c78fd9391c227ada306bc Author: Jan Kratochvil Date: Tue Jul 28 22:12:52 2015 +0200 buildidproto commit b71f23819e18a21e20dc683ed9b0f41eab41b242 Author: Jan Kratochvil Date: Sat Jul 25 23:11:36 2015 +0200 openp commit 8859bde6c6dad70f79d9f1db719529fedd0a879a Author: Jan Kratochvil Date: Mon Jul 27 23:01:54 2015 +0200 openpnullpathname commit 2066d1751f88b06a202e90eb69ed8551fc1391d8 Author: Jan Kratochvil Date: Mon Jul 27 20:11:55 2015 +0200 openpmode commit 044da2d2298af4004094cd5fcad24fdbbde03746 Author: Jan Kratochvil Date: Mon Jul 27 22:42:55 2015 +0200 openppath commit 2fc65148a99cb8b2c2889479bccb9c4f605b2c84 Author: Jan Kratochvil Date: Mon Jul 27 23:15:48 2015 +0200 openpenum commit 972af46ddba59d32ba903da5bd736bc6239a1958 Author: Jan Kratochvil Date: Sat Jul 25 22:48:02 2015 +0200 sysroots ----------------------------------------------------------------------- Summary of changes: gdb/gdb_bfd.c | 16 +++- gdb/nto-tdep.c | 31 +++----- gdb/nto-tdep.h | 2 +- gdb/solib.c | 196 +++++++++++++++++++++++++-------------------- gdb/solist.h | 7 +- gdb/source.c | 244 +++++++++++++++++++++++++++++++++----------------------- gdb/source.h | 20 ++--- 7 files changed, 291 insertions(+), 225 deletions(-) First 500 lines of diff: diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 6b65425..e7a0a32 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -238,6 +238,16 @@ gdb_bfd_iovec_fileio_open (struct bfd *abfd, void *inferior) return stream; } +static void * +gdb_bfd_iovec_fileio_open_fd (struct bfd *abfd, void *fdp_voidp) +{ + int *stream, *fdp = fdp_voidp; + + stream = XCNEW (int); + *stream = *fdp; + return stream; +} + /* Wrapper for target_fileio_pread suitable for passing as the PREAD_FUNC argument to gdb_bfd_openr_iovec. */ @@ -326,11 +336,9 @@ gdb_bfd_open (const char *name, const char *target, int fd) { if (!target_filesystem_is_local ()) { - gdb_assert (fd == -1); - return gdb_bfd_openr_iovec (name, target, - gdb_bfd_iovec_fileio_open, - current_inferior (), + (fd == -1 ? gdb_bfd_iovec_fileio_open : gdb_bfd_iovec_fileio_open_fd), + (fd == -1 ? (void *) current_inferior () : (void *) &fd), gdb_bfd_iovec_fileio_pread, gdb_bfd_iovec_fileio_close, gdb_bfd_iovec_fileio_fstat); diff --git a/gdb/nto-tdep.c b/gdb/nto-tdep.c index 7c8b4ce..d5644e4 100644 --- a/gdb/nto-tdep.c +++ b/gdb/nto-tdep.c @@ -31,6 +31,7 @@ #include "solib-svr4.h" #include "gdbcore.h" #include "objfiles.h" +#include "source.h" #ifdef __CYGWIN__ #include @@ -81,14 +82,15 @@ nto_map_arch_to_cputype (const char *arch) return CPUTYPE_UNKNOWN; } -int -nto_find_and_open_solib (char *solib, char **temp_pathname) +struct file_location +nto_find_and_open_solib (char *solib, size_t build_idsz, const gdb_byte *build_id) { char *buf, *arch_path, *nto_root; const char *endian; const char *base; const char *arch; - int arch_len, len, ret; + int arch_len, len; + struct file_location result; #define PATH_FMT \ "%s/lib:%s/usr/lib:%s/usr/photon/lib:%s/usr/photon/dll:%s/lib/dll" @@ -127,22 +129,13 @@ nto_find_and_open_solib (char *solib, char **temp_pathname) arch_path); base = lbasename (solib); - ret = openp (buf, OPF_TRY_CWD_FIRST, base, temp_pathname); - if (ret < 0 && base != solib) - { - xsnprintf (arch_path, arch_len, "/%s", solib); - ret = open (arch_path, O_RDONLY | O_BINARY); - if (temp_pathname) - { - if (ret >= 0) - *temp_pathname = xstrdup (arch_path); - else - *temp_pathname = NULL; - } - } - if (ret >= 0) - *temp_pathname = gdb_realpath_and_xfree (*temp_pathname); - return ret; + result = openp_result (buf, OPF_TRY_CWD_FIRST | OPF_IS_BFD, base, build_idsz, build_id); + if (file_location_is_valid (&result) || base == solib) + return result; + file_location_free (&result); + + xsnprintf (arch_path, arch_len, "/%s", solib); + return file_location_from_filename (arch_path, 1 /* is_bfd */, build_idsz, build_id); } void diff --git a/gdb/nto-tdep.h b/gdb/nto-tdep.h index 1f8045a..754bf56 100644 --- a/gdb/nto-tdep.h +++ b/gdb/nto-tdep.h @@ -154,7 +154,7 @@ void nto_relocate_section_addresses (struct so_list *, int nto_map_arch_to_cputype (const char *); -int nto_find_and_open_solib (char *, char **); +struct file_location nto_find_and_open_solib (char *, size_t build_idsz, const gdb_byte *build_id); enum gdb_osabi nto_elf_osabi_sniffer (bfd *abfd); diff --git a/gdb/solib.c b/gdb/solib.c index a7ef780..15900c7 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -150,18 +150,16 @@ show_solib_search_path (struct ui_file *file, int from_tty, * machines since a sysroot will almost always be set. */ -static struct solib_find_result -solib_find_2 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, - int *fd, int is_solib, const char *sysroot_orig) +static struct file_location +solib_find_3 (char *in_pathname, int is_bfd, int is_solib, const char *sysroot_orig, size_t build_idsz, const gdb_byte *build_id) { 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; int prefix_len, orig_prefix_len; - struct solib_find_result result; + struct file_location result; /* If the absolute prefix starts with "target:" but the filesystem accessed by the target_fileio_* methods is the local filesystem @@ -250,31 +248,23 @@ solib_find_2 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, in_pathname, (char *) NULL); } - /* Handle files to be accessed via the target. */ - if (is_target_filename (temp_pathname)) + /* Now see if we can open it. */ + result = file_location_from_filename (temp_pathname, is_bfd, build_idsz, build_id); + if (file_location_is_valid (&result)) { - if (fd != NULL) - *fd = -1; do_cleanups (old_chain); - return solib_find_result_from_filename (temp_pathname, build_idsz, build_id, 1 /* is_bfd */ ); + return result; } + file_location_free (&result); - result = solib_find_result_from_filename (temp_pathname, build_idsz, build_id, 1 /* is_bfd */); - if (solib_find_result_is_valid (&result)) - return result; - - /* 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); + xfree (temp_pathname); /* 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, and retrying in the sysroot: c:/foo/bar.dll ==> /sysroot/c/foo/bar.dll. */ - if (found_file < 0 - && sysroot != NULL + if (strcmp (sysroot, "") != 0 && HAS_TARGET_DRIVE_SPEC (fskind, in_pathname)) { int need_dir_separator = !IS_DIR_SEPARATOR (in_pathname[2]); @@ -287,42 +277,48 @@ solib_find_2 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, in_pathname + 2, (char *) NULL); xfree (drive); - found_file = gdb_open_cloexec (temp_pathname, O_RDONLY | O_BINARY, 0); - if (found_file < 0) + result = file_location_from_filename (temp_pathname, is_bfd, build_idsz, build_id); + if (file_location_is_valid (&result)) { - xfree (temp_pathname); + do_cleanups (old_chain); + return result; + } + file_location_free (&result); - /* If the search in gdb_sysroot still failed, try fully - stripping the drive spec, and trying once more in the - sysroot before giving up. + xfree (temp_pathname); - c:/foo/bar.dll ==> /sysroot/foo/bar.dll. */ + /* If the search in gdb_sysroot still failed, try fully + stripping the drive spec, and trying once more in the + sysroot before giving up. - temp_pathname = concat (sysroot, - need_dir_separator ? SLASH_STRING : "", - in_pathname + 2, (char *) NULL); + c:/foo/bar.dll ==> /sysroot/foo/bar.dll. */ - found_file = gdb_open_cloexec (temp_pathname, O_RDONLY | O_BINARY, 0); - if (found_file < 0) - xfree (temp_pathname); + temp_pathname = concat (sysroot, + need_dir_separator ? SLASH_STRING : "", + in_pathname + 2, (char *) NULL); + + result = file_location_from_filename (temp_pathname, is_bfd, build_idsz, build_id); + if (file_location_is_valid (&result)) + { + do_cleanups (old_chain); + return result; } + file_location_free (&result); + + xfree (temp_pathname); } do_cleanups (old_chain); - /* We try to find the library in various ways. After each attempt, - either found_file >= 0 and temp_pathname is a malloc'd string, or - found_file < 0 and temp_pathname does not point to storage that - needs to be freed. */ + /* We try to find the library in various ways. */ - if (found_file < 0) - temp_pathname = NULL; + temp_pathname = 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 file according to its absolute path otherwise, which is not what we want.) Affects subsequent searches for this solib. */ - if (found_file < 0 && IS_TARGET_ABSOLUTE_PATH (fskind, in_pathname)) + if (IS_TARGET_ABSOLUTE_PATH (fskind, in_pathname)) { /* First, get rid of any drive letters etc. */ while (!IS_TARGET_DIR_SEPARATOR (fskind, *in_pathname)) @@ -335,74 +331,110 @@ solib_find_2 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, /* If not found, and we're looking for a solib, search the solib_search_path (if any). */ - if (is_solib && found_file < 0 && solib_search_path != NULL) - found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST, - in_pathname, &temp_pathname); + if (is_solib && solib_search_path != NULL) + { + result = openp_result (solib_search_path, OPF_TRY_CWD_FIRST | (is_bfd ? OPF_IS_BFD : 0), in_pathname, build_idsz, build_id); + if (file_location_is_valid (&result)) + return result; + file_location_free (&result); + } /* If not found, and we're looking for a solib, next search the solib_search_path (if any) for the basename only (ignoring the path). This is to allow reading solibs from a path that differs from the opened path. */ - if (is_solib && found_file < 0 && solib_search_path != NULL) - found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST, - target_lbasename (fskind, in_pathname), &temp_pathname); + if (is_solib && solib_search_path != NULL) + { + result = openp_result (solib_search_path, OPF_TRY_CWD_FIRST | (is_bfd ? OPF_IS_BFD : 0), target_lbasename (fskind, in_pathname), build_idsz, build_id); + if (file_location_is_valid (&result)) + return result; + file_location_free (&result); + } /* If not found, and we're looking for a solib, try to use target supplied solib search method. */ - if (is_solib && found_file < 0 && ops->find_and_open_solib) - found_file = ops->find_and_open_solib (in_pathname, &temp_pathname); + if (is_solib && ops->find_and_open_solib) + { + result = ops->find_and_open_solib (in_pathname, build_idsz, build_id); + if (file_location_is_valid (&result)) + return result; + file_location_free (&result); + } /* If not found, next search the inferior's $PATH environment variable. */ - if (found_file < 0 && sysroot == NULL) - found_file = openp (get_in_environ (current_inferior ()->environment, - "PATH"), - OPF_TRY_CWD_FIRST, in_pathname, &temp_pathname); + if (strcmp (sysroot, "") == 0) + { + result = openp_result (get_in_environ (current_inferior ()->environment, "PATH"), OPF_TRY_CWD_FIRST | (is_bfd ? OPF_IS_BFD : 0), in_pathname, build_idsz, build_id); + if (file_location_is_valid (&result)) + return result; + file_location_free (&result); + } /* If not found, and we're looking for a solib, next search the inferior's $LD_LIBRARY_PATH environment variable. */ - if (is_solib && found_file < 0 && sysroot == NULL) - found_file = openp (get_in_environ (current_inferior ()->environment, - "LD_LIBRARY_PATH"), - OPF_TRY_CWD_FIRST, in_pathname, &temp_pathname); - - if (found_file >= 0) - temp_pathname = gdb_realpath_and_xfree (temp_pathname); - - if (fd == NULL) + if (is_solib && strcmp (sysroot, "") == 0) { - if (found_file >= 0) - close (found_file); + result = openp_result (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); + if (file_location_is_valid (&result)) + return result; + file_location_free (&result); } - else - *fd = found_file; - return solib_find_result_from_filename (temp_pathname, build_idsz, build_id, 1 /* is_bfd */); + file_location_init (&result); + return result; } -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) +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) { VEC (char_ptr) *sysroot_vec; struct cleanup *back_to; - struct solib_find_result retval; + struct file_location result; char *sysroot; int ix; sysroot_vec = dirnames_to_char_ptr_vec_target_exc (gdb_sysroot); back_to = make_cleanup_free_char_ptr_vec (sysroot_vec); - 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); + result = solib_find_3 (in_pathname, is_bfd, is_solib, sysroot, build_idsz, build_id); + if (file_location_is_valid (&result)) + { + do_cleanups (back_to); + return result; + } + file_location_free (&result); } do_cleanups (back_to); + return result; +} + +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 result = solib_find_2 (in_pathname, 0 /* is_bfd */, is_solib, build_idsz, build_id); + char *retval; + + if (!file_location_is_valid (&result)) + { + retval = NULL; + if (fd != NULL) + *fd = -1; + } + else + { + retval = xstrdup (result.filename); + if (fd != NULL) + { + gdb_assert (result.fd != -1); + *fd = result.fd; + result.fd = -1; + } + } + file_location_free (&result); return retval; } @@ -417,8 +449,7 @@ 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_result_convert_to_filename - (solib_find_1 (in_pathname, 0, NULL, fd, 0)); + char *result = solib_find_1 (in_pathname, 0, NULL, fd, 0); if (result == NULL) { @@ -432,8 +463,7 @@ exec_file_find (char *in_pathname, int *fd) strcpy (new_pathname, in_pathname); strcat (new_pathname, ".exe"); - result = solib_find_result_convert_to_filename - (solib_find_1 (new_pathname, 0, NULL, fd, 0)); + result = solib_find_1 (new_pathname, 0, NULL, fd, 0); } } @@ -478,11 +508,7 @@ solib_find (char *in_pathname, size_t build_idsz, const gdb_byte *build_id, } } - return -solib_find_result_convert_to_filename ( - solib_find_1 (in_pathname, build_idsz, build_id, fd, 1) -) - ; + return 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, diff --git a/gdb/solist.h b/gdb/solist.h index eb6160d..ca51095 100644 --- a/gdb/solist.h +++ b/gdb/solist.h @@ -143,11 +143,8 @@ struct target_so_ops bfd *(*bfd_open) (char *pathname, size_t build_idsz, const gdb_byte *build_id); - /* Optional extra hook for finding and opening a solib. - If TEMP_PATHNAME is non-NULL: If the file is successfully opened a - pointer to a malloc'd and realpath'd copy of SONAME is stored there, - otherwise NULL is stored there. */ - int (*find_and_open_solib) (char *soname, char **temp_pathname); + /* Optional extra hook for finding and opening a solib. */ + struct file_location (*find_and_open_solib) (char *soname, size_t build_idsz, const gdb_byte *build_id); /* Hook for looking up global symbols in a library-specific way. */ struct symbol * (*lookup_lib_global_symbol) (struct objfile *objfile, diff --git a/gdb/source.c b/gdb/source.c index 9811f99..7416f30 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -27,9 +27,9 @@ #include "frame.h" #include "value.h" #include "filestuff.h" -#include "build-id.h" #include "inferior.h" #include "gdb/fileio.h" +#include "build-id.h" #include #include @@ -705,28 +705,51 @@ is_regular_file (const char *name) return S_ISREG (st.st_mode); } -const char * -solib_find_result_filename_get (const struct solib_find_result *result) +VEC (char_ptr) * +dirnames_to_char_ptr_vec_target_exc (const char *string) { - if (result->abfd != NULL) - return bfd_get_filename (result->abfd); - gdb_assert (result->filename != NULL); - return result->filename; + VEC (char_ptr) *vec = dirnames_to_char_ptr_vec (string); + int ix; + char *s; + + /* Handle ambiguous "target:" split by dirnames_to_char_ptr_vec. */ + if (DIRNAME_SEPARATOR == ':') + for (ix = 0; ix < VEC_length (char_ptr, vec);) + { + char *s = VEC_index (char_ptr, vec, ix); + + if (strcmp (s, "target") != 0) + { + ++ix; + continue; + } + VEC_ordered_remove (char_ptr, vec, ix); + xfree (s); + if (ix == VEC_length (char_ptr, vec)) + VEC_safe_push (char_ptr, vec, xstrdup ("target:")); + else + xfree (VEC_replace (char_ptr, vec, ix, + concat ("target:", + VEC_index (char_ptr, vec, ix), + NULL))); + } + + return vec; } void -solib_find_result_init (struct solib_find_result *result) hooks/post-receive -- Repository for Project Archer.