2004-01-05 06:27:31 +01:00
|
|
|
//===- llvm-db.cpp - LLVM Debugger ----------------------------------------===//
|
2005-04-22 02:00:37 +02:00
|
|
|
//
|
2004-01-05 06:27:31 +01:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:44:31 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 02:00:37 +02:00
|
|
|
//
|
2004-01-05 06:27:31 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This utility implements a simple text-mode front-end to the LLVM debugger
|
|
|
|
// library.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CLIDebugger.h"
|
2009-07-01 18:58:40 +02:00
|
|
|
#include "llvm/LLVMContext.h"
|
2004-09-02 00:55:40 +02:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2006-12-06 02:18:01 +01:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2009-03-06 06:34:10 +01:00
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
2004-05-27 07:41:36 +02:00
|
|
|
#include "llvm/System/Signals.h"
|
2004-01-05 06:27:31 +01:00
|
|
|
#include <iostream>
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
// Command line options for specifying the program to debug and options to use
|
|
|
|
cl::opt<std::string>
|
|
|
|
InputFile(cl::desc("<program>"), cl::Positional, cl::init(""));
|
|
|
|
|
|
|
|
cl::list<std::string>
|
|
|
|
InputArgs("args", cl::Positional, cl::desc("<program and arguments>"),
|
|
|
|
cl::ZeroOrMore);
|
|
|
|
|
|
|
|
// Command line options to control various directory related stuff
|
|
|
|
cl::list<std::string>
|
|
|
|
SourceDirectories("directory", cl::value_desc("directory"),
|
|
|
|
cl::desc("Add directory to the search for source files"));
|
|
|
|
cl::alias SDA("d", cl::desc("Alias for --directory"),
|
|
|
|
cl::aliasopt(SourceDirectories));
|
2005-04-22 02:00:37 +02:00
|
|
|
|
2004-01-05 06:27:31 +01:00
|
|
|
cl::opt<std::string>
|
|
|
|
WorkingDirectory("cd", cl::desc("Use directory as current working directory"),
|
|
|
|
cl::value_desc("directory"));
|
|
|
|
|
|
|
|
// Command line options specific to the llvm-db debugger driver
|
|
|
|
cl::opt<bool> Quiet("quiet", cl::desc("Do not print introductory messages"));
|
|
|
|
cl::alias QA1("silent", cl::desc("Alias for -quiet"), cl::aliasopt(Quiet));
|
|
|
|
cl::alias QA2("q", cl::desc("Alias for -quiet"), cl::aliasopt(Quiet));
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// main Driver function
|
|
|
|
//
|
|
|
|
int main(int argc, char **argv, char * const *envp) {
|
2009-03-06 06:34:10 +01:00
|
|
|
// Print a stack trace if we signal out.
|
|
|
|
sys::PrintStackTraceOnErrorSignal();
|
|
|
|
PrettyStackTraceProgram X(argc, argv);
|
|
|
|
|
2009-07-16 00:16:10 +02:00
|
|
|
LLVMContext &Context = getGlobalContext();
|
2009-03-06 06:34:10 +01:00
|
|
|
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
2006-04-18 07:26:10 +02:00
|
|
|
std::cout << "NOTE: llvm-db is known useless right now.\n";
|
2004-12-30 06:36:08 +01:00
|
|
|
try {
|
|
|
|
cl::ParseCommandLineOptions(argc, argv,
|
2007-10-08 17:45:12 +02:00
|
|
|
"llvm source-level debugger\n");
|
2004-01-05 06:27:31 +01:00
|
|
|
|
2004-12-30 06:36:08 +01:00
|
|
|
if (!Quiet)
|
|
|
|
std::cout << "llvm-db: The LLVM source-level debugger\n";
|
2004-01-05 06:27:31 +01:00
|
|
|
|
2004-12-30 06:36:08 +01:00
|
|
|
// Merge Inputfile and InputArgs into the InputArgs list...
|
|
|
|
if (!InputFile.empty() && InputArgs.empty())
|
|
|
|
InputArgs.push_back(InputFile);
|
2004-01-05 06:27:31 +01:00
|
|
|
|
2004-12-30 06:36:08 +01:00
|
|
|
// Create the CLI debugger...
|
2009-07-01 23:22:36 +02:00
|
|
|
CLIDebugger D(Context);
|
2004-01-05 06:27:31 +01:00
|
|
|
|
2004-12-30 06:36:08 +01:00
|
|
|
// Initialize the debugger with the command line options we read...
|
|
|
|
Debugger &Dbg = D.getDebugger();
|
2004-01-05 06:27:31 +01:00
|
|
|
|
2004-12-30 06:36:08 +01:00
|
|
|
// Initialize the debugger environment.
|
|
|
|
Dbg.initializeEnvironment(envp);
|
|
|
|
Dbg.setWorkingDirectory(WorkingDirectory);
|
|
|
|
for (unsigned i = 0, e = SourceDirectories.size(); i != e; ++i)
|
|
|
|
D.addSourceDirectory(SourceDirectories[i]);
|
2005-04-22 02:00:37 +02:00
|
|
|
|
2004-12-30 06:36:08 +01:00
|
|
|
if (!InputArgs.empty()) {
|
|
|
|
try {
|
|
|
|
D.fileCommand(InputArgs[0]);
|
|
|
|
} catch (const std::string &Error) {
|
|
|
|
std::cout << "Error: " << Error << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
Dbg.setProgramArguments(InputArgs.begin()+1, InputArgs.end());
|
2004-01-05 06:27:31 +01:00
|
|
|
}
|
|
|
|
|
2004-12-30 06:36:08 +01:00
|
|
|
// Now that we have initialized the debugger, run it.
|
|
|
|
return D.run();
|
|
|
|
} catch (const std::string& msg) {
|
2009-07-15 18:35:29 +02:00
|
|
|
errs() << argv[0] << ": " << msg << "\n";
|
2004-12-30 06:36:08 +01:00
|
|
|
} catch (...) {
|
2009-07-15 18:35:29 +02:00
|
|
|
errs() << argv[0] << ": Unexpected unknown exception occurred.\n";
|
2004-01-05 06:27:31 +01:00
|
|
|
}
|
2004-12-30 06:36:08 +01:00
|
|
|
return 1;
|
2004-01-05 06:27:31 +01:00
|
|
|
}
|