blob: bdfd31379a9416a10870c4911bf974d678b10d0c [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4<head>
5 <title>LLVM bugpoint tool: design and usage</title>
6 <link rel="stylesheet" href="llvm.css" type="text/css">
7</head>
8
9<div class="doc_title">
10 LLVM bugpoint tool: design and usage
11</div>
12
13<ul>
14 <li><a href="#desc">Description</a></li>
15 <li><a href="#design">Design Philosophy</a>
16 <ul>
17 <li><a href="#autoselect">Automatic Debugger Selection</a></li>
18 <li><a href="#crashdebug">Crash debugger</a></li>
19 <li><a href="#codegendebug">Code generator debugger</a></li>
20 <li><a href="#miscompilationdebug">Miscompilation debugger</a></li>
21 </ul></li>
22 <li><a href="#advice">Advice for using <tt>bugpoint</tt></a></li>
23</ul>
24
25<div class="doc_author">
26<p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a></p>
27</div>
28
29<!-- *********************************************************************** -->
30<div class="doc_section">
31<a name="desc">Description</a>
32</div>
33<!-- *********************************************************************** -->
34
35<div class="doc_text">
36
37<p><tt>bugpoint</tt> narrows down the source of problems in LLVM tools and
38passes. It can be used to debug three types of failures: optimizer crashes,
39miscompilations by optimizers, or bad native code generation (including problems
40in the static and JIT compilers). It aims to reduce large test cases to small,
41useful ones. For example, if <tt>opt</tt> crashes while optimizing a
42file, it will identify the optimization (or combination of optimizations) that
43causes the crash, and reduce the file down to a small example which triggers the
44crash.</p>
45
46<p>For detailed case scenarios, such as debugging <tt>opt</tt>,
47<tt>llvm-ld</tt>, or one of the LLVM code generators, see <a
48href="HowToSubmitABug.html">How To Submit a Bug Report document</a>.</p>
49
50</div>
51
52<!-- *********************************************************************** -->
53<div class="doc_section">
54<a name="design">Design Philosophy</a>
55</div>
56<!-- *********************************************************************** -->
57
58<div class="doc_text">
59
60<p><tt>bugpoint</tt> is designed to be a useful tool without requiring any
61hooks into the LLVM infrastructure at all. It works with any and all LLVM
62passes and code generators, and does not need to "know" how they work. Because
63of this, it may appear to do stupid things or miss obvious
64simplifications. <tt>bugpoint</tt> is also designed to trade off programmer
65time for computer time in the compiler-debugging process; consequently, it may
66take a long period of (unattended) time to reduce a test case, but we feel it
67is still worth it. Note that <tt>bugpoint</tt> is generally very quick unless
68debugging a miscompilation where each test of the program (which requires
69executing it) takes a long time.</p>
70
71</div>
72
73<!-- ======================================================================= -->
74<div class="doc_subsection">
75 <a name="autoselect">Automatic Debugger Selection</a>
76</div>
77
78<div class="doc_text">
79
80<p><tt>bugpoint</tt> reads each <tt>.bc</tt> or <tt>.ll</tt> file specified on
81the command line and links them together into a single module, called the test
82program. If any LLVM passes are specified on the command line, it runs these
83passes on the test program. If any of the passes crash, or if they produce
84malformed output (which causes the verifier to abort), <tt>bugpoint</tt> starts
85the <a href="#crashdebug">crash debugger</a>.</p>
86
87<p>Otherwise, if the <tt>-output</tt> option was not specified,
88<tt>bugpoint</tt> runs the test program with the C backend (which is assumed to
89generate good code) to generate a reference output. Once <tt>bugpoint</tt> has
90a reference output for the test program, it tries executing it with the
91selected code generator. If the selected code generator crashes,
92<tt>bugpoint</tt> starts the <a href="#crashdebug">crash debugger</a> on the
93code generator. Otherwise, if the resulting output differs from the reference
94output, it assumes the difference resulted from a code generator failure, and
95starts the <a href="#codegendebug">code generator debugger</a>.</p>
96
97<p>Finally, if the output of the selected code generator matches the reference
98output, <tt>bugpoint</tt> runs the test program after all of the LLVM passes
99have been applied to it. If its output differs from the reference output, it
100assumes the difference resulted from a failure in one of the LLVM passes, and
101enters the <a href="#miscompilationdebug">miscompilation debugger</a>.
102Otherwise, there is no problem <tt>bugpoint</tt> can debug.</p>
103
104</div>
105
106<!-- ======================================================================= -->
107<div class="doc_subsection">
108 <a name="crashdebug">Crash debugger</a>
109</div>
110
111<div class="doc_text">
112
113<p>If an optimizer or code generator crashes, <tt>bugpoint</tt> will try as hard
114as it can to reduce the list of passes (for optimizer crashes) and the size of
115the test program. First, <tt>bugpoint</tt> figures out which combination of
116optimizer passes triggers the bug. This is useful when debugging a problem
117exposed by <tt>opt</tt>, for example, because it runs over 38 passes.</p>
118
119<p>Next, <tt>bugpoint</tt> tries removing functions from the test program, to
120reduce its size. Usually it is able to reduce a test program to a single
121function, when debugging intraprocedural optimizations. Once the number of
122functions has been reduced, it attempts to delete various edges in the control
123flow graph, to reduce the size of the function as much as possible. Finally,
124<tt>bugpoint</tt> deletes any individual LLVM instructions whose absence does
125not eliminate the failure. At the end, <tt>bugpoint</tt> should tell you what
126passes crash, give you a bitcode file, and give you instructions on how to
127reproduce the failure with <tt>opt</tt> or <tt>llc</tt>.</p>
128
129</div>
130
131<!-- ======================================================================= -->
132<div class="doc_subsection">
133 <a name="codegendebug">Code generator debugger</a>
134</div>
135
136<div class="doc_text">
137
138<p>The code generator debugger attempts to narrow down the amount of code that
139is being miscompiled by the selected code generator. To do this, it takes the
140test program and partitions it into two pieces: one piece which it compiles
141with the C backend (into a shared object), and one piece which it runs with
142either the JIT or the static LLC compiler. It uses several techniques to
143reduce the amount of code pushed through the LLVM code generator, to reduce the
144potential scope of the problem. After it is finished, it emits two bitcode
145files (called "test" [to be compiled with the code generator] and "safe" [to be
146compiled with the C backend], respectively), and instructions for reproducing
147the problem. The code generator debugger assumes that the C backend produces
148good code.</p>
149
150</div>
151
152<!-- ======================================================================= -->
153<div class="doc_subsection">
154 <a name="miscompilationdebug">Miscompilation debugger</a>
155</div>
156
157<div class="doc_text">
158
159<p>The miscompilation debugger works similarly to the code generator debugger.
160It works by splitting the test program into two pieces, running the
161optimizations specified on one piece, linking the two pieces back together, and
162then executing the result. It attempts to narrow down the list of passes to
163the one (or few) which are causing the miscompilation, then reduce the portion
164of the test program which is being miscompiled. The miscompilation debugger
165assumes that the selected code generator is working properly.</p>
166
167</div>
168
169<!-- *********************************************************************** -->
170<div class="doc_section">
171 <a name="advice">Advice for using bugpoint</a>
172</div>
173<!-- *********************************************************************** -->
174
175<div class="doc_text">
176
177<tt>bugpoint</tt> can be a remarkably useful tool, but it sometimes works in
178non-obvious ways. Here are some hints and tips:<p>
179
180<ol>
181<li>In the code generator and miscompilation debuggers, <tt>bugpoint</tt> only
182 works with programs that have deterministic output. Thus, if the program
183 outputs <tt>argv[0]</tt>, the date, time, or any other "random" data,
184 <tt>bugpoint</tt> may misinterpret differences in these data, when output,
185 as the result of a miscompilation. Programs should be temporarily modified
186 to disable outputs that are likely to vary from run to run.
187
188<li>In the code generator and miscompilation debuggers, debugging will go
189 faster if you manually modify the program or its inputs to reduce the
190 runtime, but still exhibit the problem.
191
192<li><tt>bugpoint</tt> is extremely useful when working on a new optimization:
193 it helps track down regressions quickly. To avoid having to relink
194 <tt>bugpoint</tt> every time you change your optimization however, have
195 <tt>bugpoint</tt> dynamically load your optimization with the
196 <tt>-load</tt> option.
197
198<li><p><tt>bugpoint</tt> can generate a lot of output and run for a long period
199 of time. It is often useful to capture the output of the program to file.
200 For example, in the C shell, you can run:</p>
201
202<div class="doc_code">
203<p><tt>bugpoint ... |&amp; tee bugpoint.log</tt></p>
204</div>
205
206 <p>to get a copy of <tt>bugpoint</tt>'s output in the file
207 <tt>bugpoint.log</tt>, as well as on your terminal.</p>
208
209<li><tt>bugpoint</tt> cannot debug problems with the LLVM linker. If
210 <tt>bugpoint</tt> crashes before you see its "All input ok" message,
211 you might try <tt>llvm-link -v</tt> on the same set of input files. If
212 that also crashes, you may be experiencing a linker bug.
213
214<li>If your program is <b>supposed</b> to crash, <tt>bugpoint</tt> will be
215 confused. One way to deal with this is to cause bugpoint to ignore the exit
216 code from your program, by giving it the <tt>-check-exit-code=false</tt>
217 option.
218
219<li><tt>bugpoint</tt> is useful for proactively finding bugs in LLVM.
220 Invoking <tt>bugpoint</tt> with the <tt>-find-bugs</tt> option will cause
221 the list of specified optimizations to be randomized and applied to the
222 program. This process will repeat until a bug is found or the user
223 kills <tt>bugpoint</tt>.
224
225</ol>
226
227</div>
228
229<!-- *********************************************************************** -->
230
231<hr>
232<address>
233 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
234 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
235 <a href="http://validator.w3.org/check/referer"><img
236 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
237
238 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
239 <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br>
240 Last modified: $Date$
241</address>
242
243</body>
244</html>