From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16139 invoked by alias); 7 Jul 2006 19:12:11 -0000 Received: (qmail 16007 invoked by uid 22791); 7 Jul 2006 19:12:09 -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 19:12:06 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-nile.gnat.com (Postfix) with ESMTP id CA75948CFC5; Fri, 7 Jul 2006 15:12:04 -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 15983-01-2; Fri, 7 Jul 2006 15:12:04 -0400 (EDT) Received: from takamaka.act-europe.fr (S0106000625ac85e1.vs.shawcable.net [70.71.27.110]) by nile.gnat.com (Postfix) with ESMTP id 384F548CF77; Fri, 7 Jul 2006 15:12:04 -0400 (EDT) Received: by takamaka.act-europe.fr (Postfix, from userid 507) id 437B247EFA; Fri, 7 Jul 2006 12:12:03 -0700 (PDT) Date: Fri, 07 Jul 2006 19:12:00 -0000 From: Joel Brobecker To: Eli Zaretskii Cc: gdb-patches@sources.redhat.com Subject: Re: [RFA] New substitute-path commands Message-ID: <20060707191203.GD971@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> <20060707052219.GA971@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="IrhDeMKUP4DT/M7F" Content-Disposition: inline In-Reply-To: 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/msg00062.txt.bz2 --IrhDeMKUP4DT/M7F Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1391 Hi Eli, > Thanks. My comments are below. Thanks for your review (and also the effort you made in providing a description of what a substitution rule is, much appreciated). I have updated the source as per your comments, as well as reworked the documentation to include your ideas. I also took the time to include a small explaination of how this new functionality differs slightly from the "dir" command. It's not necessary since the explaination can be deduced from the rest of the documentation, but might make it easier to figure this out. 2006-07-07 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. This 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); } --IrhDeMKUP4DT/M7F Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="subst-doc.diff" Content-length: 3744 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 19:02:26 -0000 @@ -5033,6 +5033,40 @@ 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. A @dfn{substitution rule} +specifies how to rewrite source directories stored in the program's +debug information in case the sources were moved to a different +directory between compilation and debugging. @value{GDBN} does a simple +string replacement of the first occurrence of @var{from} with @var{to} +in the directory part of the source file name, and uses the result +instead of the original file name to look up the sources. + +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}. To define a source path +substitution rule, use the @ref{set substitute-path} command. + +In many cases, you can achieve the same result using the @code{directory} +command. However, @code{set substitute-path} can be more efficient in +the case where the sources are organized in a complex tree with multiple +subdirectories. With the @code{directory} command, you need to add each +subdirectory of your project. If you moved the entire tree while +preserving its internal organization, then @code{set substitute-path} +allows you to direct the debugger to all the sources with one single +command. + +However, @code{set substitute-path} is also more than just a shortcut +command. The source path is only used if the file at the original +location no longer exists. On the other hand, @code{set substitute-path} +modifies the debugger behavior to look at the rewritten location +instead. So, if for any reason a source file that is not relevant to +your executable is located at the original location, the substitution +rule is the only method available to point GDB at the new location. + @table @code @item directory @var{dirname} @dots{} @item dir @var{dirname} @dots{} @@ -5068,6 +5102,34 @@ Reset the source path to its default val @item show directories @kindex show directories Print the source path: show which directories it contains. + +@anchor{set substitute-path} +@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. + +For example, if the file @file{/foo/bar/baz.c} was moved to +@file{/mnt/cross/baz.c}, then the command + +@smallexample +(@value{GDBP}) set substitute-path /usr/src /mnt/cross +@end smallexample + +@noindent +will tell @value{GDBN} to replace @samp{/usr/src} with +@samp{/mnt/cross}, which will allow @value{GDBN} to find the file +@file{baz.c} even though it was moved. + +@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 --IrhDeMKUP4DT/M7F--