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"
27 // AsChild - Specifies that this invocation of bugpoint is being generated
28 // from a parent process. It is not intended to be used by users so the
31 AsChild("as-child", cl::desc("Run bugpoint as child process"),
35 FindBugs("find-bugs", cl::desc("Run many different optimization sequences"
36 "on program to find bugs"), cl::init(false));
38 static cl::list<std::string>
39 InputFilenames(cl::Positional, cl::OneOrMore,
40 cl::desc("<input llvm ll/bc files>"));
42 static cl::opt<unsigned>
43 TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"),
44 cl::desc("Number of seconds program is allowed to run before it "
45 "is killed (default is 300s), 0 disables timeout"));
47 // The AnalysesList is automatically populated with registered Passes by the
50 static cl::list<const PassInfo*, bool, PassNameParser>
51 PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
53 /// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
54 bool llvm::BugpointIsInterrupted = false;
56 static void BugpointInterruptFunction() {
57 BugpointIsInterrupted = true;
60 int main(int argc, char **argv) {
61 cl::ParseCommandLineOptions(argc, argv,
62 " LLVM automatic testcase reducer. See\nhttp://"
63 "llvm.org/docs/CommandGuide/bugpoint.html"
64 " for more information.\n");
65 sys::PrintStackTraceOnErrorSignal();
66 sys::SetInterruptFunction(BugpointInterruptFunction);
68 BugDriver D(argv[0],AsChild,FindBugs,TimeoutValue);
69 if (D.addSources(InputFilenames)) return 1;
70 D.addPasses(PassList.begin(), PassList.end());
72 // Bugpoint has the ability of generating a plethora of core files, so to
73 // avoid filling up the disk, we prevent it
74 sys::Process::PreventCoreFiles();
78 } catch (ToolExecutionError &TEE) {
79 std::cerr << "Tool execution error: " << TEE.what() << '\n';
80 } catch (const std::string& msg) {
81 std::cerr << argv[0] << ": " << msg << "\n";
83 std::cerr << "Whoops, an exception leaked out of bugpoint. "
84 << "This is a bug in bugpoint!\n";