Index: gdb/source.c =================================================================== RCS file: /cvs/src/src/gdb/source.c,v retrieving revision 1.70 diff -u -r1.70 source.c --- gdb/source.c 29 Aug 2005 12:57:49 -0000 1.70 +++ gdb/source.c 10 Oct 2005 03:53:53 -0000 @@ -831,6 +831,7 @@ char **fullname) { char *path = source_path; + char *file = filename; const char *p; int result; @@ -847,31 +848,45 @@ if (dirname != NULL) { - /* Replace a path entry of $cdir with the compilation directory name */ + if (IS_ABSOLUTE_PATH(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, - which produces a "required warning" when assigned to a nonconst. */ - p = (char *) strstr (source_path, "$cdir"); - if (p && (p == path || p[-1] == DIRNAME_SEPARATOR) - && (p[cdir_len] == DIRNAME_SEPARATOR || p[cdir_len] == '\0')) - { - int len; - - path = (char *) - alloca (strlen (source_path) + 1 + strlen (dirname) + 1); - len = p - source_path; - strncpy (path, source_path, len); /* Before $cdir */ - strcpy (path + len, dirname); /* new stuff */ - strcat (path + len, source_path + len + cdir_len); /* After $cdir */ - } + /* We cast strstr's result in case an ANSIhole has made it const, + which produces a "required warning" when assigned to a nonconst. */ + p = (char *) strstr (source_path, "$cdir"); + if (p && (p == path || p[-1] == DIRNAME_SEPARATOR) + && (p[cdir_len] == DIRNAME_SEPARATOR || p[cdir_len] == '\0')) + { + int len; + + path = (char *) + alloca (strlen (source_path) + 1 + strlen (dirname) + 1); + len = p - source_path; + strncpy (path, source_path, len); /* Before $cdir */ + strcpy (path + len, dirname); /* new stuff */ + strcat (path + len, source_path + len + cdir_len); /* After $cdir */ + } + } + else + { + /* Use the concatenation of dirname and filename if dirname isn't absolute */ + file = (char *) + alloca (strlen (dirname) + strlen (SLASH_STRING) + + strlen (filename) + 1); + + strcpy(file, dirname); + strcat(file, SLASH_STRING); + strcat(file, filename); + } } - result = openp (path, OPF_SEARCH_IN_PATH, filename, OPEN_MODE, 0, fullname); + result = openp (path, OPF_SEARCH_IN_PATH, file, OPEN_MODE, 0, fullname); if (result < 0) { /* Didn't work. Try using just the basename. */ - p = lbasename (filename); - if (p != filename) + p = lbasename (file); + if (p != file) result = openp (path, OPF_SEARCH_IN_PATH, p, OPEN_MODE, 0, fullname); }