qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: qemu-devel@nongnu.org
Cc: jcmvbkbc@gmail.com, gxt@mprc.pku.edu.cn, proljc@gmail.com,
	claudio.fontana@gmail.com, peter.maydell@linaro.org
Subject: [Qemu-devel] [PATCH 2/2] disas: Add disas-objdump.pl
Date: Fri,  9 Aug 2013 09:19:18 -1000	[thread overview]
Message-ID: <1376075958-21932-3-git-send-email-rth@twiddle.net> (raw)
In-Reply-To: <1376075958-21932-1-git-send-email-rth@twiddle.net>

The script massages the output produced for architectures that are
not supported internally by qemu though an external objdump program
for disassembly.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 scripts/disas-objdump.pl | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
 create mode 100755 scripts/disas-objdump.pl

diff --git a/scripts/disas-objdump.pl b/scripts/disas-objdump.pl
new file mode 100755
index 0000000..c66a629
--- /dev/null
+++ b/scripts/disas-objdump.pl
@@ -0,0 +1,87 @@
+#!/usr/bin/perl -w
+
+use File::Temp qw/ tempfile /;
+use Getopt::Long;
+
+# Default to the system objdump if a cross-compiler edition not given.
+my $aobjdump = "objdump";
+my $hobjdump = "";
+my $tobjdump = "";
+my $hmachine = "";
+my $tmachine = "";
+
+GetOptions ('O|objdump=s' => \$aobjdump,
+            'host-objdump=s' => \$hobjdump,
+            'target-objdump=s' => \$tobjdump,
+            'h|host-machine=s' => \$hmachine,
+            't|target-machine=s' => \$tmachine);
+
+# But we can't default the machines.  Sanity check that we've at least one.
+die "No host or target machine type" if !$hmachine && !$tmachine;
+
+# Reuse one temp file for all of the hunks.
+my ($outh, $outname) = tempfile();
+binmode($outh);
+END { unlink $outname; }
+
+# Pre-construct the command-lines for executing the dump.
+sub mkobjcommand ($$) {
+    my ($cmd, $mach) = @_;
+    return 0 if !$mach;
+    $cmd = $aobjdump if !$cmd;
+    return "$cmd -m $mach --disassemble-all -b binary $outname";
+}
+
+$objdump[1] = mkobjcommand($hobjdump, $hmachine);
+$objdump[2] = mkobjcommand($tobjdump, $tmachine);
+
+# Zero-initialize current dumping state.
+my $mem = "";
+my $inobjd = 0;
+
+sub objcommand {
+    my $ret = $objdump[$inobjd];
+    if (!$ret) {
+        die "Host machine type not specified" if $inobjd == 1;
+        die "Target machine type not specified" if $inobjd == 2;
+        die "Internal error";
+    }
+    return $ret;
+}
+
+while (<>) {
+    # Collect the data from the relevant OBJD-* lines.
+    if (/^OBJD-H: /) {
+        die "Internal error" if $inobjd == 2;
+        $mem = $mem . pack("H*", substr($_, 8, -1));
+        $inobjd = 1;
+    } elsif (/^OBJD-T: /) {
+        die "Internal error" if $inobjd == 1;
+        $mem = $mem . pack("H*", substr($_, 8, -1));
+        $inobjd = 2;
+    }
+    # ... which will always be followed by a blank line,
+    # at which point we should produce our dump.
+    elsif ($inobjd) {
+        # Rewrite the temp file in one go; it will usually be small.
+        sysseek $outh, 0, 0;
+        truncate $outh, 0;
+        syswrite $outh, $mem;
+
+        # Pipe from objdump...
+        open IN, "-|", objcommand();
+
+        # ... copying all but the first 7 lines of boilerplate to our stdout.
+	my $i = 0;
+	while (<IN>) {
+	    print if (++$i > 7);
+        }
+        close IN;
+        print "\n";
+
+        $mem = "";
+        $inobjd = 0;
+    } else {
+        print;
+    }
+}
-- 
1.8.3.1

  parent reply	other threads:[~2013-08-09 19:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-09 19:19 [Qemu-devel] [PATCH 0/2] Disassembly with external objdump Richard Henderson
2013-08-09 19:19 ` [Qemu-devel] [PATCH 1/2] disas: Implement fallback to dump object code as hex Richard Henderson
2013-08-09 19:19 ` Richard Henderson [this message]
2013-08-10  4:08   ` [Qemu-devel] [PATCH 2/2] disas: Add disas-objdump.pl Max Filippov
2013-08-10 10:39     ` Richard Henderson
2013-08-10  1:54 ` [Qemu-devel] [PATCH 0/2] Disassembly with external objdump Jia Liu
2013-08-10  9:16 ` Peter Maydell
2013-08-10 10:22   ` Claudio Fontana
2013-08-10 15:45     ` Peter Maydell
2013-08-10 16:42       ` Richard Henderson
2013-08-10 16:53         ` Max Filippov
2013-08-10 19:47           ` Richard Henderson
2013-09-03 13:18             ` Claudio Fontana
2013-08-11  8:59 ` Blue Swirl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1376075958-21932-3-git-send-email-rth@twiddle.net \
    --to=rth@twiddle.net \
    --cc=claudio.fontana@gmail.com \
    --cc=gxt@mprc.pku.edu.cn \
    --cc=jcmvbkbc@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=proljc@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).