From patchwork Fri Aug 21 21:21:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 8356 Received: (qmail 105268 invoked by alias); 21 Aug 2015 21:21:18 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 105198 invoked by uid 89); 21 Aug 2015 21:21:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL, BAYES_05, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 21 Aug 2015 21:21:15 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 703E74C67C for ; Fri, 21 Aug 2015 21:21:13 +0000 (UTC) Received: from host1.jankratochvil.net (ovpn-116-22.ams2.redhat.com [10.36.116.22]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7LLLBOU018926 for ; Fri, 21 Aug 2015 17:21:12 -0400 Subject: [PATCH v12 08/32] Permit multiple sysroot directories From: Jan Kratochvil To: gdb-patches@sourceware.org Date: Fri, 21 Aug 2015 23:21:11 +0200 Message-ID: <20150821212111.6673.85003.stgit@host1.jankratochvil.net> In-Reply-To: <20150821212006.6673.35100.stgit@host1.jankratochvil.net> References: <20150821212006.6673.35100.stgit@host1.jankratochvil.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes 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 * 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 * 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