public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v12 08/32] Permit multiple sysroot directories
Date: Fri, 21 Aug 2015 21:21:00 -0000	[thread overview]
Message-ID: <20150821212111.6673.85003.stgit@host1.jankratochvil.net> (raw)
In-Reply-To: <20150821212006.6673.35100.stgit@host1.jankratochvil.net>

Hi,

the goal is to have both "" and "target:" as the default gdb_sysroot, in this
order.  Therefore permit multiple directory components of gdb_sysroot.


Jan


gdb/ChangeLog
2015-08-18  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* NEWS (Changes since GDB 7.10): Mention set sysroot and show sysroot.
	* solib.c: Include source.h.
	(solib_find_1): Rename to ...
	(solib_find_2): ... here and change the sysroot variable to parameter.
	(solib_find_1): Call it using dirnames_to_char_ptr_vec_target_exc.
	* source.c (dirnames_to_char_ptr_vec_target_exc): New function.
	* source.h (dirnames_to_char_ptr_vec_target_exc): New declaration.

gdb/doc/ChangeLog
2015-08-18  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.texinfo (Files): Permit set sysroot and show sysroot to have
	multiple components.
---
 0 files changed

diff --git a/gdb/NEWS b/gdb/NEWS
index fce33f3..f5a01e8 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -35,6 +35,9 @@ show debug bfd-cache
   The "/m" option is now considered deprecated: its "source-centric"
   output hasn't proved useful in practice.
 
+* The "set sysroot" (and "show sysroot") commands now permit multiple
+  directory paths.
+
 * New options
 
 set validate-build-id (on|off)
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index e82e41d..fa30007 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18154,7 +18154,8 @@ to specify the search directories for target libraries.
 @kindex set solib-absolute-prefix
 @kindex set sysroot
 @item set sysroot @var{path}
-Use @var{path} as the system root for the program being debugged.  Any
+Use @var{path} as the system root (or list of system roots) for the
+program being debugged.  Any
 absolute shared library paths will be prefixed with @var{path}; many
 runtime loaders store the absolute paths to the shared library in the
 target program's memory.  When starting processes remotely, and when
@@ -18166,7 +18167,10 @@ to be laid out in the same way that they are on the target, with
 e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
 @var{path}.
 
