Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5f5a573 | 2007-12-29 20:44:31 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 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> |
| 27 | using 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. |
| 32 | static cl::opt<bool> |
| 33 | AsChild("as-child", cl::desc("Run bugpoint as child process"), |
| 34 | cl::ReallyHidden); |
| 35 | |
| 36 | static cl::opt<bool> |
Dan Gohman | d56bb2f | 2008-02-18 17:15:45 +0000 | [diff] [blame] | 37 | FindBugs("find-bugs", cl::desc("Run many different optimization sequences " |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 38 | "on program to find bugs"), cl::init(false)); |
| 39 | |
| 40 | static cl::list<std::string> |
| 41 | InputFilenames(cl::Positional, cl::OneOrMore, |
| 42 | cl::desc("<input llvm ll/bc files>")); |
| 43 | |
| 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")); |
| 48 | |
| 49 | static cl::opt<unsigned> |
| 50 | MemoryLimit("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 | // |
| 56 | static cl::list<const PassInfo*, bool, PassNameParser> |
| 57 | PassList(cl::desc("Passes available:"), cl::ZeroOrMore); |
| 58 | |
| 59 | /// BugpointIsInterrupted - Set to true when the user presses ctrl-c. |
| 60 | bool llvm::BugpointIsInterrupted = false; |
| 61 | |
| 62 | static void BugpointInterruptFunction() { |
| 63 | BugpointIsInterrupted = true; |
| 64 | } |
| 65 | |
| 66 | int main(int argc, char **argv) { |
| 67 | llvm_shutdown_obj X; // Call llvm_shutdown() on exit. |
| 68 | cl::ParseCommandLineOptions(argc, argv, |
Dan Gohman | 6099df8 | 2007-10-08 15:45:12 +0000 | [diff] [blame] | 69 | "LLVM automatic testcase reducer. See\nhttp://" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 70 | "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 | } |