3 sub parse_objdump_file {
6 open (INPUT, $filename) or die "$filename: $!\n";
8 if (/\s*([0-9a-f]*):\t(([0-9a-f]{2} )+) *\t(.*)$/) {
9 my ($addr, $bytes, $instr) = ($1, $2, $4);
11 $bytes =~ s/\s*(.*\S)\s*/$1/; # trim any remaining whitespace
12 $instr =~ s/\s*(.*\S)\s*/$1/;
13 push (@result, {'addr' => $addr, 'bytes' => $bytes, 'instr' => $instr});
24 open (INPUT, $filename) or die "$filename: $!\n";
26 if (/^(0x[0-9a-f]*):\t([^\t]*)\t[^:]*:\t((0x[0-9a-f]{2}\s*)+)\s*$/) {
27 my ($addr, $bytes, $instr) = ($1, $3, $2);
29 $bytes =~ s/\s+/ /g; # regularize whitespace
30 $bytes =~ s/\s*(.*\S)\s*/$1/; # trim any remaining whitespace
31 $instr =~ s/\s*(.*\S)\s*/$1/;
32 push (@result, {'addr' => $addr, 'bytes' => $bytes, 'instr' => $instr});
33 } elsif (/^(0x[0-9a-f]*):\t$/) { # deal with gdb's line breaker
35 } elsif ($got_addr && /^ ([^\t]*)\t[^:]*:\t((0x[0-9a-f]{2}\s*)+)\s*$/) {
36 my ($addr, $bytes, $instr) = ($got_addr, $2, $1);
38 $bytes =~ s/\s+/ /g; # regularize whitespace
39 $bytes =~ s/\s*(.*\S)\s*/$1/; # trim any remaining whitespace
40 $instr =~ s/\s*(.*\S)\s*/$1/;
41 push (@result, {'addr' => $addr, 'bytes' => $bytes, 'instr' => $instr});
50 my ($objdump_file, $gdb_file) = @_;
51 my @file1 = parse_objdump_file ($objdump_file);
52 my @file2 = parse_gdb_file ($gdb_file);
53 my $lastrecord = ($#file1 >= $#file2) ? ($#file1) : ($#file2);
54 for (my $i = 0; $i <= $lastrecord; ++$i) {
57 if ($d1->{'bytes'} ne $d2->{'bytes'}) {
58 printf "0x%08x:\t%30s \t%s\n", 0+$d1->{'addr'}, $d1->{'bytes'}, $d1->{'instr'};
59 printf "0x%08x:\t%30s \t%s\n\n", 0+$d2->{'addr'}, $d2->{'bytes'}, $d2->{'instr'};
64 $objdump_file = $ARGV[0];
66 binary_diffs ($objdump_file, $gdb_file);
77 codegen-diff I<OBJDUMP-OUTPUT-FILE> I<GDB-DISASSEMBLY-FILE>
81 B<codegen-diff> is a program that tries to show you the differences
82 between the code that B<llc> generated and the code that B<lli> generated.
84 The way you use it is as follows: first, you create I<OBJDUMP-OUTPUT-FILE>
85 by running B<objdump> on the B<llc> compiled and linked binary. You need to
86 trim down the result so it contains only the function of interest.
88 Second, you create I<GDB-DISASSEMBLY-FILE> by running B<gdb>, with my patch
89 to print out hex bytes in the B<disassemble> command output, on
90 B<lli>. Set a breakpoint in C<Emitter::finishFunction()> and wait until
91 the function you want is compiled. Then use the B<disassemble> command
92 to print out the assembly dump of the function B<lli> just compiled.
93 (Use C<lli -debug> to find out where the function starts and ends in memory.)
94 It's easiest to save this output by using B<script>.
96 Finally, you run B<codegen-diff>, as indicated in the Synopsis section of
97 this manpage. It will print out a two-line stanza for each mismatched
98 instruction, with the B<llc> version first, and the B<lli> version second.
102 B<codegen-diff> was written by Brian Gaeke.
106 L<gdb(1)>, L<objdump(1)>, L<script(1)>.
108 You will need my B<gdb> patch:
110 http://llvm.cs.uiuc.edu/~gaeke/gdb-disassembly-print-bytes.patch