blob: 140b8e40b6b9e1501a54bb3576083b5d91f74c8a [file] [log] [blame]
Chris Lattner7af5c122004-01-05 05:27:31 +00001//===- llvm-db.cpp - LLVM Debugger ----------------------------------------===//
Misha Brukman3da94ae2005-04-22 00:00:37 +00002//
Chris Lattner7af5c122004-01-05 05:27:31 +00003// 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.
Misha Brukman3da94ae2005-04-22 00:00:37 +00007//
Chris Lattner7af5c122004-01-05 05:27:31 +00008//===----------------------------------------------------------------------===//
9//
10// This utility implements a simple text-mode front-end to the LLVM debugger
11// library.
12//
13//===----------------------------------------------------------------------===//
14
15#include "CLIDebugger.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000016#include "llvm/Support/CommandLine.h"
17#include "llvm/Support/PluginLoader.h"
Chris Lattnerbed85ff2004-05-27 05:41:36 +000018#include "llvm/System/Signals.h"
Chris Lattner7af5c122004-01-05 05:27:31 +000019#include <iostream>
20
21using namespace llvm;
22
23namespace {
24 // Command line options for specifying the program to debug and options to use
25 cl::opt<std::string>
26 InputFile(cl::desc("<program>"), cl::Positional, cl::init(""));
27
28 cl::list<std::string>
29 InputArgs("args", cl::Positional, cl::desc("<program and arguments>"),
30 cl::ZeroOrMore);
31
32 // Command line options to control various directory related stuff
33 cl::list<std::string>
34 SourceDirectories("directory", cl::value_desc("directory"),
35 cl::desc("Add directory to the search for source files"));
36 cl::alias SDA("d", cl::desc("Alias for --directory"),
37 cl::aliasopt(SourceDirectories));
Misha Brukman3da94ae2005-04-22 00:00:37 +000038
Chris Lattner7af5c122004-01-05 05:27:31 +000039 cl::opt<std::string>
40 WorkingDirectory("cd", cl::desc("Use directory as current working directory"),
41 cl::value_desc("directory"));
42
43 // Command line options specific to the llvm-db debugger driver
Chris Lattner7af5c122004-01-05 05:27:31 +000044 cl::opt<bool> Quiet("quiet", cl::desc("Do not print introductory messages"));
45 cl::alias QA1("silent", cl::desc("Alias for -quiet"), cl::aliasopt(Quiet));
46 cl::alias QA2("q", cl::desc("Alias for -quiet"), cl::aliasopt(Quiet));
47}
48
49//===----------------------------------------------------------------------===//
50// main Driver function
51//
52int main(int argc, char **argv, char * const *envp) {
Reid Spencer1ef8bda2004-12-30 05:36:08 +000053 try {
54 cl::ParseCommandLineOptions(argc, argv,
55 " llvm source-level debugger\n");
56 sys::PrintStackTraceOnErrorSignal();
Chris Lattner7af5c122004-01-05 05:27:31 +000057
Reid Spencer1ef8bda2004-12-30 05:36:08 +000058 if (!Quiet)
59 std::cout << "llvm-db: The LLVM source-level debugger\n";
Chris Lattner7af5c122004-01-05 05:27:31 +000060
Reid Spencer1ef8bda2004-12-30 05:36:08 +000061 // Merge Inputfile and InputArgs into the InputArgs list...
62 if (!InputFile.empty() && InputArgs.empty())
63 InputArgs.push_back(InputFile);
Chris Lattner7af5c122004-01-05 05:27:31 +000064
Reid Spencer1ef8bda2004-12-30 05:36:08 +000065 // Create the CLI debugger...
66 CLIDebugger D;
Chris Lattner7af5c122004-01-05 05:27:31 +000067
Reid Spencer1ef8bda2004-12-30 05:36:08 +000068 // Initialize the debugger with the command line options we read...
69 Debugger &Dbg = D.getDebugger();
Chris Lattner7af5c122004-01-05 05:27:31 +000070
Reid Spencer1ef8bda2004-12-30 05:36:08 +000071 // Initialize the debugger environment.
72 Dbg.initializeEnvironment(envp);
73 Dbg.setWorkingDirectory(WorkingDirectory);
74 for (unsigned i = 0, e = SourceDirectories.size(); i != e; ++i)
75 D.addSourceDirectory(SourceDirectories[i]);
Misha Brukman3da94ae2005-04-22 00:00:37 +000076
Reid Spencer1ef8bda2004-12-30 05:36:08 +000077 if (!InputArgs.empty()) {
78 try {
79 D.fileCommand(InputArgs[0]);
80 } catch (const std::string &Error) {
81 std::cout << "Error: " << Error << "\n";
82 }
83
84 Dbg.setProgramArguments(InputArgs.begin()+1, InputArgs.end());
Chris Lattner7af5c122004-01-05 05:27:31 +000085 }
86
Reid Spencer1ef8bda2004-12-30 05:36:08 +000087 // Now that we have initialized the debugger, run it.
88 return D.run();
89 } catch (const std::string& msg) {
90 std::cerr << argv[0] << ": " << msg << "\n";
91 } catch (...) {
92 std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
Chris Lattner7af5c122004-01-05 05:27:31 +000093 }
Reid Spencer1ef8bda2004-12-30 05:36:08 +000094 return 1;
Chris Lattner7af5c122004-01-05 05:27:31 +000095}