From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31647 invoked by alias); 16 Nov 2005 17:09:39 -0000 Received: (qmail 31628 invoked by uid 22791); 16 Nov 2005 17:09:35 -0000 Received: from fra-del-02.spheriq.net (HELO fra-del-02.spheriq.net) (195.46.51.98) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Wed, 16 Nov 2005 17:09:34 +0000 Received: from fra-out-03.spheriq.net (fra-out-03.spheriq.net [195.46.51.131]) by fra-del-02.spheriq.net with ESMTP id jAGH9T7r006266 for ; Wed, 16 Nov 2005 17:09:29 GMT Received: from fra-cus-02.spheriq.net (fra-cus-02.spheriq.net [195.46.51.38]) by fra-out-03.spheriq.net with ESMTP id jAGH9TCt012999 for ; Wed, 16 Nov 2005 17:09:29 GMT Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by fra-cus-02.spheriq.net with ESMTP id jAGH9CDx031742 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK) for ; Wed, 16 Nov 2005 17:09:21 GMT Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 40F81DA41 for ; Wed, 16 Nov 2005 17:09:12 +0000 (GMT) Received: by zeta.dmz-eu.st.com (STMicroelectronics, from userid 60012) id 58A35474A3; Wed, 16 Nov 2005 17:12:07 +0000 (GMT) Received: from zeta.dmz-eu.st.com (localhost [127.0.0.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id EB89D75969 for ; Wed, 16 Nov 2005 17:12:06 +0000 (UTC) Received: from mail1.bri.st.com (mail1.bri.st.com [164.129.8.218]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 52C2E474EB for ; Wed, 16 Nov 2005 17:12:06 +0000 (GMT) Received: from [164.129.15.13] (terrorhawk.bri.st.com [164.129.15.13]) by mail1.bri.st.com (MOS 3.5.8-GR) with ESMTP id CGZ39047 (AUTH "andrew stubbs"); Wed, 16 Nov 2005 17:09:06 GMT Message-ID: <437B6718.7070300@st.com> Date: Wed, 16 Nov 2005 19:36:00 -0000 From: Andrew STUBBS User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) MIME-Version: 1.0 To: gdb-patches@sources.redhat.com Subject: [PATCH] Use search path for scripts Content-Type: multipart/mixed; boundary="------------070902060904000101030301" X-O-Spoofed: Not Scanned X-O-General-Status: No X-O-Spam1-Status: Not Scanned X-O-Spam2-Status: Not Scanned X-O-URL-Status: Not Scanned X-O-Virus1-Status: No X-O-Virus2-Status: Not Scanned X-O-Virus3-Status: No X-O-Virus4-Status: No X-O-Virus5-Status: Not Scanned X-O-Image-Status: Not Scanned X-O-Attach-Status: Not Scanned X-SpheriQ-Ver: 4.1.07 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2005-11/txt/msg00240.txt.bz2 This is a multi-part message in MIME format. --------------070902060904000101030301 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 959 Hi all, This is my last new patch for a while, I promise! This patch adjusts the source command such that it uses the search path (normally used to find sources) to find scripts. This allows script files to be placed in a standard place and/or allow them to source one-another without knowing an absolute path. We use this mechanism to load all out target configuration routines from a toolchain installation. The search strategy employed is the one we have found most useful. If the path contains '/' then search relative to current directory first, otherwise search the path first. This way users do not get a nasty surprise if they happen to have a script with a similar name to a standard one (perhaps sourced indirectly). They can use ./ if they really want a local file. If it were the other way around then the standard scripts would not work as intended and users would need to find an absolute path to use them by hand. Andrew Stubbs --------------070902060904000101030301 Content-Type: text/plain; name="search-path.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="search-path.patch" Content-length: 3738 2005-11-16 Andrew Stubbs * cli-cmds.c: Include fcntl.h. (source_command): Use the GDB search path to find script files. doc/ * gdb.texinfo (Choosing files): Mention that -directory is used for script files. (Specifying source directories): Likewise. (Command files): Explain how script files are found. Index: src/gdb/cli/cli-cmds.c =================================================================== --- src.orig/gdb/cli/cli-cmds.c 2005-11-14 17:37:07.000000000 +0000 +++ src/gdb/cli/cli-cmds.c 2005-11-14 17:39:24.000000000 +0000 @@ -50,6 +50,8 @@ #include "tui/tui.h" /* For tui_active et.al. */ #endif +#include + /* Prototypes for local command functions */ static void complete_command (char *, int); @@ -433,6 +435,8 @@ source_command (char *args, int from_tty char *file = args; char *minusv=NULL; int old_source_verbose = source_verbose; + char *full_pathname = NULL; + int fd; /* -v causes the source command to run in verbose mode. We still have to be able to handle filenames with spaces. */ @@ -486,8 +490,21 @@ source_command (char *args, int from_tty file = tilde_expand (file); old_cleanups = make_cleanup (xfree, file); - stream = fopen (file, FOPEN_RT); - if (!stream) + /* Search for and open 'file' on the search path used for source + files. Put the full location in 'full_pathname'. */ + /* Search the current directory first if the filename has a directory + separtor in it - it might be a relative path. */ + fd = openp (source_path, + strchr (file, '/') != NULL ? OPF_TRY_CWD_FIRST : 0, + file, O_RDONLY, 0, &full_pathname); + + /* Use the full path name, if it is found. */ + if (full_pathname != NULL && fd != -1) + { + file = full_pathname; + } + + if (fd == -1) { source_verbose = old_source_verbose; if (from_tty) @@ -496,6 +513,7 @@ source_command (char *args, int from_tty return; } + stream = fdopen (fd, "r"); script_from_file (stream, file); do_cleanups (old_cleanups); Index: src/gdb/doc/gdb.texinfo =================================================================== --- src.orig/gdb/doc/gdb.texinfo 2005-11-14 17:37:07.000000000 +0000 +++ src/gdb/doc/gdb.texinfo 2005-11-14 17:39:24.000000000 +0000 @@ -951,7 +951,7 @@ also be interleaved with @samp{-command} @itemx -d @var{directory} @cindex @code{--directory} @cindex @code{-d} -Add @var{directory} to the path to search for source files. +Add @var{directory} to the path to search for source and script files. @item -r @itemx -readnow @@ -4824,6 +4824,9 @@ When you start @value{GDBN}, its source and @samp{cwd}, in that order. To add other directories, use the @code{directory} command. +The search path is used to find both program source files and @value{GDBN} +script files (read using the @samp{-command} option and @samp{source} command). + @table @code @item directory @var{dirname} @dots{} @item dir @var{dirname} @dots{} @@ -15991,6 +15994,11 @@ The lines in a command file are executed printed as they are executed. An error in any command terminates execution of the command file and control is returned to the console. +@value{GDBN} searches for @var{filename} on the search path (specified with the +@samp{directory} command), unless @var{filename} is specified with a relative +path, in which case it searches the current directory first, and then the +search path. Absolute paths are not affected by the search path. + If @code{-v}, for verbose mode, is given then then each command will be displayed as it is executed. The option may be given before or after @var{filename}, but will be interpreted as part of the filename anywhere else. --------------070902060904000101030301--