From: Tom Tromey Date: Sat, 17 Apr 2021 19:40:04 +0000 (-0600) Subject: Avoid crash in write_psymtabs_to_index X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=da314dd397ab967af558f2929a79349aa5f96ac8;p=binutils-gdb.git 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 * dwarf2/index-write.c (write_psymtabs_to_index): Check partial_symtabs. gdb/testsuite/ChangeLog 2021-04-17 Tom Tromey * gdb.dwarf2/gdb-index-nodebug.exp: New file. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 33a0997afcc..803597532a7 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2021-04-17 Tom Tromey + + * dwarf2/index-write.c (write_psymtabs_to_index): Check + partial_symtabs. + 2021-04-17 Tom Tromey * psymtab.c (psymbol_functions::expand_matching_symbols): Rename diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index f42a25331f8..6cfe415c5a2 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 995bb783bee..3e4a384bd95 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2021-04-17 Tom Tromey + + * gdb.dwarf2/gdb-index-nodebug.exp: New file. + 2021-04-16 Tom Tromey * 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 00000000000..27b46d4cea5 --- /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 . + +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"