X86: Implement the lldt instruction.
[gem5.git] / util / tracediff
1 #! /usr/bin/env perl
2 # Copyright (c) 2003-2007 The Regents of The University of Michigan
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met: redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer;
9 # redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution;
12 # neither the name of the copyright holders nor the names of its
13 # contributors may be used to endorse or promote products derived from
14 # this software without specific prior written permission.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #
28 # Authors: Steve Reinhardt
29
30 # Script to simplify using rundiff on trace outputs from two
31 # invocations of m5. Takes a common m5 command line with embedded
32 # alternatives and executes the two alternative commands in separate
33 # subdirectories with output piped to rundiff.
34 #
35 # ******Note that you need to enable some trace flags in the args in order
36 # to do anything useful!******
37 #
38 # Script arguments are handled uniformly as follows:
39 # - If the argument does not contain a '|' character, it is appended
40 # to both command lines.
41 # - If the argument has a '|' character in it, the text on either side
42 # of the '|' is appended to the respective command lines. Note that
43 # you'll have to quote the arg or escape the '|' with a backslash
44 # so that the shell doesn't think you're doing a pipe.
45 # - Arguments with '#' characters are split at those characters,
46 # processed for alternatives ('|'s) as independent terms, then
47 # pasted back into a single argument (without the '#'s). (Sort of
48 # inspired by the C preprocessor '##' token pasting operator.)
49 #
50 # In other words, the arguments should look like the command line you
51 # want to run, with "|" used to list the alternatives for the parts
52 # that you want to differ between the two runs.
53 #
54 # For example:
55 #
56 # % tracediff m5.opt --opt1 '--opt2|--opt3' --opt4
57 # would compare these two runs:
58 # m5.opt --opt1 --opt2 --opt4
59 # m5.opt --opt1 --opt3 --opt4
60 #
61 # % tracediff 'path1|path2#/m5.opt' --opt1 --opt2
62 # would compare these two runs:
63 # path1/m5.opt --opt1 --opt2
64 # path2/m5.opt --opt1 --opt2
65 #
66 # If you want to add arguments to one run only, just put a '|' in with
67 # text only on one side ('--onlyOn1|'). You can do this with multiple
68 # arguments together too ('|-a -b -c' adds three args to the second
69 # run only).
70 #
71 # The '-n' argument to tracediff allows you to preview the two
72 # generated command lines without running them.
73 #
74
75 use FindBin;
76
77 $dryrun = 0;
78
79 if (@ARGV >= 1 && $ARGV[0] eq '-n') {
80 $dryrun = 1;
81 shift @ARGV;
82 }
83
84 if (@ARGV < 1) {
85 die "Usage: tracediff [-n] \"sim1|sim2\" [common-arg \"arg1|arg2\" ...]\n";
86 }
87
88 foreach $arg (@ARGV) {
89 $a1 = $a2 = '';
90 @subargs = split('#', $arg);
91 foreach $subarg (@subargs) {
92 if ($subarg eq '') {
93 next;
94 }
95 @pair = split('\|', $subarg, -1); # -1 enables null trailing fields
96 if (@pair == 1) {
97 $a1 .= $subarg;
98 $a2 .= $subarg;
99 } elsif (@pair == 2) {
100 $a1 .= $pair[0];
101 $a2 .= $pair[1];
102 } else {
103 print 'Parse error: too many |s in ', $arg, "\n";
104 exit(1);
105 }
106 }
107
108 push @cmd1, $a1;
109 push @cmd2, $a2;
110 }
111
112
113 if ($dryrun) {
114 print "CMD1: ", join(' ', @cmd1), "\n";
115 print "CMD2: ", join(' ', @cmd2), "\n";
116 exit(0);
117 }
118
119 # First two args are the two simulator binaries to compare
120 $sim1 = shift @cmd1;
121 $sim2 = shift @cmd2;
122
123 # Everything else is a simulator arg.
124 $args1 = join(' ', @cmd1);
125 $args2 = join(' ', @cmd2);
126
127 # Common mistake: if you don't set any traceflags this often isn't
128 # doing what you want.
129 if ($args1 !~ /--trace-flags/) {
130 print "****\n";
131 print "**** WARNING: no trace flags set... you may not be diffing much!\n";
132 print "****\n";
133 }
134
135 # Run individual invocations in separate dirs so output and intermediate
136 # files (particularly config.py and config.ini) don't conflict.
137 $dir1 = "tracediff-$$-1";
138 $dir2 = "tracediff-$$-2";
139 mkdir($dir1) or die "Can't create dir $dir1\n";
140 mkdir($dir2) or die "Can't create dir $dir2\n";
141
142 $cmd1 = "$sim1 -d $dir1 $args1 2>&1 |";
143 $cmd2 = "$sim2 -d $dir2 $args2 2>&1 |";
144
145 # Expect that rundiff is in the same dir as the tracediff script.
146 # FindBin figures that out for us.
147 $fullcmd = "$FindBin::Bin/rundiff '$cmd1' '$cmd2' 2>&1 > tracediff-$$.out";
148
149 print "Executing $fullcmd\n";
150 system($fullcmd);
151
152
153