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 "llvm/Analysis/LinkAllAnalyses.h"
18 #include "llvm/Transforms/LinkAllPasses.h"
19 #include "llvm/Support/PassNameParser.h"
20 #include "llvm/Support/ToolRunner.h"
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/PluginLoader.h"
23 #include "llvm/System/Process.h"
24 #include "llvm/System/Signals.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"),
34 static cl::list<std::string>
35 InputFilenames(cl::Positional, cl::OneOrMore,
36 cl::desc("<input llvm ll/bc files>"));
38 // The AnalysesList is automatically populated with registered Passes by the
41 static cl::list<const PassInfo*, bool, PassNameParser>
42 PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
44 /// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
45 bool llvm::BugpointIsInterrupted = false;
47 static void BugpointInterruptFunction() {
48 BugpointIsInterrupted = true;
51 int main(int argc, char **argv) {
52 cl::ParseCommandLineOptions(argc, argv,
53 " LLVM automatic testcase reducer. See\nhttp://"
54 "llvm.org/docs/CommandGuide/bugpoint.html"
55 " for more information.\n");
56 sys::PrintStackTraceOnErrorSignal();
57 sys::SetInterruptFunction(BugpointInterruptFunction);
59 BugDriver D(argv[0],AsChild);
60 if (D.addSources(InputFilenames)) return 1;
61 D.addPasses(PassList.begin(), PassList.end());
63 // Bugpoint has the ability of generating a plethora of core files, so to
64 // avoid filling up the disk, we prevent it
65 sys::Process::PreventCoreFiles();
69 } catch (ToolExecutionError &TEE) {
70 std::cerr << "Tool execution error: " << TEE.what() << '\n';
71 } catch (const std::string& msg) {
72 std::cerr << argv[0] << ": " << msg << "\n";
74 std::cerr << "Whoops, an exception leaked out of bugpoint. "
75 << "This is a bug in bugpoint!\n";