This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix symtab/23853: symlinked default symtab


This patch attempts to fix a bug dealing with setting breakpoints
in default symtabs that are symlinks.  For example:

(gdb) list
11	   GNU General Public License for more details.
12
13	   You should have received a copy of the GNU General Public License
14	   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
15
16	static int
17	foo (void)
18	{
19	  return 0; /* break here  */
20	}
(gdb)
21
22	int
23	main (void)
24	{
25	  return foo ();
26	}
(gdb) b 19
No line 19 in the current file.
Make breakpoint pending on future shared library load? (y or [n])

The problem here is that when convert_sals_line_offset sets the default
symtab, it immediately calls symtab_to_fullname, passing that fullname
to collect_symtabs_from_filename.

When we iterate over the compunit_symtabs in iterate_over_some_symtabs,
NAME is this the fullname from symtab_to_fullname while the symtab
filename is the symlink name (gotten from debuginfo).
compare_filenames_for_search is then called to ascertain a match between,
e.g., "symlink.c" and "/path/to/realsource.c".
The first comparison fails (compare_filenames_for_search returns early
with a simple strlen comparison).

Later in iterate_over_some_symtabs, symtab_to_fullname would be called
with the result of symtab_to_fullname, but only if the user has set
"basenames-may-differ."  This flag defaults to "off" because, as
iterate_over_some_symtabs says, realpath is very expensive to use.

However, there seems little reason not to check the fullname if it is
already known (non-NULL).  That's what this patch does.

gdb/ChangeLog

	PR symtab/23853
	* symtab.c (iterate_over_some_symtabs): If the symtab has a
	fullname, check whether it is a filename match, too.

gdb/testsuite/ChangeLog

	PR symtab/23853
	* gdb.base/symlink-sourcefile.c: New file.
	* gdb.base/symlink-sourcefile.exp: New file.
---
 gdb/ChangeLog                                 |  6 +++
 gdb/symtab.c                                  |  4 +-
 gdb/testsuite/ChangeLog                       |  6 +++
 gdb/testsuite/gdb.base/symlink-sourcefile.c   | 26 +++++++++++
 gdb/testsuite/gdb.base/symlink-sourcefile.exp | 44 +++++++++++++++++++
 5 files changed, 85 insertions(+), 1 deletion(-)
 create mode 100644 gdb/testsuite/gdb.base/symlink-sourcefile.c
 create mode 100644 gdb/testsuite/gdb.base/symlink-sourcefile.exp

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index bc77fe85c7..557c72b203 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+YYYY-MM-DD  Keith Seitz  <keiths@redhat.com>
+
+	PR symtab/23853
+	* symtab.c (iterate_over_some_symtabs): If the symtab has a
+	fullname, check whether it is a filename match, too.
+
 2018-11-04  Tom Tromey  <tom@tromey.com>
 
 	* varobj.c (install_default_visualizer): Update.
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 7649908d9c..5b39db6d33 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -412,7 +412,9 @@ iterate_over_some_symtabs (const char *name,
     {
       ALL_COMPUNIT_FILETABS (cust, s)
 	{
-	  if (compare_filenames_for_search (s->filename, name))
+	  if (compare_filenames_for_search (s->filename, name)
+	      || (s->fullname != nullptr
+		  && compare_filenames_for_search (s->fullname, name)))
 	    {
 	      if (callback (s))
 		return true;
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 0df75aa54f..4befa4f4c9 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+YYYY-MM-DD  Keith Seitz  <keiths@redhat.com>
+
+	PR symtab/23853
+	* gdb.base/symlink-sourcefile.c: New file.
+	* gdb.base/symlink-sourcefile.exp: New file.
+
 2018-11-01  Joel Brobecker  <brobecker@adacore.com>
 
 	* gdb.ada/watch_minus_l: New testcase.
diff --git a/gdb/testsuite/gdb.base/symlink-sourcefile.c b/gdb/testsuite/gdb.base/symlink-sourcefile.c
new file mode 100644
index 0000000000..2cf0d0e2fe
--- /dev/null
+++ b/gdb/testsuite/gdb.base/symlink-sourcefile.c
@@ -0,0 +1,26 @@
+/* Copyright 2018 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/>.  */
+
+static int
+foo (void)
+{
+  return 0; /* break here  */
+}
+
+int
+main (void)
+{
+  return foo ();
+}
diff --git a/gdb/testsuite/gdb.base/symlink-sourcefile.exp b/gdb/testsuite/gdb.base/symlink-sourcefile.exp
new file mode 100644
index 0000000000..084be07151
--- /dev/null
+++ b/gdb/testsuite/gdb.base/symlink-sourcefile.exp
@@ -0,0 +1,44 @@
+# Copyright 2018 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/>.
+
+# Test GDB when source files are symlinks.
+standard_testfile
+
+set test "file symbolic link name"
+set linksrc "link-${srcfile}"
+set srcfilelink [standard_output_file $linksrc]
+
+
+# Remove any existing symlink and build executable using the
+# symlink.
+remote_file host delete $srcfilelink
+set status [remote_exec host \
+		"ln -sf $srcdir/$subdir/$srcfile $srcfilelink"]
+if {[lindex $status 0] != 0} {
+    unsupported "$test (host does not support symbolic links)"
+    return 0
+}
+
+if {[prepare_for_testing $testfile $testfile $srcfilelink]} {
+    return -1
+}
+
+if {![runto_main]} {
+    untested "could not run to main"
+    return -1
+}
+
+gdb_breakpoint [gdb_get_line_number "break here" $srcfile] message
+gdb_continue_to_breakpoint "run to breakpoint marker"
-- 
2.17.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]