Switch from readelf to objdump for reading contents of sections, since readelf switched its output format.
authordbaron@dbaron.org
Wed, 20 Jun 2007 15:01:17 -0700
changeset 2619 706b1f7437e5549ee10ab8a86fdd2c283ef72a85
parent 2618 7d9faff1e81c5da6b09474e2de2e0ff1b21360e4
child 2620 2759d533e703ab00c716c14416921c431fb27774
push idunknown
push userunknown
push dateunknown
milestone1.9a6pre
Switch from readelf to objdump for reading contents of sections, since readelf switched its output format.
tools/rb/fix-linux-stack.pl
--- a/tools/rb/fix-linux-stack.pl
+++ b/tools/rb/fix-linux-stack.pl
@@ -31,16 +31,18 @@
 # use your version of this file under the terms of the MPL, indicate your
 # decision by deleting the provisions above and replace them with the notice
 # and other provisions required by the GPL or the LGPL. If you do not delete
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
+# $Id: fix-linux-stack.pl,v 1.15 2007/06/20 22:01:17 dbaron%dbaron.org Exp $
+#
 # This script uses addr2line (part of binutils) to process the output of
 # nsTraceRefcnt's Linux stack walking code.  This is useful for two
 # things:
 #  (1) Getting line number information out of
 #      |nsTraceRefcntImpl::WalkTheStack|'s output in debug builds.
 #  (2) Getting function names out of |nsTraceRefcntImpl::WalkTheStack|'s
 #      output on optimized builds (where it mostly prints UNKNOWN
 #      because only a handful of symbols are exported from component
@@ -104,18 +106,19 @@ sub address_adjustment($) {
 # for documentation of debugging information in separate files.
 # On Fedora distributions, these files can be obtained by installing
 # *-debuginfo RPM packages.
 sub separate_debug_file_for($) {
     my ($file) = @_;
     # We can read the .gnu_debuglink section using either of:
     #   objdump -s --section=.gnu_debuglink $file
     #   readelf -x .gnu_debuglink $file
-    # Since we already depend on readelf in |address_adjustment|, use it
-    # again here.
+    # Since readelf prints things backwards on little-endian platforms
+    # for some versions only (backwards on Fedora Core 6, forwards on
+    # Fedora 7), use objdump.
 
     # See if there's a .gnu_debuglink section
     my $have_debuglink = 0;
     open(ELFSECS, '-|', 'readelf', '-S', $file);
     while (<ELFSECS>) {
         if (/^\s*\[\s*\d+\]\s+\.gnu_debuglink\s+\w+\s+(\w+)\s+(\w+)\s+/) {
             $have_debuglink = 1;
             last;
@@ -134,29 +137,23 @@ sub separate_debug_file_for($) {
         }
     }
     close(ELFHDR);
     if ($endian ne 'little' && $endian ne 'big') {
         print STDERR "Warning: could not determine endianness of $file.\n";
         return '';
     }
 
-    # Read the debuglink section as an array of words, in hexidecimal,
-    # library endianness.  (I'm guessing that readelf's big-endian
-    # output is sensible; I've only tested little-endian, where it's a
-    # bit odd.)
-    open(DEBUGLINK, '-|', 'readelf', '-x', '.gnu_debuglink', $file);
+
+    # Read the debuglink section as an array of words, in hexidecimal.
+    open(DEBUGLINK, '-|', 'objdump', '-s', '--section=.gnu_debuglink', $file);
     my @words;
     while (<DEBUGLINK>) {
-        if ($_ =~ /^  0x[0-9a-f]{8} ([0-9a-f ]{8}) ([0-9a-f ]{8}) ([0-9a-f ]{8}) ([0-9a-f ]{8}).*/) {
-            if ($endian eq 'little') {
-                push @words, $4, $3, $2, $1;
-            } else {
-                push @words, $1, $2, $3, $4;
-            }
+        if ($_ =~ /^ [0-9a-f]* ([0-9a-f ]{8}) ([0-9a-f ]{8}) ([0-9a-f ]{8}) ([0-9a-f ]{8}).*/) {
+            push @words, $1, $2, $3, $4;
         }
     }
     close(DEBUGLINK);
 
     while (@words[$#words] eq '        ') {
         pop @words;
     }
 
@@ -164,23 +161,19 @@ sub separate_debug_file_for($) {
         print STDERR "Warning: .gnu_debuglink section in $file too short.\n";
         return '';
     }
 
     my @chars;
     while ($#words >= 0) {
         my $w = shift @words;
         if ($w =~ /^([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/) {
-            if ($endian eq 'little') {
-                push @chars, $4, $3, $2, $1;
-            } else {
-                push @chars, $1, $2, $3, $4;
-            }
+            push @chars, $1, $2, $3, $4;
         } else {
-            print STDERR "Warning: malformed readelf output for $file.\n";
+            print STDERR "Warning: malformed objdump output for $file.\n";
             return '';
         }
     }
 
     my @hash_bytes = map(hex, @chars[$#chars - 3 .. $#chars]);
     $#chars -= 4;
 
     my $hash;