-If @var{path} starts with the sequence @file{target:} and the target
+Multiple entries may be delimited by the host platform path separator in use.
+
+If @var{path} starts with the sequence @file{target:} (even if the host
+platform path separator is character @file{:}) and the target
 system is remote then @value{GDBN} will retrieve the target binaries
 from the remote system.  This is only supported when using a remote
 target that supports the @code{remote get} command (@pxref{File
@@ -18248,7 +18252,7 @@ location.
 
 @kindex show sysroot
 @item show sysroot
-Display the current executable and shared library prefix.
+Display the current executable and shared library prefix(es).
 
 @kindex set solib-search-path
 @item set solib-search-path @var{path}
diff --git a/gdb/solib.c b/gdb/solib.c
index be31ffd..98af2c0 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -46,6 +46,7 @@
 #include "filesystem.h"
 #include "gdb_bfd.h"
 #include "filestuff.h"
+#include "source.h"
 
 /* Architecture-specific operations.  */
 
@@ -118,9 +119,9 @@ show_solib_search_path (struct ui_file *file, int from_tty,
    is non-NULL, *FD is set to either -1 or an open file handle for
    the binary file.
 
-   Global variable GDB_SYSROOT is used as a prefix directory
+   Parameter SYSROOT is used as a prefix directory
    to search for binary files if they have an absolute path.
-   If GDB_SYSROOT starts with "target:" and target filesystem
+   If SYSROOT starts with "target:" and target filesystem
    is the local filesystem then the "target:" prefix will be
    stripped before the search starts.  This ensures that the
    same search algorithm is used for local files regardless of
@@ -150,14 +151,13 @@ show_solib_search_path (struct ui_file *file, int from_tty,
 */
 
 static char *
-solib_find_1 (char *in_pathname, int *fd, int is_solib)
+solib_find_2 (char *in_pathname, int *fd, int is_solib, const char *sysroot)
 {
   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);
-  const char *sysroot = gdb_sysroot;
   int prefix_len, orig_prefix_len;
 
   /* If the absolute prefix starts with "target:" but the filesystem
@@ -377,6 +377,31 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib)
   return temp_pathname;
 }
 
+/* It is an solib_find_2 wrapper handling multiple directory components
+   of GDB_SYSROOT.  */
+
+static char *
+solib_find_1 (char *in_pathname, int *fd, int is_solib)
+{
+  VEC (char_ptr) *sysroot_vec;
+  struct cleanup *back_to;
+  char *retval, *sysroot;
+  int ix;
+
+  sysroot_vec = dirnames_to_char_ptr_vec_target_exc (gdb_sysroot);
+  back_to = make_cleanup_free_char_ptr_vec (sysroot_vec);
+
+  for (ix = 0; VEC_iterate (char_ptr, sysroot_vec, ix, sysroot); ++ix)
+    {
+      retval = solib_find_2 (in_pathname, fd, is_solib, sysroot);
+      if (retval != NULL)
+	break;
+    }
+
+  do_cleanups (back_to);
+  return retval;
+}
+
 /* Return the full pathname of the main executable, or NULL if not
    found.  The returned pathname is malloc'ed and must be freed by
    the caller.  If FD is non-NULL, *FD is set to either -1 or an open
diff --git a/gdb/source.c b/gdb/source.c
index 0c23b7e..4cd3046 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -702,6 +702,41 @@ is_regular_file (const char *name)
   return S_ISREG (st.st_mode);
 }
 
+/* It is a wrapper of dirnames_to_char_ptr_vec which handles possible
+   TARGET_SYSROOT_PREFIX clash with DIRNAME_SEPARATOR.  */
+
+VEC (char_ptr) *
+dirnames_to_char_ptr_vec_target_exc (const char *string)
+{
+  VEC (char_ptr) *vec = dirnames_to_char_ptr_vec (string);
+  int ix;
+  char *s;
+
+  if (DIRNAME_SEPARATOR == ':')
+    for (ix = 0; ix < VEC_length (char_ptr, vec);)
+      {
+	char *s = VEC_index (char_ptr, vec, ix);
+
+	gdb_assert (strcmp (TARGET_SYSROOT_PREFIX, "target" ":") == 0);
+	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_SYSROOT_PREFIX));
+	else
+	  xfree (VEC_replace (char_ptr, vec, ix,
+			      concat (TARGET_SYSROOT_PREFIX,
+				      VEC_index (char_ptr, vec, ix),
+				      NULL)));
+      }
+
+  return vec;
+}
+
 /* Open a file named STRING, searching path PATH (dir names sep by some char)
    using mode MODE in the calls to open.  You cannot use this function to
    create files (O_CREAT).
diff --git a/gdb/source.h b/gdb/source.h
index 9050357..fd58d8e 100644
--- a/gdb/source.h
+++ b/gdb/source.h
@@ -98,4 +98,7 @@ extern void clear_current_source_symtab_and_line (void);
 
 /* Add a source path substitution rule.  */
 extern void add_substitute_path_rule (char *, char *);
+
+extern VEC (char_ptr) *dirnames_to_char_ptr_vec_target_exc (const char *string);
+
 #endif

  parent reply	other threads:[~2015-08-21 21:21 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-21 21:20 [PATCH v12 00/32] Validate binary before use Jan Kratochvil
2015-08-21 21:20 ` [PATCH v12 05/32] gdbserver build-id attribute generator Jan Kratochvil
2015-08-22  7:17   ` Eli Zaretskii
2015-08-21 21:20 ` [PATCH v12 01/32] Create empty common/linux-maps.[ch] and common/target-utils.[ch] Jan Kratochvil
2015-08-21 21:20 ` [PATCH v12 04/32] Move linux_find_memory_regions_full & co Jan Kratochvil
2015-08-21 21:20 ` [PATCH v12 03/32] Prepare linux_find_memory_regions_full & co. for move Jan Kratochvil
2015-08-21 21:20 ` [PATCH v12 02/32] Move gdb_regex* to common/ Jan Kratochvil
2015-08-21 21:21 ` Jan Kratochvil [this message]
2015-08-22  7:31   ` [PATCH v12 08/32] Permit multiple sysroot directories Eli Zaretskii
2015-08-22 19:24     ` Jan Kratochvil
2015-08-21 21:21 ` [PATCH v12 06/32] Validate symbol file using build-id Jan Kratochvil
2015-08-22  7:23   ` Eli Zaretskii
2015-08-22 19:19     ` Jan Kratochvil
2015-08-21 21:21 ` [PATCH v12 07/32] Code cleanup: Make solib_find_1 variable const Jan Kratochvil
2015-08-21 21:21 ` [PATCH v12 12/32] Code cleanup: Remove openp parameter mode Jan Kratochvil
2015-08-21 21:21 ` [PATCH v12 10/32] Code cleanup: Add enum for openp_flags Jan Kratochvil
2015-08-21 21:21 ` [PATCH v12 11/32] Code cleanup: Remove OPF_RETURN_REALPATH Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 09/32] Change sysroot to ":target:" Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 13/32] Code cleanup: openp parameter filename_opened is never NULL Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 18/32] Refactor openp() to return file_location Jan Kratochvil
2015-08-25 19:07   ` [PATCH v13 " Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 17/32] Add file_location utility functions Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 16/32] gdb_bfd_open_from_target: Optionally do not close fd Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 19/32] solib_find: Make it use file_location Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 20/32] symfile_bfd_open: Make it use openp_bfd() Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 14/32] Provide new gdb_bfd_open_from_target Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 15/32] gdb_bfd_open_from_target: Support real fd Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 24/32] solib_find: Search also by build-id Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 26/32] solib_bfd_open: Optimize opening twice Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 22/32] Add dummy build-id params to prototypes Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 27/32] build_id_verify: Make it more verbose Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 23/32] build_id_to_bfd: Make it return file_location Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 25/32] Verify the build-id Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 21/32] build_id_to_debug_bfd: Make it also non-.debug capable Jan Kratochvil
2015-08-21 21:24 ` [PATCH v12 30/32] Code cleanup: New hex2bin_allocate() Jan Kratochvil
2015-08-21 21:24 ` [PATCH v12 31/32] Make only user-specified executable and symbol filenames sticky Jan Kratochvil
2015-08-21 21:24 ` [PATCH v12 32/32] Support build-id for main executables Jan Kratochvil
2015-08-21 21:24 ` [PATCH v12 28/32] Tests for validate symbol file using build-id Jan Kratochvil
2015-08-21 21:24 ` [PATCH v12 29/32] testcase: Test also locating shlibs by build-id Jan Kratochvil
2015-09-02  3:57 ` [PATCH v12 00/32] Validate binary before use Doug Evans
2015-09-02  7:41   ` Jan Kratochvil
2015-09-02 14:58     ` Doug Evans
2015-09-02 15:14       ` Jan Kratochvil
2015-09-02 15:22         ` Doug Evans
2015-09-02 19:12           ` Jan Kratochvil
2015-09-15  1:37             ` Doug Evans

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150821212111.6673.85003.stgit@host1.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).