[PATCH 3/3] set BFD_DECOMPRESS

Tom Tromey tromey@redhat.com
Tue Oct 16 20:50:00 GMT 2012


This sets BFD_DECOMPRESS, finally fixing PR 14704.  This causes BFD to
automatically decompress compressed sections.

In 7.5 and earlier (back to 2008, when compressed section support was
added), gdb would read compressed sections that had relocations -- but
it would not actually apply the relocations.

This patch also fixes this bug, because now the relocation code path
in dwarf2_read_section will also handle decompression, via BFD.

Built and regtested on x86-64 Fedora 16.

I've included a new test case that "fails" before the patch series, and
passes afterward.

I say "fails" because gdb_file_cmd calls perror, which sets the next
test to UNRESOLVED.  This seems bogus to me, but I didn't want to change
it.  I suppose I could; or at least add a "don't call perror" argument
to it -- thoughts?


	PR gdb/14704:
	* gdb_bfd.c (gdb_bfd_ref): Set BFD_DECOMPRESS.

	* gdb.base/comprdebug.exp: New file.
---
 gdb/gdb_bfd.c                         |    3 ++
 gdb/testsuite/gdb.base/comprdebug.exp |   46 +++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 0 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/comprdebug.exp

diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index f334e27..740da49 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -258,6 +258,9 @@ gdb_bfd_ref (struct bfd *abfd)
       return;
     }
 
+  /* Ask BFD to decompress sections in bfd_get_full_section_contents.  */
+  abfd->flags |= BFD_DECOMPRESS;
+
   gdata = bfd_zalloc (abfd, sizeof (struct gdb_bfd_data));
   gdata->refc = 1;
   gdata->mtime = bfd_get_mtime (abfd);
diff --git a/gdb/testsuite/gdb.base/comprdebug.exp b/gdb/testsuite/gdb.base/comprdebug.exp
new file mode 100644
index 0000000..65005bd
--- /dev/null
+++ b/gdb/testsuite/gdb.base/comprdebug.exp
@@ -0,0 +1,46 @@
+# Copyright 2012 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/>.
+
+standard_testfile average.c
+
+set ofile "${binfile}0.o"
+if {[gdb_compile $srcdir/$subdir/$srcfile $ofile \
+	 object {debug}] != ""} {
+    untested comprdebug.exp
+    return
+}
+
+set objcopy_program [transform objcopy]
+set cmd "$objcopy_program --compress-debug-sections $ofile"
+verbose "invoking $cmd"
+set result [catch "exec $cmd" output]
+verbose "result is $result"
+verbose "output is $output"
+
+if {$result == 1} {
+    untested comprdebug.exp
+    return
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+set testname "file [file tail $ofile]"
+if {[gdb_file_cmd $ofile] == 0} {
+    pass $testname
+} else {
+    fail $testname
+}
+
-- 
1.7.7.6



More information about the Gdb-patches mailing list