blob: 236467550407a7b8adbda997da56b7b21f40be6f [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5f5a5732007-12-29 20:44:31 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
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.
13//
14//===----------------------------------------------------------------------===//
15
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"
26#include <iostream>
27using namespace llvm;
28
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
31// option is hidden.
32static cl::opt<bool>
33AsChild("as-child", cl::desc("Run bugpoint as child process"),
34 cl::ReallyHidden);
35
36static cl::opt<bool>
Dan Gohmand56bb2f2008-02-18 17:15:45 +000037FindBugs("find-bugs", cl::desc("Run many different optimization sequences "
Dan Gohmanf17a25c2007-07-18 16:29:46 +000038 "on program to find bugs"), cl::init(false));
39
40static cl::list<std::string>
41InputFilenames(cl::Positional, cl::OneOrMore,
42 cl::desc("<input llvm ll/bc files>"));
43
44static cl::opt<unsigned>
45TimeoutValue("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"));
48
49static cl::opt<unsigned>
50MemoryLimit("mlimit", cl::init(100), cl::value_desc("MBytes"),
51 cl::desc("Maximum amount of memory to use. 0 disables check."));
52
53// The AnalysesList is automatically populated with registered Passes by the
54// PassNameParser.
55//
56static cl::list<const PassInfo*, bool, PassNameParser>
57PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
58
59/// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
60bool llvm::BugpointIsInterrupted = false;
61
62static void BugpointInterruptFunction() {
63 BugpointIsInterrupted = true;
64}
65
66int main(int argc, char **argv) {
67 llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
68 cl::ParseCommandLineOptions(argc, argv,
Dan Gohman6099df82007-10-08 15:45:12 +000069 "LLVM automatic testcase reducer. See\nhttp://"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000070 "llvm.org/docs/CommandGuide/bugpoint.html"
71 " for more information.\n");
72 sys::PrintStackTraceOnErrorSignal();
73 sys::SetInterruptFunction(BugpointInterruptFunction);
74
75 BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit);
76 if (D.addSources(InputFilenames)) return 1;
77 D.addPasses(PassList.begin(), PassList.end());
78
79 // Bugpoint has the ability of generating a plethora of core files, so to
80 // avoid filling up the disk, we prevent it
81 sys::Process::PreventCoreFiles();
82
83 try {
84 return D.run();
85 } catch (ToolExecutionError &TEE) {
86 std::cerr << "Tool execution error: " << TEE.what() << '\n';
87 } catch (const std::string& msg) {
88 std::cerr << argv[0] << ": " << msg << "\n";
89 } catch (...) {
90 std::cerr << "Whoops, an exception leaked out of bugpoint. "
91 << "This is a bug in bugpoint!\n";
92 }
93 return 1;
94}