Index: gdb/Makefile.in =================================================================== RCS file: /cvs/src/src/gdb/Makefile.in,v retrieving revision 1.1018 diff -u -p -r1.1018 Makefile.in --- gdb/Makefile.in 9 May 2008 17:02:01 -0000 1.1018 +++ gdb/Makefile.in 13 May 2008 17:59:11 -0000 @@ -1998,7 +1998,7 @@ buildsym.o: buildsym.c $(defs_h) $(bfd_h $(complaints_h) $(gdb_string_h) $(expression_h) $(bcache_h) \ $(filenames_h) $(macrotab_h) $(demangle_h) $(block_h) \ $(cp_support_h) $(dictionary_h) $(buildsym_h) $(stabsread_h) \ - $(addrmap_h) + $(addrmap_h) $(source_h) c-exp.o: c-exp.c $(defs_h) $(gdb_string_h) $(expression_h) $(value_h) \ $(parser_defs_h) $(language_h) $(c_lang_h) $(bfd_h) $(symfile_h) \ $(objfiles_h) $(charset_h) $(block_h) $(cp_support_h) $(dfp_h) Index: gdb/buildsym.c =================================================================== RCS file: /cvs/src/src/gdb/buildsym.c,v retrieving revision 1.60 diff -u -p -r1.60 buildsym.c --- gdb/buildsym.c 17 Apr 2008 17:54:04 -0000 1.60 +++ gdb/buildsym.c 13 May 2008 17:59:11 -0000 @@ -44,6 +44,7 @@ #include "cp-support.h" #include "dictionary.h" #include "addrmap.h" +#include "source.h" /* Ask buildsym.h to define the vars it normally declares `extern'. */ #define EXTERN @@ -583,6 +584,24 @@ void start_subfile (char *name, char *dirname) { struct subfile *subfile; + char *rwname = NULL; + char *rwdirname = NULL; + + if (substitute_path_at_source) + { + rwname = rewrite_source_path (name); + rwdirname = rewrite_source_path (dirname); + } + + if (rwname == NULL) + rwname = name; + else + make_cleanup (xfree, rwname); + if (rwdirname == NULL) + rwdirname = dirname; + else + make_cleanup (xfree, rwdirname); + /* See if this subfile is already known as a subfile of the current main source file. */ @@ -593,7 +612,7 @@ start_subfile (char *name, char *dirname /* If NAME is an absolute path, and this subfile is not, then attempt to create an absolute path to compare. */ - if (IS_ABSOLUTE_PATH (name) + if (IS_ABSOLUTE_PATH (rwname) && !IS_ABSOLUTE_PATH (subfile->name) && subfile->dirname != NULL) subfile_name = concat (subfile->dirname, SLASH_STRING, @@ -601,7 +620,7 @@ start_subfile (char *name, char *dirname else subfile_name = subfile->name; - if (FILENAME_CMP (subfile_name, name) == 0) + if (FILENAME_CMP (subfile_name, rwname) == 0) { current_subfile = subfile; if (subfile_name != subfile->name) @@ -623,9 +642,10 @@ start_subfile (char *name, char *dirname current_subfile = subfile; /* Save its name and compilation directory name */ - subfile->name = (name == NULL) ? NULL : savestring (name, strlen (name)); + subfile->name = + (rwname == NULL) ? NULL : savestring (rwname, strlen (rwname)); subfile->dirname = - (dirname == NULL) ? NULL : savestring (dirname, strlen (dirname)); + (rwdirname == NULL) ? NULL : savestring (rwdirname, strlen (rwdirname)); /* Initialize line-number recording for this subfile. */ subfile->line_vector = NULL; Index: gdb/source.c =================================================================== RCS file: /cvs/src/src/gdb/source.c,v retrieving revision 1.88 diff -u -p -r1.88 source.c --- gdb/source.c 3 May 2008 06:13:21 -0000 1.88 +++ gdb/source.c 13 May 2008 17:59:12 -0000 @@ -91,6 +91,8 @@ static struct symtab *current_source_sym static int current_source_line; +int substitute_path_at_source = 0; + /* Default number of lines to print with commands like "list". This is based on guessing how many long (i.e. more than chars_per_line characters) lines there will be. To be completely correct, "list" @@ -895,7 +897,7 @@ get_substitute_path_rule (const char *pa Return NULL if no substitution rule was specified by the user, or if no rule applied to the given PATH. */ -static char * +char * rewrite_source_path (const char *path) { const struct substitute_path_rule *rule = get_substitute_path_rule (path); @@ -2027,4 +2029,12 @@ Usage: show substitute-path [FROM]\n\ Print the rule for substituting FROM in source file names. If FROM\n\ is not specified, print all substitution rules."), &showlist); + + add_setshow_zinteger_cmd ("substitute-path-at-source", class_files, + &substitute_path_at_source, _("\ +Activate path substitution rule at source."), _("\ +Show path substitution rule at source."), _("\ +When set, paths loaded from debug info will be rewritten before\n\ +being used in GDB."), + NULL, NULL, &setlist, &showlist); } Index: gdb/source.h =================================================================== RCS file: /cvs/src/src/gdb/source.h,v retrieving revision 1.9 diff -u -p -r1.9 source.h --- gdb/source.h 1 Jan 2008 22:53:13 -0000 1.9 +++ gdb/source.h 13 May 2008 17:59:12 -0000 @@ -66,4 +66,9 @@ extern struct symtab_and_line set_curren /* Reset any information stored about a default file and line to print. */ extern void clear_current_source_symtab_and_line (void); + +extern char *rewrite_source_path (const char *path); + +extern int substitute_path_at_source; + #endif Index: gdb/symfile.c =================================================================== RCS file: /cvs/src/src/gdb/symfile.c,v retrieving revision 1.203 diff -u -p -r1.203 symfile.c --- gdb/symfile.c 5 May 2008 16:13:49 -0000 1.203 +++ gdb/symfile.c 13 May 2008 17:59:13 -0000 @@ -3072,13 +3072,22 @@ start_psymtab_common (struct objfile *ob struct partial_symbol **static_syms) { struct partial_symtab *psymtab; + char *rwfilename = NULL; - psymtab = allocate_psymtab (filename, objfile); + if (substitute_path_at_source) + rwfilename = rewrite_source_path (filename); + + if (rwfilename == NULL) + rwfilename = filename; + + psymtab = allocate_psymtab (rwfilename, objfile); psymtab->section_offsets = section_offsets; psymtab->textlow = textlow; psymtab->texthigh = psymtab->textlow; /* default */ psymtab->globals_offset = global_syms - objfile->global_psymbols.list; psymtab->statics_offset = static_syms - objfile->static_psymbols.list; + if (rwfilename != filename) + xfree (rwfilename); return (psymtab); }