Fix -Wmisleading-indentation warning in top.c
[deliverable/binutils-gdb.git] / gdb / minidebug.c
index a4907b2c028a66aa28cc6b26c89936a937c6d8ee..2a60741dfaff687b37f07986a69ea48876cebd5e 100644 (file)
@@ -1,6 +1,6 @@
 /* Read MiniDebugInfo data from an objfile.
 
-   Copyright (C) 2012-2014 Free Software Foundation, Inc.
+   Copyright (C) 2012-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 
 #include "defs.h"
 #include "gdb_bfd.h"
-#include <string.h>
 #include "symfile.h"
 #include "objfiles.h"
 #include "gdbcore.h"
+#include <algorithm>
 
 #ifdef HAVE_LIBLZMA
 
@@ -53,7 +53,7 @@ static lzma_allocator gdb_lzma_allocator = { alloc_lzma, free_lzma, NULL };
    a section.  This keeps only the last decompressed block in memory
    to allow larger data without using to much memory.  */
 
-struct lzma_stream
+struct gdb_lzma_stream
 {
   /* Section of input BFD from which we are decoding data.  */
   asection *section;
@@ -71,24 +71,23 @@ struct lzma_stream
    find_separate_debug_file_in_section.  OPEN_CLOSURE is 'asection *'
    of the section to decompress.
 
-   Return 'struct lzma_stream *' must be freed by caller by xfree, together
-   with its INDEX lzma data.  */
+   Return 'struct gdb_lzma_stream *' must be freed by caller by xfree,
+   together with its INDEX lzma data.  */
 
 static void *
 lzma_open (struct bfd *nbfd, void *open_closure)
 {
-  asection *section = open_closure;
+  asection *section = (asection *) open_closure;
   bfd_size_type size, offset;
   lzma_stream_flags options;
   gdb_byte footer[LZMA_STREAM_HEADER_SIZE];
   gdb_byte *indexdata;
   lzma_index *index;
-  int ret;
   uint64_t memlimit = UINT64_MAX;
-  struct lzma_stream *lstream;
+  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
@@ -102,7 +101,7 @@ lzma_open (struct bfd *nbfd, void *open_closure)
     }
 
   offset -= options.backward_size;
-  indexdata = xmalloc (options.backward_size);
+  indexdata = (gdb_byte *) xmalloc (options.backward_size);
   index = NULL;
   pos = 0;
   if (bfd_seek (section->owner, offset, SEEK_SET) != 0
@@ -119,7 +118,7 @@ lzma_open (struct bfd *nbfd, void *open_closure)
     }
   xfree (indexdata);
 
-  lstream = xzalloc (sizeof (struct lzma_stream));
+  lstream = XCNEW (struct gdb_lzma_stream);
   lstream->section = section;
   lstream->index = index;
 
@@ -128,13 +127,13 @@ lzma_open (struct bfd *nbfd, void *open_closure)
 
 /* bfd_openr_iovec PREAD_P implementation for
    find_separate_debug_file_in_section.  Passed STREAM
-   is 'struct lzma_stream *'.  */
+   is 'struct gdb_lzma_stream *'.  */
 
 static file_ptr
 lzma_pread (struct bfd *nbfd, void *stream, void *buf, file_ptr nbytes,
            file_ptr offset)
 {
-  struct lzma_stream *lstream = stream;
+  struct gdb_lzma_stream *lstream = (struct gdb_lzma_stream *) stream;
   bfd_size_type chunk_size;
   lzma_index_iter iter;
   gdb_byte *compressed, *uncompressed;
@@ -156,7 +155,7 @@ lzma_pread (struct bfd *nbfd, void *stream, void *buf, file_ptr nbytes,
          if (lzma_index_iter_locate (&iter, offset))
            break;
 
-         compressed = xmalloc (iter.block.total_size);
+         compressed = (gdb_byte *) xmalloc (iter.block.total_size);
          block_offset = section->filepos + iter.block.compressed_file_offset;
          if (bfd_seek (section->owner, block_offset, SEEK_SET) != 0
              || bfd_bread (compressed, iter.block.total_size, section->owner)
@@ -166,7 +165,7 @@ lzma_pread (struct bfd *nbfd, void *stream, void *buf, file_ptr nbytes,
              break;
            }
 
-         uncompressed = xmalloc (iter.block.uncompressed_size);
+         uncompressed = (gdb_byte *) xmalloc (iter.block.uncompressed_size);
 
          memset (&block, 0, sizeof (block));
          block.filters = filters;
@@ -202,7 +201,7 @@ lzma_pread (struct bfd *nbfd, void *stream, void *buf, file_ptr nbytes,
                               + iter.block.uncompressed_size);
        }
 
-      chunk_size = min (nbytes, lstream->data_end - offset);
+      chunk_size = std::min (nbytes, (file_ptr) lstream->data_end - offset);
       memcpy (buf, lstream->data + offset - lstream->data_start, chunk_size);
       buf = (gdb_byte *) buf + chunk_size;
       offset += chunk_size;
@@ -215,13 +214,13 @@ lzma_pread (struct bfd *nbfd, void *stream, void *buf, file_ptr nbytes,
 
 /* bfd_openr_iovec CLOSE_P implementation for
    find_separate_debug_file_in_section.  Passed STREAM
-   is 'struct lzma_stream *'.  */
+   is 'struct gdb_lzma_stream *'.  */
 
 static int
 lzma_close (struct bfd *nbfd,
            void *stream)
 {
-  struct lzma_stream *lstream = stream;
+  struct gdb_lzma_stream *lstream = (struct gdb_lzma_stream *) stream;
 
   lzma_index_end (lstream->index, &gdb_lzma_allocator);
   xfree (lstream->data);
@@ -233,15 +232,16 @@ lzma_close (struct bfd *nbfd,
 
 /* bfd_openr_iovec STAT_P implementation for
    find_separate_debug_file_in_section.  Passed STREAM
-   is 'struct lzma_stream *'.  */
+   is 'struct gdb_lzma_stream *'.  */
 
 static int
 lzma_stat (struct bfd *abfd,
           void *stream,
           struct stat *sb)
 {
-  struct lzma_stream *lstream = stream;
+  struct gdb_lzma_stream *lstream = (struct gdb_lzma_stream *) stream;
 
+  memset (sb, 0, sizeof (struct stat));
   sb->st_size = lzma_index_uncompressed_size (lstream->index);
   return 0;
 }
@@ -255,11 +255,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;
@@ -269,21 +269,22 @@ 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,
+  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;
     }
 #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.027614 seconds and 4 git commands to generate.