This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/3] simplify decompression code


Tom> I will give it a try with that fixed soon.

This patch, applied on top of my series, regression-tested ok.
So, if the BFD patch goes in, I will update gdb.

Pardon the reindentation in gdb_bfd.c.
This change does make the code prettier.

Tom

diff --git a/bfd/compress.c b/bfd/compress.c
index 7f94781..75d54e4 100644
--- a/bfd/compress.c
+++ b/bfd/compress.c
@@ -292,11 +292,20 @@ bfd_boolean
 bfd_is_section_compressed (bfd *abfd, sec_ptr sec)
 {
   bfd_byte compressed_buffer [12];
+  unsigned int saved = sec->compress_status;
+  bfd_boolean compressed;
+
+  /* Don't decompress the section.  */
+  sec->compress_status = COMPRESS_SECTION_NONE;
 
   /* Read the zlib header.  In this case, it should be "ZLIB" followed
      by the uncompressed section size, 8 bytes in big-endian order.  */
-  return (bfd_get_section_contents (abfd, sec, compressed_buffer, 0, 12)
-	  && CONST_STRNEQ ((char*) compressed_buffer, "ZLIB"));
+  compressed = (bfd_get_section_contents (abfd, sec, compressed_buffer, 0, 12)
+		&& CONST_STRNEQ ((char*) compressed_buffer, "ZLIB"));
+
+  /* Restore compress_status.  */
+  sec->compress_status = saved;
+  return compressed;
 }
 
 /*
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index 740da49..dcda614 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -365,50 +365,40 @@ gdb_bfd_map_section (asection *sectp, bfd_size_type *size)
   /* Check if the file has a 4-byte header indicating compression.
      Note that we can't use bfd_is_section_compressed here, because
      that does not work if the BFD_DECOMPRESS flag is set.  */
-  if (bfd_get_section_size (sectp) > sizeof (header)
-      && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
-      && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
+  if (!bfd_is_section_compressed (abfd, sectp))
     {
-      /* Upon decompression, update the buffer and its size.  */
-      if (strncmp (header, "ZLIB", sizeof (header)) == 0)
-	goto no_mmap;
-    }
-
-  {
-    /* The page size, used when mmapping.  */
-    static int pagesize;
+      /* The page size, used when mmapping.  */
+      static int pagesize;
 
-    if (pagesize == 0)
-      pagesize = getpagesize ();
+      if (pagesize == 0)
+	pagesize = getpagesize ();
 
-    /* Only try to mmap sections which are large enough: we don't want
-       to waste space due to fragmentation.  */
+      /* Only try to mmap sections which are large enough: we don't want
+	 to waste space due to fragmentation.  */
 
-    if (bfd_get_section_size (sectp) > 4 * pagesize)
-      {
-	descriptor->size = bfd_get_section_size (sectp);
-	descriptor->data = bfd_mmap (abfd, 0, descriptor->size, PROT_READ,
-				     MAP_PRIVATE, sectp->filepos,
-				     &descriptor->map_addr,
-				     &descriptor->map_len);
-
-	if ((caddr_t)descriptor->data != MAP_FAILED)
-	  {
+      if (bfd_get_section_size (sectp) > 4 * pagesize)
+	{
+	  descriptor->size = bfd_get_section_size (sectp);
+	  descriptor->data = bfd_mmap (abfd, 0, descriptor->size, PROT_READ,
+				       MAP_PRIVATE, sectp->filepos,
+				       &descriptor->map_addr,
+				       &descriptor->map_len);
+
+	  if ((caddr_t)descriptor->data != MAP_FAILED)
+	    {
 #if HAVE_POSIX_MADVISE
-	    posix_madvise (descriptor->map_addr, descriptor->map_len,
-			   POSIX_MADV_WILLNEED);
+	      posix_madvise (descriptor->map_addr, descriptor->map_len,
+			     POSIX_MADV_WILLNEED);
 #endif
-	    goto done;
-	  }
+	      goto done;
+	    }
 
-	/* On failure, clear out the section data and try again.  */
-	memset (descriptor, 0, sizeof (*descriptor));
-      }
-  }
+	  /* On failure, clear out the section data and try again.  */
+	  memset (descriptor, 0, sizeof (*descriptor));
+	}
+    }
 #endif /* HAVE_MMAP */
 
- no_mmap:
-
   /* Handle compressed sections, or ordinary uncompressed sections in
      the no-mmap case.  */
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]