Fix gdb segv when objfile can't be opened
[binutils-gdb.git] / gdb / gdb_bfd.c
index cc02740c1a63b662516e1ed79f0152701d37dcc9..02b1375b8ac7d59efd5f4e024136cbea355b584e 100644 (file)
@@ -1,6 +1,6 @@
 /* Definitions for BFD wrappers used by GDB.
 
-   Copyright (C) 2011-2017 Free Software Foundation, Inc.
+   Copyright (C) 2011-2018 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -702,9 +702,15 @@ gdb_bfd_map_section (asection *sectp, bfd_size_type *size)
 
   data = NULL;
   if (!bfd_get_full_section_contents (abfd, sectp, &data))
-    error (_("Can't read data for section '%s' in file '%s'"),
-          bfd_get_section_name (abfd, sectp),
-          bfd_get_filename (abfd));
+    {
+      warning (_("Can't read data for section '%s' in file '%s'"),
+              bfd_get_section_name (abfd, sectp),
+              bfd_get_filename (abfd));
+      /* Set size to 0 to prevent further attempts to read the invalid
+        section.  */
+      *size = 0;
+      return (const gdb_byte *) NULL;
+    }
   descriptor->data = data;
 
  done: