Chris Lattner | 7af5c12 | 2004-01-05 05:27:31 +0000 | [diff] [blame^] | 1 | //===- llvm-db.cpp - LLVM Debugger ----------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 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. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This utility implements a simple text-mode front-end to the LLVM debugger |
| 11 | // library. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "CLIDebugger.h" |
| 16 | #include "Support/CommandLine.h" |
| 17 | #include <iostream> |
| 18 | |
| 19 | using namespace llvm; |
| 20 | |
| 21 | namespace { |
| 22 | // Command line options for specifying the program to debug and options to use |
| 23 | cl::opt<std::string> |
| 24 | InputFile(cl::desc("<program>"), cl::Positional, cl::init("")); |
| 25 | |
| 26 | cl::list<std::string> |
| 27 | InputArgs("args", cl::Positional, cl::desc("<program and arguments>"), |
| 28 | cl::ZeroOrMore); |
| 29 | |
| 30 | // Command line options to control various directory related stuff |
| 31 | cl::list<std::string> |
| 32 | SourceDirectories("directory", cl::value_desc("directory"), |
| 33 | cl::desc("Add directory to the search for source files")); |
| 34 | cl::alias SDA("d", cl::desc("Alias for --directory"), |
| 35 | cl::aliasopt(SourceDirectories)); |
| 36 | |
| 37 | cl::opt<std::string> |
| 38 | WorkingDirectory("cd", cl::desc("Use directory as current working directory"), |
| 39 | cl::value_desc("directory")); |
| 40 | |
| 41 | // Command line options specific to the llvm-db debugger driver |
| 42 | cl::opt<bool> Version("version", cl::desc("Print version number and quit")); |
| 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)); |
| 46 | } |
| 47 | |
| 48 | //===----------------------------------------------------------------------===// |
| 49 | // main Driver function |
| 50 | // |
| 51 | int main(int argc, char **argv, char * const *envp) { |
| 52 | cl::ParseCommandLineOptions(argc, argv, |
| 53 | " llvm source-level debugger\n"); |
| 54 | |
| 55 | if (Version || !Quiet) { |
| 56 | std::cout << "llvm-db: The LLVM source-level debugger\n"; |
| 57 | if (Version) return 1; |
| 58 | } |
| 59 | |
| 60 | // Merge Inputfile and InputArgs into the InputArgs list... |
| 61 | if (!InputFile.empty() && InputArgs.empty()) |
| 62 | InputArgs.push_back(InputFile); |
| 63 | |
| 64 | // Create the CLI debugger... |
| 65 | CLIDebugger D; |
| 66 | |
| 67 | // Initialize the debugger with the command line options we read... |
| 68 | Debugger &Dbg = D.getDebugger(); |
| 69 | |
| 70 | // Initialize the debugger environment. |
| 71 | Dbg.initializeEnvironment(envp); |
| 72 | Dbg.setWorkingDirectory(WorkingDirectory); |
| 73 | for (unsigned i = 0, e = SourceDirectories.size(); i != e; ++i) |
| 74 | D.addSourceDirectory(SourceDirectories[i]); |
| 75 | |
| 76 | if (!InputArgs.empty()) { |
| 77 | try { |
| 78 | D.fileCommand(InputArgs[0]); |
| 79 | } catch (const std::string &Error) { |
| 80 | std::cout << "Error: " << Error << "\n"; |
| 81 | } |
| 82 | |
| 83 | Dbg.setProgramArguments(InputArgs.begin()+1, InputArgs.end()); |
| 84 | } |
| 85 | |
| 86 | // Now that we have initialized the debugger, run it. |
| 87 | return D.run(); |
| 88 | } |