5 use File
::Temp qw
/ tempfile /;
8 # Default to the system objdump if a cross-compiler edition not given.
9 my $aobjdump = "objdump";
15 GetOptions
('O|objdump=s' => \
$aobjdump,
16 'host-objdump=s' => \
$hobjdump,
17 'target-objdump=s' => \
$tobjdump,
18 'h|host-machine=s' => \
$hmachine,
19 't|target-machine=s' => \
$tmachine);
21 # But we can't default the machines. Sanity check that we've at least one.
22 die "No host or target machine type" if !$hmachine && !$tmachine;
24 # Reuse one temp file for all of the hunks.
25 my ($outh, $outname) = tempfile
();
27 END { unlink $outname; }
29 # Pre-construct the command-lines for executing the dump.
30 sub mkobjcommand
($$) {
31 my ($cmd, $mach) = @_;
33 $cmd = $aobjdump if !$cmd;
34 return "$cmd -m $mach --disassemble-all -b binary";
37 $objdump[1] = mkobjcommand
($hobjdump, $hmachine);
38 $objdump[2] = mkobjcommand
($tobjdump, $tmachine);
40 # Zero-initialize current dumping state.
46 my $ret = $objdump[$inobjd];
48 die "Host machine type not specified" if $inobjd == 1;
49 die "Target machine type not specified" if $inobjd == 2;
56 # Collect the data from the relevant OBJD-* lines ...
58 die "Internal error" if $inobjd == 2;
59 $mem = $mem . pack("H*", substr($_, 8, -1));
61 } elsif (/^OBJD-T: /) {
62 die "Internal error" if $inobjd == 1;
63 $mem = $mem . pack("H*", substr($_, 8, -1));
66 # ... which will always be followed by a blank line,
67 # at which point we should produce our dump.
69 # Rewrite the temp file in one go; it will usually be small.
74 my $cmd = objcommand
();
75 $cmd = $cmd . " --adjust-vma=" . $vma if $vma;
76 $cmd = $cmd . " " . $outname;
78 # Pipe from objdump...
81 # ... copying all but the first 7 lines of boilerplate to our stdout.
93 # The line before "OBJD-*" will be of the form "0x<hex>+: +\n".
94 # Extract the value for passing to --adjust-vma.
95 elsif (/^(0x[0-9a-fA-F]+):\s*$/) {