public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Avoid crash in write_psymtabs_to_index
@ 2021-04-17 19:50 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2021-04-17 19:50 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=da314dd397ab967af558f2929a79349aa5f96ac8

commit da314dd397ab967af558f2929a79349aa5f96ac8
Author: Tom Tromey <tom@tromey.com>
Date:   Sat Apr 17 13:40:04 2021 -0600

    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.

Diff:
---
 gdb/ChangeLog                                  |  5 +++++
 gdb/dwarf2/index-write.c                       |  3 ++-
 gdb/testsuite/ChangeLog                        |  4 ++++
 gdb/testsuite/gdb.dwarf2/gdb-index-nodebug.exp | 28 ++++++++++++++++++++++++++
 4 files changed, 39 insertions(+), 1 deletion(-)

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  <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
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  <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 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 <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"


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-17 19:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-17 19:50 [binutils-gdb] Avoid crash in write_psymtabs_to_index Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).