[gdb/testsuite] Fix incorrect string concat in jit-elf.exp
[deliverable/binutils-gdb.git] / gdb / minidebug.c
index 43232945b9df963dce8aa2bb4c598159e458abc2..dbf14c79fb958f4357f06bdef617a2652c74184b 100644 (file)
@@ -1,6 +1,6 @@
 /* Read MiniDebugInfo data from an objfile.
 
-   Copyright (C) 2012-2016 Free Software Foundation, Inc.
+   Copyright (C) 2012-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 
 #ifdef HAVE_LIBLZMA
 
+/* We stash a reference to the .gnu_debugdata BFD on the enclosing
+   BFD.  */
+static const bfd_key<gdb_bfd_ref_ptr> gnu_debug_key;
+
 #include <lzma.h>
 
 /* Allocator function for LZMA.  */
@@ -83,12 +87,11 @@ lzma_open (struct bfd *nbfd, void *open_closure)
   gdb_byte footer[LZMA_STREAM_HEADER_SIZE];
   gdb_byte *indexdata;
   lzma_index *index;
-  int ret;
   uint64_t memlimit = UINT64_MAX;
   struct gdb_lzma_stream *lstream;
   size_t pos;
 
-  size = bfd_get_section_size (section);
+  size = bfd_section_size (section);
   offset = section->filepos + size - LZMA_STREAM_HEADER_SIZE;
   if (size < LZMA_STREAM_HEADER_SIZE
       || bfd_seek (section->owner, offset, SEEK_SET) != 0
@@ -256,11 +259,11 @@ lzma_stat (struct bfd *abfd,
    If we find one we create a iovec based bfd that decompresses the
    object data on demand.  If we don't find one, return NULL.  */
 
-bfd *
+gdb_bfd_ref_ptr
 find_separate_debug_file_in_section (struct objfile *objfile)
 {
   asection *section;
-  bfd *abfd;
+  gdb_bfd_ref_ptr abfd;
 
   if (objfile->obfd == NULL)
     return NULL;
@@ -270,21 +273,29 @@ find_separate_debug_file_in_section (struct objfile *objfile)
     return NULL;
 
 #ifdef HAVE_LIBLZMA
-  abfd = gdb_bfd_openr_iovec (objfile_name (objfile), gnutarget, lzma_open,
+  gdb_bfd_ref_ptr *shared = gnu_debug_key.get (objfile->obfd);
+  if (shared != nullptr)
+    return *shared;
+
+  std::string filename = string_printf (_(".gnu_debugdata for %s"),
+                                       objfile_name (objfile));
+
+  abfd = gdb_bfd_openr_iovec (filename.c_str (), gnutarget, lzma_open,
                              section, lzma_pread, lzma_close, lzma_stat);
   if (abfd == NULL)
     return NULL;
 
-  if (!bfd_check_format (abfd, bfd_object))
+  if (!bfd_check_format (abfd.get (), bfd_object))
     {
       warning (_("Cannot parse .gnu_debugdata section; not a BFD object"));
-      gdb_bfd_unref (abfd);
       return NULL;
     }
+
+  gnu_debug_key.emplace (objfile->obfd, abfd);
+
 #else
   warning (_("Cannot parse .gnu_debugdata section; LZMA support was "
             "disabled at compile time"));
-  abfd = NULL;
 #endif /* !HAVE_LIBLZMA */
 
   return abfd;
This page took 0.026002 seconds and 4 git commands to generate.