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