From patchwork Mon Nov 5 21:19:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 30029 Received: (qmail 87018 invoked by alias); 5 Nov 2018 21:19:57 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 87005 invoked by uid 89); 5 Nov 2018 21:19:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Keith, keith, symlinked, symlinks X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Nov 2018 21:19:54 +0000 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 64E2780F91 for ; Mon, 5 Nov 2018 21:19:53 +0000 (UTC) Received: from theo.uglyboxes.com.com (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B7B510027CE for ; Mon, 5 Nov 2018 21:19:53 +0000 (UTC) From: Keith Seitz To: gdb-patches@sourceware.org Subject: [PATCH] Fix symtab/23853: symlinked default symtab Date: Mon, 5 Nov 2018 13:19:51 -0800 Message-Id: <20181105211951.14945-1-keiths@redhat.com> X-IsSubscribed: yes 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 . */ 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 + + 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 * 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 + + PR symtab/23853 + * gdb.base/symlink-sourcefile.c: New file. + * gdb.base/symlink-sourcefile.exp: New file. + 2018-11-01 Joel Brobecker * 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 . */ + +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 . + +# 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"