This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patch] Parent dirs of non-existing CU current dirs
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Sat, 26 Apr 2008 15:15:56 +0200
- Subject: [patch] Parent dirs of non-existing CU current dirs
Hi,
(gdb) up
#1 0x00007f79042e1ee4 in PR_WaitCondVar (cvar=0x14196f0, timeout=4294967295)
at ../../../mozilla/nsprpub/pr/src/pthreads/ptsynch.c:405
405 ../../../mozilla/nsprpub/pr/src/pthreads/ptsynch.c: No such file or directory.
in ../../../mozilla/nsprpub/pr/src/pthreads/ptsynch.c
/usr/lib/debug/lib64/libnspr4.so.debug
<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
<11> DW_AT_name : (indirect string, offset: 0x7d): ../.././mozilla/nsprpub/pr/src/prvrsion.c
<15> DW_AT_comp_dir : (indirect string, offset: 0x14c): /usr/src/debug/nspr-4.7.0.99.2/pr/src
ls: cannot access /usr/src/debug/nspr-4.7.0.99.2/pr/src/../.././mozilla/nsprpub/pr/src/prvrsion.c: No such file or directory
ls: cannot access /usr/src/debug/nspr-4.7.0.99.2/pr/src: No such file or directory
-rw-r--r-- 1 root root 4715 2004-04-25 11:00 /usr/src/debug/nspr-4.7.0.99.2/./mozilla/nsprpub/pr/src/prvrsion.c
-rw-r--r-- 1 root root 4715 2004-04-25 11:00 /usr/src/debug/nspr-4.7.0.99.2/mozilla/nsprpub/pr/src/prvrsion.c
We should not insist the current directory of CU exists as it may be omitted if
it would be empty. The other opinion may be there is a bug in the debuginfo
generator and the empty directories should still exist there. One may also
normalize the directories listed in the debuginfo files.
No regressions on x86_64-fedora-9.
Regards,
Jan
2008-04-26 Jan Kratochvil <jan.kratochvil@redhat.com>
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 <jan.kratochvil@redhat.com>
* 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 <http://www.gnu.org/licenses/>.
+
+ 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 <http://www.gnu.org/licenses/>.
+
+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"