Work around the fact that GNU libstdc++'s debug mode uses RTTI.
[llvm/msp430.git] / tools / llvm-db / CLIDebugger.h
blob56ea14dfbcfd88a0d1c6dbfda9bee37a35f25017
1 //===- CLIDebugger.h - LLVM Command Line Interface Debugger -----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the CLIDebugger class, which implements a command line
11 // interface to the LLVM Debugger library.
13 //===----------------------------------------------------------------------===//
15 #ifndef CLIDEBUGGER_H
16 #define CLIDEBUGGER_H
18 #include "llvm/Debugger/Debugger.h"
19 #include <map>
21 namespace llvm {
22 class CLICommand;
23 class SourceFile;
24 class SourceLanguage;
25 class ProgramInfo;
26 class RuntimeInfo;
28 /// CLIDebugger - This class implements the command line interface for the
29 /// LLVM debugger.
30 class CLIDebugger {
31 /// Dbg - The low-level LLVM debugger object that we use to do our dirty
32 /// work.
33 Debugger Dbg;
35 /// CommandTable - This table contains a mapping from command names to the
36 /// CLICommand object that implements the command.
37 std::map<std::string, CLICommand*> CommandTable;
39 //===------------------------------------------------------------------===//
40 // Data related to the program that is currently loaded. Note that the Dbg
41 // variable also captures some information about the loaded program. This
42 // pointer is non-null iff Dbg.isProgramLoaded() is true.
44 ProgramInfo *TheProgramInfo;
46 //===------------------------------------------------------------------===//
47 // Data related to the program that is currently executing, but has stopped.
48 // Note that the Dbg variable also captures some information about the
49 // loaded program. This pointer is non-null iff Dbg.isProgramRunning() is
50 // true.
52 RuntimeInfo *TheRuntimeInfo;
54 /// LastCurrentFrame - This variable holds the Frame ID of the top-level
55 /// stack frame from the last time that the program was executed. We keep
56 /// this because we only want to print the source location when the current
57 /// function changes.
58 void *LastCurrentFrame;
60 //===------------------------------------------------------------------===//
61 // Data directly exposed through the debugger prompt
63 std::string Prompt; // set prompt, show prompt
64 unsigned ListSize; // set listsize, show listsize
66 //===------------------------------------------------------------------===//
67 // Data to support user interaction
70 /// CurrentFile - The current source file we are inspecting, or null if
71 /// none.
72 const SourceFile *CurrentFile;
73 unsigned LineListedStart, LineListedEnd;
75 /// CurrentLanguage - This contains the source language in use, if one is
76 /// explicitly set by the user. If this is null (the default), the language
77 /// is automatically determined from the current stack frame.
78 ///
79 const SourceLanguage *CurrentLanguage;
81 public:
82 CLIDebugger();
84 /// getDebugger - Return the current LLVM debugger implementation being
85 /// used.
86 Debugger &getDebugger() { return Dbg; }
88 /// run - Start the debugger, returning when the user exits the debugger.
89 /// This starts the main event loop of the CLI debugger.
90 ///
91 int run();
93 /// addCommand - Add a command to the CommandTable, potentially displacing a
94 /// preexisting command.
95 void addCommand(const std::string &Option, CLICommand *Cmd);
97 /// addSourceDirectory - Add a directory to search when looking for the
98 /// source code of the program.
99 void addSourceDirectory(const std::string &Dir) {
100 // FIXME: implement
103 /// getCurrentLanguage - Return the current source language that the user is
104 /// playing around with. This is aquired from the current stack frame of a
105 /// running program if one exists, but this value can be explicitly set by
106 /// the user as well.
107 const SourceLanguage &getCurrentLanguage() const;
109 /// getProgramInfo - Return a reference to the ProgramInfo object for the
110 /// currently loaded program. If there is no program loaded, throw an
111 /// exception.
112 ProgramInfo &getProgramInfo() const {
113 if (TheProgramInfo == 0)
114 throw "No program is loaded.";
115 return *TheProgramInfo;
118 /// getRuntimeInfo - Return a reference to the current RuntimeInfo object.
119 /// If there is no program running, throw an exception.
120 RuntimeInfo &getRuntimeInfo() const {
121 if (TheRuntimeInfo == 0)
122 throw "No program is running.";
123 return *TheRuntimeInfo;
126 private: // Internal implementation methods
128 /// getCommand - This looks up the specified command using a fuzzy match.
129 /// If the string exactly matches a command or is an unambiguous prefix of a
130 /// command, it returns the command. Otherwise it throws an exception
131 /// indicating the possible ambiguous choices.
132 CLICommand *getCommand(const std::string &Command);
134 /// askYesNo - Ask the user a question, and demand a yes/no response. If
135 /// the user says yes, return true.
136 bool askYesNo(const std::string &Message) const;
138 /// printProgramLocation - Given a loaded and created child process that has
139 /// stopped, print its current source location.
140 void printProgramLocation(bool PrintLocation = true);
142 /// eliminateRunInfo - We are about to run the program. Forget any state
143 /// about how the program used to be stopped.
144 void eliminateRunInfo();
146 /// programStoppedSuccessfully - This method updates internal data
147 /// structures to reflect the fact that the program just executed a while,
148 /// and has successfully stopped.
149 void programStoppedSuccessfully();
151 public: /// Builtin debugger commands, invokable by the user
152 // Program startup and shutdown options
153 void fileCommand(std::string &Options); // file
154 void createCommand(std::string &Options); // create
155 void killCommand(std::string &Options); // kill
156 void quitCommand(std::string &Options); // quit
158 // Program execution commands
159 void runCommand(std::string &Options); // run|r
160 void contCommand(std::string &Options); // cont|c|fg
161 void stepCommand(std::string &Options); // step|s [count]
162 void nextCommand(std::string &Options); // next|n [count]
163 void finishCommand(std::string &Options); // finish
165 // Stack frame commands
166 void backtraceCommand(std::string &Options); // backtrace|bt [count]
167 void upCommand(std::string &Options); // up
168 void downCommand(std::string &Options); // down
169 void frameCommand(std::string &Options); // frame
172 // Breakpoint related commands
173 void breakCommand(std::string &Options); // break|b <id>
175 // Miscellaneous commands
176 void infoCommand(std::string &Options); // info
177 void listCommand(std::string &Options); // list
178 void setCommand(std::string &Options); // set
179 void showCommand(std::string &Options); // show
180 void helpCommand(std::string &Options); // help
182 private:
183 /// startProgramRunning - If the program has been updated, reload it, then
184 /// start executing the program.
185 void startProgramRunning();
187 /// printSourceLine - Print the specified line of the current source file.
188 /// If the specified line is invalid (the source file could not be loaded or
189 /// the line number is out of range), don't print anything, but return true.
190 bool printSourceLine(unsigned LineNo);
192 /// parseLineSpec - Parses a line specifier, for use by the 'list' command.
193 /// If SourceFile is returned as a void pointer, then it was not specified.
194 /// If the line specifier is invalid, an exception is thrown.
195 void parseLineSpec(std::string &LineSpec, const SourceFile *&SourceFile,
196 unsigned &LineNo);
198 /// parseProgramOptions - This method parses the Options string and loads it
199 /// as options to be passed to the program. This is used by the run command
200 /// and by 'set args'.
201 void parseProgramOptions(std::string &Options);
205 #endif