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