public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM] jankratochvil/gdbserverbuildid2: buildid
@ 2015-07-29 20:55 jkratoch
0 siblings, 0 replies; 2+ messages in thread
From: jkratoch @ 2015-07-29 20:55 UTC (permalink / raw)
To: archer-commits
The branch, jankratochvil/gdbserverbuildid2 has been updated
discards 51282bfd4e5ef67dc87a025955cb75891ae3d638 (commit)
discards 5c924531a91c3f3de15c78fd9391c227ada306bc (commit)
discards b71f23819e18a21e20dc683ed9b0f41eab41b242 (commit)
via c15b4dc5da134d1fc80131d025459adab9edb071 (commit)
via 9673d0d64e72e2dbc7455d3700bf3793c8bf104c (commit)
via 0d4cc1d76b5a4c7f472a998a71f50f87f8371955 (commit)
via 62757e6e09df9aaa5a6b5c5681e71ce1ebd67a91 (commit)
via 12d35640805beb504883f5e811a773c2a458fb68 (commit)
via 9cb0c0a45bbf0797a69b9e4ea1b1c4059a7af9ec (commit)
via b6bfeca5e45c1a91923f89195e95adb41e672acf (commit)
from 51282bfd4e5ef67dc87a025955cb75891ae3d638 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit c15b4dc5da134d1fc80131d025459adab9edb071
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Tue Jul 28 22:13:31 2015 +0200
buildid
commit 9673d0d64e72e2dbc7455d3700bf3793c8bf104c
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Tue Jul 28 22:12:52 2015 +0200
buildidproto
commit 0d4cc1d76b5a4c7f472a998a71f50f87f8371955
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Wed Jul 29 21:38:45 2015 +0200
buildidtobfd
commit 62757e6e09df9aaa5a6b5c5681e71ce1ebd67a91
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Wed Jul 29 19:52:47 2015 +0200
buildidforcemove
commit 12d35640805beb504883f5e811a773c2a458fb68
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Sat Jul 25 23:11:36 2015 +0200
openp
commit 9cb0c0a45bbf0797a69b9e4ea1b1c4059a7af9ec
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Wed Jul 29 22:49:17 2015 +0200
filelib
commit b6bfeca5e45c1a91923f89195e95adb41e672acf
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Wed Jul 29 22:47:55 2015 +0200
targetfd
-----------------------------------------------------------------------
Summary of changes:
gdb/build-id.c | 97 ++++++++++++++++++++++++++++++++++++++---------------
gdb/build-id.h | 3 ++
gdb/solib.c | 101 ++++++++++++++++++++++++++++++++------------------------
gdb/source.c | 30 ++++-------------
gdb/source.h | 5 +--
5 files changed, 140 insertions(+), 96 deletions(-)
First 500 lines of diff:
diff --git a/gdb/build-id.c b/gdb/build-id.c
index c89cd55..636d5c3 100644
--- a/gdb/build-id.c
+++ b/gdb/build-id.c
@@ -26,6 +26,22 @@
#include "objfiles.h"
#include "filenames.h"
#include "gdbcore.h"
+#include "gdbcmd.h"
+#include "source.h"
+
+/* Boolean for command 'set validate-build-id'. */
+int validate_build_id = 1;
+
+/* Implement 'show validate-build-id'. */
+
+static void
+show_validate_build_id (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ fprintf_filtered (file, _("Validation a build-id matches to load a shared "
+ "library is %s.\n"),
+ value);
+}
/* See build-id.h. */
@@ -65,20 +81,23 @@ build_id_verify (bfd *abfd, size_t check_len, const bfd_byte *check)
return retval;
}
-/* See build-id.h. */
+/* Find and open a BFD given a build-id. If no BFD can be found,
+ return NULL. Use "" or ".debug" for SUFFIX. The returned reference to the
+ BFD must be released by the caller. */
-bfd *
-build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
+struct file_location
+build_id_to_file (size_t build_id_len, const bfd_byte *build_id,
+ const char *suffix, int is_bfd)
{
char *link, *debugdir;
VEC (char_ptr) *debugdir_vec;
struct cleanup *back_to;
int ix;
- bfd *abfd = NULL;
+ struct file_location result;
/* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */
link = alloca (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
- + 2 * build_id_len + (sizeof ".debug" - 1) + 1);
+ + 2 * build_id_len + strlen (suffix) + 1);
/* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
cause "/.build-id/..." lookups. */
@@ -92,8 +111,6 @@ build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
const gdb_byte *data = build_id;
size_t size = build_id_len;
char *s;
- char *filename = NULL;
- struct cleanup *inner;
memcpy (link, debugdir, debugdir_len);
s = &link[debugdir_len];
@@ -107,32 +124,39 @@ build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
*s++ = '/';
while (size-- > 0)
s += sprintf (s, "%02x", (unsigned) *data++);
- strcpy (s, ".debug");
-
- /* lrealpath() is expensive even for the usually non-existent files. */
- if (access (link, F_OK) == 0)
- filename = lrealpath (link);
+ strcpy (s, suffix);
- if (filename == NULL)
- continue;
+ result = file_location_from_filename (link, is_bfd, build_id_len, build_id);
+ if (file_location_is_valid (&result))
+ {
+ do_cleanups (back_to);
+ return result;
+ }
+ file_location_free (&result);
+ }
- /* We expect to be silent on the non-existing files. */
- inner = make_cleanup (xfree, filename);
- abfd = gdb_bfd_open (filename, gnutarget, -1);
- do_cleanups (inner);
+ file_location_init (&result);
+ return result;
+}
- if (abfd == NULL)
- continue;
+/* See build-id.h. */
- if (build_id_verify (abfd, build_id_len, build_id))
- break;
+bfd *
+build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
+{
+ struct file_location result;
+ bfd *retval;
- gdb_bfd_unref (abfd);
- abfd = NULL;
+ result = build_id_to_file (build_id_len, build_id, ".debug", 1 /* is_bfd */);
+ if (result.abfd == NULL)
+ {
+ file_location_free (&result);
+ return NULL;
}
-
- do_cleanups (back_to);
- return abfd;
+ gdb_bfd_ref (result.abfd);
+ retval = result.abfd;
+ file_location_free (&result);
+ return retval;
}
/* See build-id.h. */
@@ -167,3 +191,22 @@ find_separate_debug_file_by_buildid (struct objfile *objfile)
}
return NULL;
}
+
+extern initialize_file_ftype _initialize_build_id; /* -Wmissing-prototypes */
+
+void
+_initialize_build_id (void)
+{
+ add_setshow_boolean_cmd ("validate-build-id", class_support,
+ &validate_build_id, _("\
+Set validation a build-id matches to load a shared library."), _("\
+SHow validation a build-id matches to load a shared library."), _("\
+Inferior shared library and symbol file may contain unique build-id.\n\
+If both build-ids are present but they do not match then this setting\n\
+enables (off) or disables (on) loading of such symbol file.\n\
+Loading non-matching symbol file may confuse debugging including breakage\n\
+of backtrace output."),
+ NULL,
+ show_validate_build_id,
+ &setlist, &showlist);
+}
diff --git a/gdb/build-id.h b/gdb/build-id.h
index bea761b..5fd7043 100644
--- a/gdb/build-id.h
+++ b/gdb/build-id.h
@@ -30,6 +30,7 @@ extern const struct bfd_build_id *build_id_bfd_get (bfd *abfd);
extern int build_id_verify (bfd *abfd,
size_t check_len, const bfd_byte *check);
+extern struct file_location build_id_to_file (size_t build_id_len, const bfd_byte *build_id, const char *suffix, int is_bfd);
/* Find and open a BFD given a build-id. If no BFD can be found,
return NULL. The returned reference to the BFD must be released by
@@ -45,4 +46,6 @@ extern bfd *build_id_to_debug_bfd (size_t build_id_len,
extern char *find_separate_debug_file_by_buildid (struct objfile *objfile);
+extern int validate_build_id;
+
#endif /* BUILD_ID_H */
diff --git a/gdb/solib.c b/gdb/solib.c
index 15900c7..e5c1272 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -47,6 +47,9 @@
#include "gdb_bfd.h"
#include "filestuff.h"
#include "source.h"
+#include "build-id.h"
+
+static struct file_location solib_find_file (char *in_pathname, int is_bfd, size_t build_idsz, const gdb_byte *build_id);
/* Architecture-specific operations. */
@@ -154,7 +157,7 @@ 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 ());
- char *temp_pathname = NULL;
+ char *temp_pathname;
const char *fskind = effective_target_file_system_kind ();
struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
char *sysroot;
@@ -312,7 +315,16 @@ solib_find_3 (char *in_pathname, int is_bfd, int is_solib, const char *sysroot_o
/* We try to find the library in various ways. */
- temp_pathname = NULL;
+ if (build_idsz != 0)
+ {
+ result = build_id_to_file (build_idsz, build_id, "", is_bfd);
+ if (file_location_is_valid (&result))
+ {
+ do_cleanups (old_chain);
+ return result;
+ }
+ file_location_free (&result);
+ }
/* 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
@@ -449,7 +461,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_1 (in_pathname, 0, NULL, fd, 0);
+ char *result = solib_find_1 (in_pathname, 0 /* build_idsz */, NULL, fd, 0 /* is_solib */);
if (result == NULL)
{
@@ -463,7 +475,7 @@ 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_1 (new_pathname, 0 /* build_idsz */, NULL, fd, 0 /* is_solib */);
}
}
@@ -478,9 +490,8 @@ exec_file_find (char *in_pathname, int *fd)
The search algorithm used is described in solib_find_1's comment
above. */
-char *
-solib_find (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
- int *fd)
+static struct file_location
+solib_find_file (char *in_pathname, int is_bfd, size_t build_idsz, const gdb_byte *build_id)
{
const char *solib_symbols_extension
= gdbarch_solib_symbols_extension (target_gdbarch ());
@@ -508,7 +519,34 @@ 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_2 (in_pathname, is_bfd, 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);
+ char *retval;
+
+ if (!file_location_is_valid (&file))
+ {
+ retval = NULL;
+ if (fd != NULL)
+ *fd = -1;
+ }
+ else
+ {
+ retval = xstrdup (file.filename);
+ if (fd != NULL)
+ {
+ gdb_assert (file.fd != -1);
+ *fd = file.fd;
+ file.fd = -1;
+ }
+ }
+ file_location_free (&file);
+ return retval;
}
/* Open and return a BFD for the shared library PATHNAME. If FD is not -1,
@@ -544,25 +582,30 @@ solib_bfd_fopen (char *pathname, int fd)
bfd *
solib_bfd_open (char *pathname, size_t build_idsz, const gdb_byte *build_id)
{
- char *found_pathname;
- int found_file;
+ struct file_location file;
bfd *abfd;
const struct bfd_arch_info *b;
/* Search for shared library file. */
- found_pathname = solib_find (pathname, build_idsz, build_id, &found_file);
- if (found_pathname == NULL)
+ file = solib_find_file (pathname, 1 /* 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
accumulate messages about missing libraries. */
- if (errno == ENOENT)
- return NULL;
+ if (file.file_errno == ENOENT)
+ {
+ file_location_free (&file);
+ return NULL;
+ }
+ file_location_free (&file);
perror_with_name (pathname);
}
/* Open bfd for shared library. */
- abfd = solib_bfd_fopen (found_pathname, found_file);
+ gdb_bfd_ref (file.abfd);
+ abfd = file.abfd;
+ file_location_free (&file);
/* Check bfd format. */
if (!bfd_check_format (abfd, bfd_object))
@@ -582,20 +625,6 @@ solib_bfd_open (char *pathname, size_t build_idsz, const gdb_byte *build_id)
return abfd;
}
-/* Boolean for command 'set validate-build-id'. */
-static int validate_build_id = 1;
-
-/* Implement 'show validate-build-id'. */
-
-static void
-show_validate_build_id (struct ui_file *file, int from_tty,
- struct cmd_list_element *c, const char *value)
-{
- fprintf_filtered (file, _("Validation a build-id matches to load a shared "
- "library is %s.\n"),
- value);
-}
-
/* Given a pointer to one of the shared objects in our list of mapped
objects, use the recorded name to open a bfd descriptor for the
object, build a section table, relocate all the section addresses
@@ -1826,18 +1855,4 @@ PATH and LD_LIBRARY_PATH."),
reload_shared_libraries,
show_solib_search_path,
&setlist, &showlist);
-
- add_setshow_boolean_cmd ("validate-build-id", class_support,
- &validate_build_id, _("\
-Set validation a build-id matches to load a shared library."), _("\
-SHow validation a build-id matches to load a shared library."), _("\
-Inferior shared library and symbol file may contain unique build-id.\n\
-If both build-ids are present but they do not match then this setting\n\
-enables (off) or disables (on) loading of such symbol file.\n\
-Loading non-matching symbol file may confuse debugging including breakage\n\
-of backtrace output."),
- NULL,
- show_validate_build_id,
- &setlist, &showlist);
-
}
diff --git a/gdb/source.c b/gdb/source.c
index 7416f30..297c2f3 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -760,7 +760,6 @@ file_location_free (struct file_location *result)
}
gdb_bfd_unref (result->abfd);
xfree (result->filename);
- xfree (result->errmsg);
}
static void
@@ -775,19 +774,6 @@ file_location_is_valid (const struct file_location *result)
return result->abfd != NULL || result->filename != NULL;
}
-char *
-file_location_convert_to_filename (struct file_location result)
-{
- char *retval;
-
- if (!file_location_is_valid (&result))
- retval = NULL;
- else
- retval = xstrdup (result.filename);
- file_location_free (&result);
- return retval;
-}
-
struct file_location
file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz, const gdb_byte *build_id)
{
@@ -825,7 +811,7 @@ file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz
&target_errno);
if (result.fd == -1)
{
- result.errmsg = xstrdup (safe_strerror (fileio_errno_to_host (target_errno)));
+ result.file_errno = fileio_errno_to_host (target_errno);
discard_cleanups (back_to);
return result;
}
@@ -837,13 +823,13 @@ file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz
result.fd = gdb_open_cloexec (filename, O_RDONLY | O_BINARY, 0);
if (result.fd == -1)
{
- result.errmsg = xstrdup (safe_strerror (errno));
+ result.file_errno = errno;
discard_cleanups (back_to);
return result;
}
}
- if (build_idsz == 0 && !is_bfd)
+ if ((build_idsz == 0 || !validate_build_id) && !is_bfd)
{
discard_cleanups (back_to);
return result;
@@ -855,7 +841,7 @@ file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz
fd_dup = dup (result.fd);
if (fd_dup == -1)
{
- result.errmsg = xstrdup (safe_strerror (errno));
+ result.file_errno = errno;
close (result.fd);
result.fd = -1;
discard_cleanups (back_to);
@@ -884,13 +870,13 @@ file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz
result.fd = -1;
if (result.abfd == NULL)
{
- result.errmsg = xstrdup (bfd_errmsg (bfd_get_error ()));
+ result.bfderr = bfd_get_error ();
do_cleanups (fd_dup_cleanup);
discard_cleanups (back_to);
return result;
}
- if (build_idsz == 0)
+ if (build_idsz == 0 || !validate_build_id)
{
gdb_assert (is_bfd);
gdb_assert (fd_dup == -1);
@@ -952,13 +938,11 @@ openp_bfd (const char *path, enum openp_flags opts, const char *string)
gdb_assert ((opts & OPF_IS_BFD) == 0);
result = openp_result (path, opts | OPF_IS_BFD, string, 0, NULL);
- gdb_assert (result.abfd == NULL);
- if (result.fd == -1)
+ if (result.abfd == NULL)
{
file_location_free (&result);
return NULL;
}
- gdb_assert (result.abfd != NULL);
gdb_bfd_ref (result.abfd);
retval = result.abfd;
file_location_free (&result);
diff --git a/gdb/source.h b/gdb/source.h
index daaa217..c79090b 100644
--- a/gdb/source.h
+++ b/gdb/source.h
@@ -106,7 +106,8 @@ struct file_location
bfd *abfd;
char *filename;
int fd;
- char *errmsg;
+ int file_errno;
+ bfd_error_type bfderr;
};
extern void file_location_init (struct file_location *result);
@@ -115,8 +116,6 @@ extern void file_location_free (struct file_location *result);
extern int file_location_is_valid (const struct file_location *result);
-extern char *file_location_convert_to_filename (struct file_location result);
-
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 openp_result (const char *path, enum openp_flags opts, const char *string, size_t build_idsz, const gdb_byte *build_id);
hooks/post-receive
--
Repository for Project Archer.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [SCM] jankratochvil/gdbserverbuildid2: buildid
@ 2015-07-28 21:00 jkratoch
0 siblings, 0 replies; 2+ messages in thread
From: jkratoch @ 2015-07-28 21:00 UTC (permalink / raw)
To: archer-commits
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 <jan.kratochvil@redhat.com>
Date: Tue Jul 28 22:13:31 2015 +0200
buildid
commit 5c924531a91c3f3de15c78fd9391c227ada306bc
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Tue Jul 28 22:12:52 2015 +0200
buildidproto
commit b71f23819e18a21e20dc683ed9b0f41eab41b242
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Sat Jul 25 23:11:36 2015 +0200
openp
commit 8859bde6c6dad70f79d9f1db719529fedd0a879a
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Mon Jul 27 23:01:54 2015 +0200
openpnullpathname
commit 2066d1751f88b06a202e90eb69ed8551fc1391d8
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Mon Jul 27 20:11:55 2015 +0200
openpmode
commit 044da2d2298af4004094cd5fcad24fdbbde03746
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Mon Jul 27 22:42:55 2015 +0200
openppath
commit 2fc65148a99cb8b2c2889479bccb9c4f605b2c84
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Mon Jul 27 23:15:48 2015 +0200
openpenum
commit 972af46ddba59d32ba903da5bd736bc6239a1958
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
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 <sys/cygwin.h>
@@ -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 <sys/types.h>
#include <sys/stat.h>
@@ -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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-07-29 20:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-29 20:55 [SCM] jankratochvil/gdbserverbuildid2: buildid jkratoch
-- strict thread matches above, loose matches on Subject: below --
2015-07-28 21:00 jkratoch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).