1 //===- llvm-db.cpp - LLVM Debugger ----------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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/Support/CommandLine.h"
17 #include "llvm/Support/ManagedStatic.h"
18 #include "llvm/System/Signals.h"
23 // Command line options for specifying the program to debug and options to use
25 InputFile(cl::desc("<program>"), cl::Positional, cl::init(""));
28 InputArgs("args", cl::Positional, cl::desc("<program and arguments>"),
31 // Command line options to control various directory related stuff
33 SourceDirectories("directory", cl::value_desc("directory"),
34 cl::desc("Add directory to the search for source files"));
35 cl::alias SDA("d", cl::desc("Alias for --directory"),
36 cl::aliasopt(SourceDirectories));
39 WorkingDirectory("cd", cl::desc("Use directory as current working directory"),
40 cl::value_desc("directory"));
42 // Command line options specific to the llvm-db debugger driver
43 cl::opt<bool> Quiet("quiet", cl::desc("Do not print introductory messages"));
44 cl::alias QA1("silent", cl::desc("Alias for -quiet"), cl::aliasopt(Quiet));
45 cl::alias QA2("q", cl::desc("Alias for -quiet"), cl::aliasopt(Quiet));
48 //===----------------------------------------------------------------------===//
49 // main Driver function
51 int main(int argc, char **argv, char * const *envp) {
52 llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
53 std::cout << "NOTE: llvm-db is known useless right now.\n";
55 cl::ParseCommandLineOptions(argc, argv,
56 " llvm source-level debugger\n");
57 sys::PrintStackTraceOnErrorSignal();
60 std::cout << "llvm-db: The LLVM source-level debugger\n";
62 // Merge Inputfile and InputArgs into the InputArgs list...
63 if (!InputFile.empty() && InputArgs.empty())
64 InputArgs.push_back(InputFile);
66 // Create the CLI debugger...
69 // Initialize the debugger with the command line options we read...
70 Debugger &Dbg = D.getDebugger();
72 // Initialize the debugger environment.
73 Dbg.initializeEnvironment(envp);
74 Dbg.setWorkingDirectory(WorkingDirectory);
75 for (unsigned i = 0, e = SourceDirectories.size(); i != e; ++i)
76 D.addSourceDirectory(SourceDirectories[i]);
78 if (!InputArgs.empty()) {
80 D.fileCommand(InputArgs[0]);
81 } catch (const std::string &Error) {
82 std::cout << "Error: " << Error << "\n";
85 Dbg.setProgramArguments(InputArgs.begin()+1, InputArgs.end());
88 // Now that we have initialized the debugger, run it.
90 } catch (const std::string& msg) {
91 std::cerr << argv[0] << ": " << msg << "\n";
93 std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";