2003-10-20 19:57:13 +02:00
|
|
|
//===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
|
2005-04-22 02:00:37 +02:00
|
|
|
//
|
2003-10-20 19:47:21 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-22 02:00:37 +02:00
|
|
|
//
|
2003-10-20 19:47:21 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-11-20 23:28:10 +01:00
|
|
|
//
|
|
|
|
// This program is an automated compiler debugger tool. It is used to narrow
|
|
|
|
// down miscompilations and crash problems to a specific pass in the compiler,
|
|
|
|
// and the specific Module or Function input that is causing the problem.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "BugDriver.h"
|
2006-06-07 00:30:59 +02:00
|
|
|
#include "ToolRunner.h"
|
2006-08-21 07:34:03 +02:00
|
|
|
#include "llvm/LinkAllPasses.h"
|
2002-11-20 23:28:10 +01:00
|
|
|
#include "llvm/Support/PassNameParser.h"
|
2004-09-02 00:55:40 +02:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/PluginLoader.h"
|
2004-12-27 07:18:02 +01:00
|
|
|
#include "llvm/System/Process.h"
|
2004-05-27 07:41:36 +02:00
|
|
|
#include "llvm/System/Signals.h"
|
2006-06-08 01:06:50 +02:00
|
|
|
#include "llvm/LinkAllVMCore.h"
|
2003-11-11 23:41:34 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
2005-12-22 21:02:55 +01:00
|
|
|
// AsChild - Specifies that this invocation of bugpoint is being generated
|
|
|
|
// from a parent process. It is not intended to be used by users so the
|
|
|
|
// option is hidden.
|
|
|
|
static cl::opt<bool>
|
2006-08-15 18:40:49 +02:00
|
|
|
AsChild("as-child", cl::desc("Run bugpoint as child process"),
|
|
|
|
cl::ReallyHidden);
|
|
|
|
|
|
|
|
static cl::opt<bool>
|
|
|
|
FindBugs("find-bugs", cl::desc("Run many different optimization sequences"
|
|
|
|
"on program to find bugs"), cl::init(false));
|
2005-12-22 21:02:55 +01:00
|
|
|
|
2002-11-20 23:28:10 +01:00
|
|
|
static cl::list<std::string>
|
|
|
|
InputFilenames(cl::Positional, cl::OneOrMore,
|
|
|
|
cl::desc("<input llvm ll/bc files>"));
|
|
|
|
|
2006-06-13 05:10:48 +02:00
|
|
|
static cl::opt<unsigned>
|
|
|
|
TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"),
|
|
|
|
cl::desc("Number of seconds program is allowed to run before it "
|
|
|
|
"is killed (default is 300s), 0 disables timeout"));
|
|
|
|
|
2002-11-20 23:28:10 +01:00
|
|
|
// The AnalysesList is automatically populated with registered Passes by the
|
|
|
|
// PassNameParser.
|
|
|
|
//
|
|
|
|
static cl::list<const PassInfo*, bool, PassNameParser>
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-24 20:17:43 +02:00
|
|
|
PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
|
2002-11-20 23:28:10 +01:00
|
|
|
|
2005-08-02 04:16:17 +02:00
|
|
|
/// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
|
|
|
|
bool llvm::BugpointIsInterrupted = false;
|
|
|
|
|
|
|
|
static void BugpointInterruptFunction() {
|
|
|
|
BugpointIsInterrupted = true;
|
|
|
|
}
|
|
|
|
|
2002-11-20 23:28:10 +01:00
|
|
|
int main(int argc, char **argv) {
|
2003-10-18 23:55:35 +02:00
|
|
|
cl::ParseCommandLineOptions(argc, argv,
|
|
|
|
" LLVM automatic testcase reducer. See\nhttp://"
|
2006-03-14 06:54:52 +01:00
|
|
|
"llvm.org/docs/CommandGuide/bugpoint.html"
|
2003-10-18 23:55:35 +02:00
|
|
|
" for more information.\n");
|
2004-08-29 21:28:55 +02:00
|
|
|
sys::PrintStackTraceOnErrorSignal();
|
2005-08-02 04:16:17 +02:00
|
|
|
sys::SetInterruptFunction(BugpointInterruptFunction);
|
|
|
|
|
2006-08-15 18:40:49 +02:00
|
|
|
BugDriver D(argv[0],AsChild,FindBugs,TimeoutValue);
|
2002-11-20 23:28:10 +01:00
|
|
|
if (D.addSources(InputFilenames)) return 1;
|
|
|
|
D.addPasses(PassList.begin(), PassList.end());
|
|
|
|
|
2003-09-12 22:42:57 +02:00
|
|
|
// Bugpoint has the ability of generating a plethora of core files, so to
|
2004-09-02 00:55:40 +02:00
|
|
|
// avoid filling up the disk, we prevent it
|
2004-12-27 07:18:02 +01:00
|
|
|
sys::Process::PreventCoreFiles();
|
2003-09-12 22:42:57 +02:00
|
|
|
|
2004-02-18 18:32:54 +01:00
|
|
|
try {
|
|
|
|
return D.run();
|
2004-02-18 21:22:11 +01:00
|
|
|
} catch (ToolExecutionError &TEE) {
|
2004-07-23 03:30:49 +02:00
|
|
|
std::cerr << "Tool execution error: " << TEE.what() << '\n';
|
2004-12-30 06:36:08 +01:00
|
|
|
} catch (const std::string& msg) {
|
|
|
|
std::cerr << argv[0] << ": " << msg << "\n";
|
2004-02-18 18:32:54 +01:00
|
|
|
} catch (...) {
|
|
|
|
std::cerr << "Whoops, an exception leaked out of bugpoint. "
|
|
|
|
<< "This is a bug in bugpoint!\n";
|
|
|
|
}
|
2004-12-30 06:36:08 +01:00
|
|
|
return 1;
|
2002-11-20 23:28:10 +01:00
|
|
|
}
|