Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Doug Gilmore <Doug.Gilmore@imgtec.com>
To: Simon Marchi <simon.marchi@polymtl.ca>,
	"Maciej W. Rozycki"	<macro@imgtec.com>
Cc: Luis Machado <lgustavo@codesourcery.com>, <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Fix PR 21337 (v4): segfault when re-reading symbols with remote debugging.
Date: Tue, 27 Jun 2017 17:29:00 -0000	[thread overview]
Message-ID: <3abdfadd-9ec1-0f2c-45ed-de2184340320@imgtec.com> (raw)
In-Reply-To: <1314dbb1177c39791e5f7a5d51c13089@polymtl.ca>

On 06/25/2017 04:24 AM, Simon Marchi wrote:
> Hi Doug,
> 
> Good thing you pinged, I had completely missed it, sorry for the wait.
> 
> +gdb_test "source $gdbfile" ".*source-command-completed.*" \
> +    "source $testfile.gdb"
> +# Sometimes the failure only occurs on the second invocation.
> +gdb_test "source $gdbfile" ".*source-command-completed.*" \
> +    "source $testfile.gdb"
> 
> Tests should have unique names, so that when one fails, you know easily which one.  So, perhaps "source $testfile.gdb 1" and "source $testfile.gdb 2"?
> 
> The patch is ok with this fixed.
> 
> Thanks,
> 
> Simon
Hi Simon and Maciej,

Simon: I updated the tests per your request.  When I asked Maciej to
commit the patch for me, he noticed that the comment extended over the
soft 72 column limit of, so I reformatted it.  Also I corrected a typo
and format issues in the changelog entries that he noticed.

Thanks,

Doug

Fix PR 21337: segfault when re-reading symbols.

Fix issue exposed by commit 3e29f34.

The basic issue is that section data referenced through an objfile
pointer can also be referenced via the program-space data pointer,
although via a separate mapping mechanism, which is set up by
update_section_map.  Thus once section data attached to an objfile
pointer is released, the section map associated with the program-space
data pointer must be marked dirty to ensure that update_section_map is
called to prevent stale data being referenced.  For the matter at hand
this marking is being done via a call to objfiles_changed.

Before commit 3e29f34 objfiles_changed could be called after all of
the objfile pointers were processed in reread_symbols since section
data references via the program-space data pointer would not occur in
the calls of read_symbols performed by reread_symbols.

With commit 3e29f34 MIPS target specific calls to find_pc_section were
added to the code for DWARF information processing, which is called
via read_symbols.  Thus in reread_symbols the call to objfiles_changed
needs to be called before calling read_symbols, otherwise stale
section data can be referenced.

Thanks to Luis Machado for providing text for the main comment
associated with the change.

gdb/
2017-??-??  Doug Gilmore  <Doug.Gilmore@imgtec.com>
    PR gdb/21337.
    * symfile.c (reread_symbols): Call objfiles_changed just before
    read_symbols.

gdb/testsuite
2017-??-??  Doug Gilmore  <Doug.Gilmore@imgtec.com>
    PR gdb/21337
    * gdb.base/reread-readsym.exp: New file.
    * gdb.base/reread-readsym.c: New file.

diff --git a/gdb/symfile.c b/gdb/symfile.c
index aa53415..ce37390 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2587,6 +2587,9 @@ reread_symbols (void)
 	  /* Free the obstacks for non-reusable objfiles.  */
 	  psymbol_bcache_free (objfile->psymbol_cache);
 	  objfile->psymbol_cache = psymbol_bcache_init ();
+
+	  /* NB: after this call to obstack_free, objfiles_changed
+	     will need to be called (see discussion below).  */
 	  obstack_free (&objfile->objfile_obstack, 0);
 	  objfile->sections = NULL;
 	  objfile->compunit_symtabs = NULL;
@@ -2639,6 +2642,23 @@ reread_symbols (void)
 	  clear_complaints (&symfile_complaints, 1, 1);
 
 	  objfile->flags &= ~OBJF_PSYMTABS_READ;
+
+	  /* We are about to read new symbols and potentially also
+	     DWARF information.  Some targets may want to pass addresses
+	     read from DWARF DIE's through an adjustment function before
+	     saving them, like MIPS, which may call into
+	     "find_pc_section".  When called, that function will make
+	     use of per-objfile program space data.
+
+	     Since we discarded our section information above, we have
+	     dangling pointers in the per-objfile program space data
+	     structure.  Force GDB to update the section mapping
+	     information by letting it know the objfile has changed,
+	     making the dangling pointers point to correct data
+	     again.  */
+	     
+	  objfiles_changed ();
+
 	  read_symbols (objfile, 0);
 
 	  if (!objfile_has_symbols (objfile))
