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