Skip to content

Commit

Permalink
disas-objdump: Pass --adjust-vma to objdump
Browse files Browse the repository at this point in the history
This gives the dumped blob its correct address during disassembly,
which makes pc-relative insns much easier to interpret.

Signed-off-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
  • Loading branch information
rth7680 authored and edgarigl committed Aug 24, 2013
1 parent 8dc6d24 commit 42eed42
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions scripts/disas-objdump.pl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ($$)
my ($cmd, $mach) = @_;
return 0 if !$mach;
$cmd = $aobjdump if !$cmd;
return "$cmd -m $mach --disassemble-all -b binary $outname";
return "$cmd -m $mach --disassemble-all -b binary";
}

$objdump[1] = mkobjcommand($hobjdump, $hmachine);
Expand All @@ -38,6 +38,7 @@ ($$)
# Zero-initialize current dumping state.
my $mem = "";
my $inobjd = 0;
my $vma = 0;

sub objcommand {
my $ret = $objdump[$inobjd];
Expand All @@ -50,7 +51,7 @@ sub objcommand {
}

while (<>) {
# Collect the data from the relevant OBJD-* lines.
# Collect the data from the relevant OBJD-* lines ...
if (/^OBJD-H: /) {
die "Internal error" if $inobjd == 2;
$mem = $mem . pack("H*", substr($_, 8, -1));
Expand All @@ -68,8 +69,12 @@ sub objcommand {
truncate $outh, 0;
syswrite $outh, $mem;

my $cmd = objcommand();
$cmd = $cmd . " --adjust-vma=" . $vma if $vma;
$cmd = $cmd . " " . $outname;

# Pipe from objdump...
open IN, "-|", objcommand();
open IN, "-|", $cmd;

# ... copying all but the first 7 lines of boilerplate to our stdout.
my $i = 0;
Expand All @@ -81,6 +86,13 @@ sub objcommand {

$mem = "";
$inobjd = 0;
$vma = 0;
}
# The line before "OBJD-*" will be of the form "0x<hex>+: +\n".
# Extract the value for passing to --adjust-vma.
elsif (/^(0x[0-9a-fA-F]+):\s*$/) {
$vma = $1;
print;
} else {
print;
}
Expand Down

0 comments on commit 42eed42

Please sign in to comment.