1 //===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This program is an automated compiler debugger tool. It is used to narrow
11 // down miscompilations and crash problems to a specific pass in the compiler,
12 // and the specific Module or Function input that is causing the problem.
14 //===----------------------------------------------------------------------===//
16 #include "BugDriver.h"
17 #include "ToolRunner.h"
18 #include "llvm/LinkAllPasses.h"
19 #include "llvm/Support/PassNameParser.h"
20 #include "llvm/Support/CommandLine.h"
21 #include "llvm/Support/PluginLoader.h"
22 #include "llvm/System/Process.h"
23 #include "llvm/System/Signals.h"
24 #include "llvm/LinkAllVMCore.h"
28 // AsChild - Specifies that this invocation of bugpoint is being generated
29 // from a parent process. It is not intended to be used by users so the
32 AsChild("as-child", cl::desc("Run bugpoint as child process"),
36 FindBugs("find-bugs", cl::desc("Run many different optimization sequences"
37 "on program to find bugs"), cl::init(false));
39 static cl::list<std::string>
40 InputFilenames(cl::Positional, cl::OneOrMore,
41 cl::desc("<input llvm ll/bc files>"));
43 static cl::opt<unsigned>
44 TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"),
45 cl::desc("Number of seconds program is allowed to run before it "
46 "is killed (default is 300s), 0 disables timeout"));
48 // The AnalysesList is automatically populated with registered Passes by the
51 static cl::list<const PassInfo*, bool, PassNameParser>
52 PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
54 /// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
55 bool llvm::BugpointIsInterrupted = false;
57 static void BugpointInterruptFunction() {
58 BugpointIsInterrupted = true;
61 int main(int argc, char **argv) {
62 cl::ParseCommandLineOptions(argc, argv,
63 " LLVM automatic testcase reducer. See\nhttp://"
64 "llvm.org/docs/CommandGuide/bugpoint.html"
65 " for more information.\n");
66 sys::PrintStackTraceOnErrorSignal();
67 sys::SetInterruptFunction(BugpointInterruptFunction);
69 BugDriver D(argv[0],AsChild,FindBugs,TimeoutValue);
70 if (D.addSources(InputFilenames)) return 1;
71 D.addPasses(PassList.begin(), PassList.end());
73 // Bugpoint has the ability of generating a plethora of core files, so to
74 // avoid filling up the disk, we prevent it
75 sys::Process::PreventCoreFiles();
79 } catch (ToolExecutionError &TEE) {
80 std::cerr << "Tool execution error: " << TEE.what() << '\n';
81 } catch (const std::string& msg) {
82 std::cerr << argv[0] << ": " << msg << "\n";
84 std::cerr << "Whoops, an exception leaked out of bugpoint. "
85 << "This is a bug in bugpoint!\n";