aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorDoug Gilmore <Doug.Gilmore@imgtec.com>2017-06-28 02:54:22 +0100
committerMaciej W. Rozycki <macro@imgtec.com>2017-06-28 02:54:22 +0100
commit41664b45ab6387184bd0e7512fcf7a72c58744e7 (patch)
treec2c3df35f53f8a8d9ec76db7e96d066c0ef195f1 /gdb/testsuite
parent819e1f86976dbbd13e0de004cdd3e3089e4c3fc0 (diff)
downloadgdb-41664b45ab6387184bd0e7512fcf7a72c58744e7.zip
gdb-41664b45ab6387184bd0e7512fcf7a72c58744e7.tar.gz
gdb-41664b45ab6387184bd0e7512fcf7a72c58744e7.tar.bz2
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-06-28 Doug Gilmore <Doug.Gilmore@imgtec.com> PR gdb/21337 * symfile.c (reread_symbols): Call objfiles_changed just before read_symbols. gdb/testsuite/ 2017-06-28 Doug Gilmore <Doug.Gilmore@imgtec.com> PR gdb/21337 * gdb.base/reread-readsym.exp: New file. * gdb.base/reread-readsym.c: New file.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog6
-rw-r--r--gdb/testsuite/gdb.base/reread-readsym.c22
-rw-r--r--gdb/testsuite/gdb.base/reread-readsym.exp61
3 files changed, 89 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 253e229..b7462a5 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2017-06-28 Doug Gilmore <Doug.Gilmore@imgtec.com>
+
+ PR gdb/21337
+ * gdb.base/reread-readsym.exp: New file.
+ * gdb.base/reread-readsym.c: New file.
+
2017-06-21 Kevin Buettner <kevinb@redhat.com>
* gdb.exp (gdb_test): Using noncapturing parens for the $pattern
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"