1 //===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 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/LLVMContext.h" 20 #include "llvm/Support/PassNameParser.h" 21 #include "llvm/Support/CommandLine.h" 22 #include "llvm/Support/ManagedStatic.h" 23 #include "llvm/Support/PluginLoader.h" 24 #include "llvm/Support/PrettyStackTrace.h" 25 #include "llvm/System/Process.h" 26 #include "llvm/System/Signals.h" 27 #include "llvm/LinkAllVMCore.h" 28 #include <iostream> 29 using namespace llvm; 30 31 // AsChild - Specifies that this invocation of bugpoint is being generated 32 // from a parent process. It is not intended to be used by users so the 33 // option is hidden. 34 static cl::opt<bool> 35 AsChild("as-child", cl::desc("Run bugpoint as child process"), 36 cl::ReallyHidden); 37 38 static cl::opt<bool> 39 FindBugs("find-bugs", cl::desc("Run many different optimization sequences " 40 "on program to find bugs"), cl::init(false)); 41 42 static cl::list<std::string> 43 InputFilenames(cl::Positional, cl::OneOrMore, 44 cl::desc("<input llvm ll/bc files>")); 45 46 static cl::opt<unsigned> 47 TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"), 48 cl::desc("Number of seconds program is allowed to run before it " 49 "is killed (default is 300s), 0 disables timeout")); 50 51 static cl::opt<unsigned> 52 MemoryLimit("mlimit", cl::init(100), cl::value_desc("MBytes"), 53 cl::desc("Maximum amount of memory to use. 0 disables check.")); 54 55 // The AnalysesList is automatically populated with registered Passes by the 56 // PassNameParser. 57 // 58 static cl::list<const PassInfo*, bool, PassNameParser> 59 PassList(cl::desc("Passes available:"), cl::ZeroOrMore); 60 61 /// BugpointIsInterrupted - Set to true when the user presses ctrl-c. 62 bool llvm::BugpointIsInterrupted = false; 63 64 static void BugpointInterruptFunction() { 65 BugpointIsInterrupted = true; 66 } 67 68 int main(int argc, char **argv) { 69 llvm::sys::PrintStackTraceOnErrorSignal(); 70 llvm::PrettyStackTraceProgram X(argc, argv); 71 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. 72 cl::ParseCommandLineOptions(argc, argv, 73 "LLVM automatic testcase reducer. See\nhttp://" 74 "llvm.org/cmds/bugpoint.html" 75 " for more information.\n"); 76 sys::SetInterruptFunction(BugpointInterruptFunction); 77 78 LLVMContext Context; 79 BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit, Context); 80 if (D.addSources(InputFilenames)) return 1; 81 D.addPasses(PassList.begin(), PassList.end()); 82 83 // Bugpoint has the ability of generating a plethora of core files, so to 84 // avoid filling up the disk, we prevent it 85 sys::Process::PreventCoreFiles(); 86 87 try { 88 return D.run(); 89 } catch (ToolExecutionError &TEE) { 90 std::cerr << "Tool execution error: " << TEE.what() << '\n'; 91 } catch (const std::string& msg) { 92 std::cerr << argv[0] << ": " << msg << "\n"; 93 } catch (const std::bad_alloc &e) { 94 std::cerr << "Oh no, a bugpoint process ran out of memory!\n" 95 "To increase the allocation limits for bugpoint child\n" 96 "processes, use the -mlimit option.\n"; 97 } catch (const std::exception &e) { 98 std::cerr << "Whoops, a std::exception leaked out of bugpoint: " 99 << e.what() << "\n" 100 << "This is a bug in bugpoint!\n"; 101 } catch (...) { 102 std::cerr << "Whoops, an exception leaked out of bugpoint. " 103 << "This is a bug in bugpoint!\n"; 104 } 105 return 1; 106 } 107