2008-04-26 Jan Kratochvil Find sources in parent dirs of non-existing CU current dirs. * defs.h (gdb_trim_dir_parents): New prototype. * utils.c (gdb_trim_dir_parents): New function. * source.c (openp): Call GDB_TRIM_DIR_PARENTS. 2008-04-26 Jan Kratochvil * gdb.base/nodir.exp, gdb.base/nodir.c: New files. --- ./gdb/defs.h 24 Apr 2008 11:13:44 -0000 1.221 +++ ./gdb/defs.h 26 Apr 2008 12:56:19 -0000 @@ -372,6 +372,7 @@ extern void init_page_info (void); extern char *gdb_realpath (const char *); extern char *xfullpath (const char *); +extern void gdb_trim_dir_parents (char *path); extern unsigned long gnu_debuglink_crc32 (unsigned long crc, unsigned char *buf, size_t len); --- ./gdb/source.c 17 Apr 2008 17:43:58 -0000 1.87 +++ ./gdb/source.c 26 Apr 2008 12:56:21 -0000 @@ -773,6 +773,8 @@ openp (const char *path, int opts, const strcat (filename + len, SLASH_STRING); strcat (filename, string); + gdb_trim_dir_parents (filename); + if (is_regular_file (filename)) { fd = open (filename, mode); --- ./gdb/utils.c 24 Apr 2008 11:13:44 -0000 1.187 +++ ./gdb/utils.c 26 Apr 2008 12:56:24 -0000 @@ -2987,6 +2987,35 @@ xfullpath (const char *filename) return result; } +/* Remove any `dir/../' parts as DIR from the CU current directory may not + exist and we still should find the source file in its parent directory. */ + +void +gdb_trim_dir_parents (char *path) +{ + char *src = path; + char *dest = path; + + do + { + if ((dest == path || IS_DIR_SEPARATOR (src[-1])) + && src[0] == '.' && src[1] == '.' + && (IS_DIR_SEPARATOR (src[2]) || src[2] == 0)) + { + while (dest > path && IS_DIR_SEPARATOR (dest[-1])) + dest--; + while (dest > path && !IS_DIR_SEPARATOR (dest[-1])) + dest--; + src = &src[2]; + while (IS_DIR_SEPARATOR (*src)) + src++; + continue; + } + *dest++ = *src++; + } + while (src[-1] != 0); +} + /* This is the 32-bit CRC function used by the GNU separate debug facility. An executable may contain a section named --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ./gdb/testsuite/gdb.base/nodir.c 26 Apr 2008 12:56:24 -0000 @@ -0,0 +1,31 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2008 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + Please email any bugs, comments, and/or additions to this file to: + bug-gdb@prep.ai.mit.edu */ + +void +foo () +{ +} + +int +main () +{ + foo (); /* EXPECTED-STRING */ + return 0; +} --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ./gdb/testsuite/gdb.base/nodir.exp 26 Apr 2008 12:56:24 -0000 @@ -0,0 +1,49 @@ +# Copyright 2005, 2007, 2008 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set srcfile nodir.c +set binfile ${objdir}/${subdir}/nodir +set binfiledir ${objdir}/${subdir}/nodir.d + +file copy -force ${srcdir}/${subdir}/${srcfile} ${objdir}/${subdir}/nodir-tmp.c +file mkdir $binfiledir +set origdir [pwd] +cd ${binfiledir} +set result [gdb_compile "../nodir-tmp.c" "../nodir" executable {debug}] +cd ${origdir} +file delete -force ${binfiledir} + +if { $result != "" } { + untested "Couldn't compile test program" + return -1 +} + +# Get things started. + +gdb_exit +gdb_start +# Intentionally a bogus directory. +gdb_reinitialize_dir /dir-doEs-nOt-exIst +gdb_load ${binfile} + +# For C programs, "start" should stop in main(). +if { [gdb_start_cmd] < 0 } { + untested start + return -1 +} + +gdb_test "" \ + "main \\(\\) at .*nodir-tmp.c.*EXPECTED-STRING.*" \ + "start"