bugpoint.cpp revision 195340
1193323Sed//===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This program is an automated compiler debugger tool. It is used to narrow 11193323Sed// down miscompilations and crash problems to a specific pass in the compiler, 12193323Sed// and the specific Module or Function input that is causing the problem. 13193323Sed// 14193323Sed//===----------------------------------------------------------------------===// 15193323Sed 16193323Sed#include "BugDriver.h" 17193323Sed#include "ToolRunner.h" 18193323Sed#include "llvm/LinkAllPasses.h" 19195340Sed#include "llvm/LLVMContext.h" 20193323Sed#include "llvm/Support/PassNameParser.h" 21193323Sed#include "llvm/Support/CommandLine.h" 22193323Sed#include "llvm/Support/ManagedStatic.h" 23193323Sed#include "llvm/Support/PluginLoader.h" 24193323Sed#include "llvm/Support/PrettyStackTrace.h" 25193323Sed#include "llvm/System/Process.h" 26193323Sed#include "llvm/System/Signals.h" 27193323Sed#include "llvm/LinkAllVMCore.h" 28193323Sed#include <iostream> 29193323Sedusing namespace llvm; 30193323Sed 31193323Sed// AsChild - Specifies that this invocation of bugpoint is being generated 32193323Sed// from a parent process. It is not intended to be used by users so the 33193323Sed// option is hidden. 34193323Sedstatic cl::opt<bool> 35193323SedAsChild("as-child", cl::desc("Run bugpoint as child process"), 36193323Sed cl::ReallyHidden); 37193323Sed 38193323Sedstatic cl::opt<bool> 39193323SedFindBugs("find-bugs", cl::desc("Run many different optimization sequences " 40193323Sed "on program to find bugs"), cl::init(false)); 41193323Sed 42193323Sedstatic cl::list<std::string> 43193323SedInputFilenames(cl::Positional, cl::OneOrMore, 44193323Sed cl::desc("<input llvm ll/bc files>")); 45193323Sed 46193323Sedstatic cl::opt<unsigned> 47193323SedTimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"), 48193323Sed cl::desc("Number of seconds program is allowed to run before it " 49193323Sed "is killed (default is 300s), 0 disables timeout")); 50193323Sed 51193323Sedstatic cl::opt<unsigned> 52193323SedMemoryLimit("mlimit", cl::init(100), cl::value_desc("MBytes"), 53193323Sed cl::desc("Maximum amount of memory to use. 0 disables check.")); 54193323Sed 55193323Sed// The AnalysesList is automatically populated with registered Passes by the 56193323Sed// PassNameParser. 57193323Sed// 58193323Sedstatic cl::list<const PassInfo*, bool, PassNameParser> 59193323SedPassList(cl::desc("Passes available:"), cl::ZeroOrMore); 60193323Sed 61193323Sed/// BugpointIsInterrupted - Set to true when the user presses ctrl-c. 62193323Sedbool llvm::BugpointIsInterrupted = false; 63193323Sed 64193323Sedstatic void BugpointInterruptFunction() { 65193323Sed BugpointIsInterrupted = true; 66193323Sed} 67193323Sed 68193323Sedint main(int argc, char **argv) { 69193323Sed llvm::sys::PrintStackTraceOnErrorSignal(); 70193323Sed llvm::PrettyStackTraceProgram X(argc, argv); 71193323Sed llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. 72193323Sed cl::ParseCommandLineOptions(argc, argv, 73193323Sed "LLVM automatic testcase reducer. See\nhttp://" 74193323Sed "llvm.org/cmds/bugpoint.html" 75193323Sed " for more information.\n"); 76193323Sed sys::SetInterruptFunction(BugpointInterruptFunction); 77195340Sed 78195340Sed LLVMContext Context; 79195340Sed BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit, Context); 80193323Sed if (D.addSources(InputFilenames)) return 1; 81193323Sed D.addPasses(PassList.begin(), PassList.end()); 82193323Sed 83193323Sed // Bugpoint has the ability of generating a plethora of core files, so to 84193323Sed // avoid filling up the disk, we prevent it 85193323Sed sys::Process::PreventCoreFiles(); 86193323Sed 87193323Sed try { 88193323Sed return D.run(); 89193323Sed } catch (ToolExecutionError &TEE) { 90193323Sed std::cerr << "Tool execution error: " << TEE.what() << '\n'; 91193323Sed } catch (const std::string& msg) { 92193323Sed std::cerr << argv[0] << ": " << msg << "\n"; 93193323Sed } catch (const std::bad_alloc &e) { 94193323Sed std::cerr << "Oh no, a bugpoint process ran out of memory!\n" 95193323Sed "To increase the allocation limits for bugpoint child\n" 96193323Sed "processes, use the -mlimit option.\n"; 97193323Sed } catch (const std::exception &e) { 98193323Sed std::cerr << "Whoops, a std::exception leaked out of bugpoint: " 99193323Sed << e.what() << "\n" 100193323Sed << "This is a bug in bugpoint!\n"; 101193323Sed } catch (...) { 102193323Sed std::cerr << "Whoops, an exception leaked out of bugpoint. " 103193323Sed << "This is a bug in bugpoint!\n"; 104193323Sed } 105193323Sed return 1; 106193323Sed} 107