1 //===- llvm-db.cpp - LLVM Debugger ----------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This utility implements a simple text-mode front-end to the LLVM debugger
13 //===----------------------------------------------------------------------===//
15 #include "CLIDebugger.h"
16 #include "llvm/LLVMContext.h"
17 #include "llvm/Support/CommandLine.h"
18 #include "llvm/Support/ManagedStatic.h"
19 #include "llvm/Support/PrettyStackTrace.h"
20 #include "llvm/System/Signals.h"
25 // Command line options for specifying the program to debug and options to use
27 InputFile(cl::desc("<program>"), cl::Positional, cl::init(""));
30 InputArgs("args", cl::Positional, cl::desc("<program and arguments>"),
33 // Command line options to control various directory related stuff
35 SourceDirectories("directory", cl::value_desc("directory"),
36 cl::desc("Add directory to the search for source files"));
37 cl::alias SDA("d", cl::desc("Alias for --directory"),
38 cl::aliasopt(SourceDirectories));
41 WorkingDirectory("cd", cl::desc("Use directory as current working directory"),
42 cl::value_desc("directory"));
44 // Command line options specific to the llvm-db debugger driver
45 cl::opt<bool> Quiet("quiet", cl::desc("Do not print introductory messages"));
46 cl::alias QA1("silent", cl::desc("Alias for -quiet"), cl::aliasopt(Quiet));
47 cl::alias QA2("q", cl::desc("Alias for -quiet"), cl::aliasopt(Quiet));
50 //===----------------------------------------------------------------------===//
51 // main Driver function
53 int main(int argc, char **argv, char * const *envp) {
54 // Print a stack trace if we signal out.
55 sys::PrintStackTraceOnErrorSignal();
56 PrettyStackTraceProgram X(argc, argv);
59 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
60 std::cout << "NOTE: llvm-db is known useless right now.\n";
62 cl::ParseCommandLineOptions(argc, argv,
63 "llvm source-level debugger\n");
66 std::cout << "llvm-db: The LLVM source-level debugger\n";
68 // Merge Inputfile and InputArgs into the InputArgs list...
69 if (!InputFile.empty() && InputArgs.empty())
70 InputArgs.push_back(InputFile);
72 // Create the CLI debugger...
73 CLIDebugger D(&Context);
75 // Initialize the debugger with the command line options we read...
76 Debugger &Dbg = D.getDebugger();
78 // Initialize the debugger environment.
79 Dbg.initializeEnvironment(envp);
80 Dbg.setWorkingDirectory(WorkingDirectory);
81 for (unsigned i = 0, e = SourceDirectories.size(); i != e; ++i)
82 D.addSourceDirectory(SourceDirectories[i]);
84 if (!InputArgs.empty()) {
86 D.fileCommand(InputArgs[0]);
87 } catch (const std::string &Error) {
88 std::cout << "Error: " << Error << "\n";
91 Dbg.setProgramArguments(InputArgs.begin()+1, InputArgs.end());
94 // Now that we have initialized the debugger, run it.
96 } catch (const std::string& msg) {
97 std::cerr << argv[0] << ": " << msg << "\n";
99 std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";