@@ -2671,9 +2691,6 @@ reread_symbols (void)
 
   if (!new_objfiles.empty ())
     {
-      /* Notify objfiles that we've modified objfile sections.  */
-      objfiles_changed ();
-
       clear_symtab_users (0);
 
       /* clear_objfile_data for each objfile was called before freeing it and
diff --git a/gdb/testsuite/gdb.base/reread-readsym.c b/gdb/testsuite/gdb.base/reread-readsym.c
new file mode 100644
index 0000000..2fee696
--- /dev/null
+++ b/gdb/testsuite/gdb.base/reread-readsym.c
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2017 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/>.  */
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/reread-readsym.exp b/gdb/testsuite/gdb.base/reread-readsym.exp
new file mode 100644
index 0000000..b69eaad
--- /dev/null
+++ b/gdb/testsuite/gdb.base/reread-readsym.exp
@@ -0,0 +1,61 @@
+#   Copyright 2017 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/>.
+
+standard_testfile
+
+set gdbfile [standard_output_file ${testfile}.gdb]
+
+# Test rereading executable.  See PR gdb/21337.
+
+proc generate_cmd_file {gdbfile binfile} {
+    set ofd [open $gdbfile w]
+
+    puts $ofd "file ${binfile}"
+    puts $ofd "shell sleep 1; touch ${binfile}"
+    puts $ofd "run"
+    puts $ofd "file"
+    puts $ofd "file ${binfile}"
+    puts $ofd "shell sleep 1; touch ${binfile}"
+    puts $ofd "run"
+    puts $ofd "file"
+    puts $ofd "file ${binfile}"
+    puts $ofd "shell sleep 1; touch ${binfile}"
+    puts $ofd "run"
+    puts $ofd "file"
+    puts $ofd "p \"source-command-completed\""
+    close $ofd
+}
+
+if [use_gdb_stub] {
+    return 0
+}
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
+    return -1
+}
+
+# Start with a fresh gdb.
+clean_restart ${testfile}
+
+# Using the source command to read commands from a file is important,
+# otherwise section data is freed and reallocated using the same
+# memory locations and the bug is not exposed.
+generate_cmd_file $gdbfile $binfile
+
+gdb_test "source $gdbfile" ".*source-command-completed.*" \
+    "source $testfile.gdb 1"
+# Sometimes the failure only occurs on the second invocation.
+gdb_test "source $gdbfile" ".*source-command-completed.*" \
+    "source $testfile.gdb 2"
-- 
1.9.1



  reply	other threads:[~2017-06-27 17:29 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-31 23:04 [PATCH] [mips] Fix PR 21337 v1: " Doug Gilmore
2017-04-10 16:01 ` Doug Gilmore
2017-04-12 18:52 ` Luis Machado
2017-04-12 21:42   ` Doug Gilmore
2017-04-13 18:56     ` [PATCH] Fix PR 21337 v2: " Doug Gilmore
2017-04-14 15:33       ` Luis Machado
2017-04-22  2:15       ` Simon Marchi
2017-04-25 18:16         ` Doug Gilmore
2017-04-27 19:46           ` Simon Marchi
2017-04-28 23:44             ` Doug Gilmore
2017-04-29  1:13               ` Luis Machado
2017-04-29  1:42               ` Simon Marchi
2017-04-29 17:12                 ` Doug Gilmore
2017-04-29 23:26                   ` Simon Marchi
2017-04-30  5:14                     ` Doug Gilmore
2017-05-10 23:26                       ` Doug Gilmore
2017-05-12  3:29                         ` Simon Marchi
2017-05-12 19:24                           ` Doug Gilmore
2017-05-16 23:11                           ` [PATCH] Fix PR 21337 (v3): " Doug Gilmore
2017-06-06 16:08                             ` [PING][PATCH] " Doug Gilmore
2017-06-23 18:20                               ` [PING^2][PATCH] " Doug Gilmore
2017-06-25 11:25                             ` [PATCH] " Simon Marchi
2017-06-27 17:29                               ` Doug Gilmore [this message]
2017-06-27 21:35                                 ` [PATCH] Fix PR 21337 (v4): " Doug Gilmore
2017-06-28  2:01                                   ` Maciej W. Rozycki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3abdfadd-9ec1-0f2c-45ed-de2184340320@imgtec.com \
    --to=doug.gilmore@imgtec.com \
    --cc=gdb-patches@sourceware.org \
    --cc=lgustavo@codesourcery.com \
    --cc=macro@imgtec.com \
    --cc=simon.marchi@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox