blob: 57994bfe31652c35689ea50ae7eb63450ed0075b [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- 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 "llvm/Support/CommandLine.h"
17#include "llvm/Support/ManagedStatic.h"
18#include "llvm/System/Signals.h"
19#include <iostream>
20using namespace llvm;
21
22namespace {
23 // Command line options for specifying the program to debug and options to use
24 cl::opt<std::string>
25 InputFile(cl::desc("<program>"), cl::Positional, cl::init(""));
26
27 cl::list<std::string>
28 InputArgs("args", cl::Positional, cl::desc("<program and arguments>"),
29 cl::ZeroOrMore);
30
31 // Command line options to control various directory related stuff
32 cl::list<std::string>
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));
37
38 cl::opt<std::string>
39 WorkingDirectory("cd", cl::desc("Use directory as current working directory"),
40 cl::value_desc("directory"));
41
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));
46}
47
48//===----------------------------------------------------------------------===//
49// main Driver function
50//
51int 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";
54 try {
55 cl::ParseCommandLineOptions(argc, argv,
56 " llvm source-level debugger\n");
57 sys::PrintStackTraceOnErrorSignal();
58
59 if (!Quiet)
60 std::cout << "llvm-db: The LLVM source-level debugger\n";
61
62 // Merge Inputfile and InputArgs into the InputArgs list...
63 if (!InputFile.empty() && InputArgs.empty())
64 InputArgs.push_back(InputFile);
65
66 // Create the CLI debugger...
67 CLIDebugger D;
68
69 // Initialize the debugger with the command line options we read...
70 Debugger &Dbg = D.getDebugger();
71
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]);
77
78 if (!InputArgs.empty()) {
79 try {
80 D.fileCommand(InputArgs[0]);
81 } catch (const std::string &Error) {
82 std::cout << "Error: " << Error << "\n";
83 }
84
85 Dbg.setProgramArguments(InputArgs.begin()+1, InputArgs.end());
86 }
87
88 // Now that we have initialized the debugger, run it.
89 return D.run();
90 } catch (const std::string& msg) {
91 std::cerr << argv[0] << ": " << msg << "\n";
92 } catch (...) {
93 std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
94 }
95 return 1;
96}