aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-04-17 13:40:04 -0600
committerTom Tromey <tom@tromey.com>2021-04-17 13:40:04 -0600
commitda314dd397ab967af558f2929a79349aa5f96ac8 (patch)
treeb208014a1127187e98feb5a94afa6148f48787bf /gdb
parent0b7b2c2adff43d39ee3bd39ebd91a6710d9175e4 (diff)
downloadfsf-binutils-gdb-da314dd397ab967af558f2929a79349aa5f96ac8.zip
fsf-binutils-gdb-da314dd397ab967af558f2929a79349aa5f96ac8.tar.gz
fsf-binutils-gdb-da314dd397ab967af558f2929a79349aa5f96ac8.tar.bz2
Avoid crash in write_psymtabs_to_index
If I try "save gdb-index" using the executable from gdb.cp/cmpd-minsyms.exp, gdb will crash. This happens due to a missing NULL check. gdb/ChangeLog 2021-04-17 Tom Tromey <tom@tromey.com> * dwarf2/index-write.c (write_psymtabs_to_index): Check partial_symtabs. gdb/testsuite/ChangeLog 2021-04-17 Tom Tromey <tom@tromey.com> * gdb.dwarf2/gdb-index-nodebug.exp: New file.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/dwarf2/index-write.c3
-rw-r--r--gdb/testsuite/ChangeLog4
-rw-r--r--gdb/testsuite/gdb.dwarf2/gdb-index-nodebug.exp28
4 files changed, 39 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 33a0997..8035975 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2021-04-17 Tom Tromey <tom@tromey.com>
+ * dwarf2/index-write.c (write_psymtabs_to_index): Check
+ partial_symtabs.
+
+2021-04-17 Tom Tromey <tom@tromey.com>
+
* psymtab.c (psymbol_functions::expand_matching_symbols): Rename
from map_matching_symbols. Change parameters.
* psympriv.h (struct psymbol_functions) <expand_matching_symbols>:
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index f42a253..6cfe415 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1693,7 +1693,8 @@ write_psymtabs_to_index (dwarf2_per_objfile *per_objfile, const char *dir,
if (per_objfile->per_bfd->types.size () > 1)
error (_("Cannot make an index when the file has multiple .debug_types sections"));
- if (!per_bfd->partial_symtabs->psymtabs
+ if (per_bfd->partial_symtabs == nullptr
+ || !per_bfd->partial_symtabs->psymtabs
|| !per_bfd->partial_symtabs->psymtabs_addrmap)
return;
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 995bb78..3e4a384 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2021-04-17 Tom Tromey <tom@tromey.com>
+
+ * gdb.dwarf2/gdb-index-nodebug.exp: New file.
+
2021-04-16 Tom Tromey <tom@tromey.com>
* gdb.rust/simple.exp: Change error text.
diff --git a/gdb/testsuite/gdb.dwarf2/gdb-index-nodebug.exp b/gdb/testsuite/gdb.dwarf2/gdb-index-nodebug.exp
new file mode 100644
index 0000000..27b46d4
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/gdb-index-nodebug.exp
@@ -0,0 +1,28 @@
+# Copyright 2021 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/>.
+
+load_lib dwarf.exp
+
+standard_testfile main.c
+
+if {[prepare_for_testing "failed to prepare" "${testfile}" \
+ [list ${srcfile}] {nodebug}]} {
+ return -1
+}
+
+set index_file ${testfile}.gdb-index
+# The bug was that gdb would crash here.
+gdb_test_no_output "save gdb-index [file dirname ${index_file}]" \
+ "try to save gdb index"