From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19840 invoked by alias); 7 Jul 2006 05:22:26 -0000 Received: (qmail 19830 invoked by uid 22791); 7 Jul 2006 05:22:25 -0000 X-Spam-Check-By: sourceware.org Received: from nile.gnat.com (HELO nile.gnat.com) (205.232.38.5) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 07 Jul 2006 05:22:23 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-nile.gnat.com (Postfix) with ESMTP id C49D348CEEB for ; Fri, 7 Jul 2006 01:22:20 -0400 (EDT) Received: from nile.gnat.com ([127.0.0.1]) by localhost (nile.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 20582-01 for ; Fri, 7 Jul 2006 01:22:20 -0400 (EDT) Received: from takamaka.act-europe.fr (S0106000625ac85e1.vs.shawcable.net [70.71.27.110]) by nile.gnat.com (Postfix) with ESMTP id 0969D48CEF7 for ; Fri, 7 Jul 2006 01:22:19 -0400 (EDT) Received: by takamaka.act-europe.fr (Postfix, from userid 507) id 3D26647EFA; Thu, 6 Jul 2006 22:22:19 -0700 (PDT) Date: Fri, 07 Jul 2006 05:22:00 -0000 From: Joel Brobecker To: gdb-patches@sources.redhat.com Subject: Re: [RFA] New substitute-path commands Message-ID: <20060707052219.GA971@adacore.com> References: <20060705215606.GF3580@adacore.com> <20060705230129.GA1145@nevyn.them.org> <20060706044733.GC673@adacore.com> <1152198199.6282.63.camel@dufur.beaverton.ibm.com> <20060706162952.GB24631@nevyn.them.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="SLDf9lqlvOQaIe6s" Content-Disposition: inline In-Reply-To: <20060706162952.GB24631@nevyn.them.org> User-Agent: Mutt/1.4i 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: 2006-07/txt/msg00049.txt.bz2 --SLDf9lqlvOQaIe6s Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1007 Hello, Here is a second take at this new functionality, updated as suggested: > set substitute-path FROM TO > > [We can make it use buildargv for uniform quoting of TO and FROM. > I'd recommend that.] > > unset substitute-path FROM > > show substitute-path Added bonus, I included a documentation patch for review. 2006-07-06 Joel Brobecker = 0) return result; @@ -869,6 +929,27 @@ find_and_open_source (struct objfile *ob if (dirname != NULL) { + /* If necessary, rewrite the compilation directory name according + to the source path substitution rules specified by the user. + + Normally, we should really try to do the rewrite on the entire + path as opposed to just the directory name, but that's making + things much more complicated since we now have to concat the + dirname and filename, apply the substitution rule, and then do + [...] ??? How do we split the path back into dirname and filename? + In practice, the source path substitution feature should be used + when the entire tree has been moved, in which case only the root + part of the tree path will need to be rewritten. So this should + not be a problem in practice. */ + + char *rewritten_dirname = xrewrite_source_path (dirname); + + if (rewritten_dirname != NULL) + { + make_cleanup (xfree, rewritten_dirname); + dirname = rewritten_dirname; + } + /* Replace a path entry of $cdir with the compilation directory name */ #define cdir_len 5 /* We cast strstr's result in case an ANSIhole has made it const, @@ -1587,6 +1668,65 @@ reverse_search_command (char *regex, int fclose (stream); return; } + +/* Print the current source path substitution rule. */ + +static void +show_substitute_path_command (char *args, int from_tty) +{ + if (substitute_path_from == NULL) + printf_filtered (_("No source path substitution rule specified.\n")); + else + printf_filtered (_("`%s' in source paths now substituted with `%s'.\n"), + substitute_path_from, substitute_path_to); +} + +/* Delete the current source path substitution rule. */ + +static void +unset_substitute_path_command (char *args, int from_tty) +{ + if (substitute_path_from != NULL) + { + xfree (substitute_path_from); + substitute_path_from = NULL; + } + + if (substitute_path_to != NULL) + { + xfree (substitute_path_to); + substitute_path_to = NULL; + } +} + +/* Add a new source path substitution rule. */ + +static void +set_substitute_path_command (char *args, int from_tty) +{ + char *from_path, *to_path; + char **argv = buildargv (args); + + if (argv == NULL || argv[0] == NULL || argv [1] == NULL) + error (_("Incorrect usage, too few arguments in command")); + + if (argv[2] != NULL) + error (_("Incorrect usage, too many arguments in command")); + + /* Remove any previous substitution rule. */ + + unset_substitute_path_command (NULL, from_tty); + + /* Insert the new substitution rule, and print a confirmation message + to the user. */ + + substitute_path_from = xstrdup (argv[0]); + substitute_path_to = xstrdup (argv[1]); + freeargv (argv); + + show_substitute_path_command (NULL, from_tty); +} + void _initialize_source (void) @@ -1666,4 +1806,19 @@ Show number of source lines gdb will lis NULL, show_lines_to_list, &setlist, &showlist); + + add_cmd ("substitute-path", class_files, set_substitute_path_command, + _("\ +Add a source path substitution rule. If a substitution rule was previously\n\ +set, it is overridden."), &setlist); + + add_cmd ("substitute-path", class_files, unset_substitute_path_command, + _("\ +Remove the current source path substitution rule. Has no effect\n\ +if no path substitution rule was previously specified."), + &unsetlist); + + add_cmd ("substitute-path", class_files, show_substitute_path_command, + _("Show the current source path substitution rule."), + &showlist); } --SLDf9lqlvOQaIe6s Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="subst-doc.diff" Content-length: 2302 Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.340 diff -u -p -r1.340 gdb.texinfo --- doc/gdb.texinfo 21 Jun 2006 13:57:21 -0000 1.340 +++ doc/gdb.texinfo 7 Jul 2006 04:51:00 -0000 @@ -5033,6 +5033,23 @@ To add other directories, use the @code{ 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). +In addition to the source path, @value{GDBN} provides a set of commands +that manage a source path substitution rule. Instead of attempting to +locate the source file using the original source path as described above, +it will first apply the substitution rule to that source path, and use +the resulting path instead. By default, there is no substitution rule +defined, but this can be very useful in the case when your source tree +has been moved to a different location from the one where the sources +were compiled. To define a source path substitution rule, use the +@code{set substitute-path} command. + +Using the previous example, suppose the @file{foo-1.0} tree has been +moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell +GDB to replace @file{/usr/src} in all source path names with +@file{/mnt/cross}. The first lookup will then be +@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location +of @file{/usr/src/foo-1.0/lib/foo.c}. + @table @code @item directory @var{dirname} @dots{} @item dir @var{dirname} @dots{} @@ -5068,6 +5085,21 @@ Reset the source path to its default val @item show directories @kindex show directories Print the source path: show which directories it contains. + +@item set substitute-path @var{FROM} @var{TO} +@kindex set substitute-path +Define a source path substitution rule. The new substitution rule +replaces any rule previously defined. + +@item unset substitute-path +@kindex unset substitute-path +If a source path substitution rule is active, then cancel it. +This command has no effect otherwise. + +@item show substitute-path +@kindex show substitute-path +Print the source path substitution rule if defined. + @end table If your source path is cluttered with directories that are no longer of --SLDf9lqlvOQaIe6s--