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/ManagedStatic.h"
22 #include "llvm/Support/PluginLoader.h"
23 #include "llvm/System/Process.h"
24 #include "llvm/System/Signals.h"
25 #include "llvm/LinkAllVMCore.h"
29 // AsChild - Specifies that this invocation of bugpoint is being generated
30 // from a parent process. It is not intended to be used by users so the
33 AsChild("as-child", cl::desc("Run bugpoint as child process"),
37 FindBugs("find-bugs", cl::desc("Run many different optimization sequences"
38 "on program to find bugs"), cl::init(false));
40 static cl::list<std::string>
41 InputFilenames(cl::Positional, cl::OneOrMore,
42 cl::desc("<input llvm ll/bc files>"));
44 static cl::opt<unsigned>
45 TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"),
46 cl::desc("Number of seconds program is allowed to run before it "
47 "is killed (default is 300s), 0 disables timeout"));
49 // The AnalysesList is automatically populated with registered Passes by the
52 static cl::list<const PassInfo*, bool, PassNameParser>
53 PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
55 /// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
56 bool llvm::BugpointIsInterrupted = false;
58 static void BugpointInterruptFunction() {
59 BugpointIsInterrupted = true;
62 int main(int argc, char **argv) {
63 llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
64 cl::ParseCommandLineOptions(argc, argv,
65 " LLVM automatic testcase reducer. See\nhttp://"
66 "llvm.org/docs/CommandGuide/bugpoint.html"
67 " for more information.\n");
68 sys::PrintStackTraceOnErrorSignal();
69 sys::SetInterruptFunction(BugpointInterruptFunction);
71 BugDriver D(argv[0],AsChild,FindBugs,TimeoutValue);
72 if (D.addSources(InputFilenames)) return 1;
73 D.addPasses(PassList.begin(), PassList.end());
75 // Bugpoint has the ability of generating a plethora of core files, so to
76 // avoid filling up the disk, we prevent it
77 sys::Process::PreventCoreFiles();
81 } catch (ToolExecutionError &TEE) {
82 std::cerr << "Tool execution error: " << TEE.what() << '\n';
83 } catch (const std::string& msg) {
84 std::cerr << argv[0] << ": " << msg << "\n";
86 std::cerr << "Whoops, an exception leaked out of bugpoint. "
87 << "This is a bug in bugpoint!\n";