LLVM API Documentation
00001 //===- Debugger.h - LLVM debugger library interface -------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the LLVM source-level debugger library interface. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_DEBUGGER_DEBUGGER_H 00015 #define LLVM_DEBUGGER_DEBUGGER_H 00016 00017 #include <string> 00018 #include <vector> 00019 00020 namespace llvm { 00021 class Module; 00022 class InferiorProcess; 00023 00024 /// Debugger class - This class implements the LLVM source-level debugger. 00025 /// This allows clients to handle the user IO processing without having to 00026 /// worry about how the debugger itself works. 00027 /// 00028 class Debugger { 00029 // State the debugger needs when starting and stopping the program. 00030 std::vector<std::string> ProgramArguments; 00031 00032 // The environment to run the program with. This should eventually be 00033 // changed to vector of strings when we allow the user to edit the 00034 // environment. 00035 const char * const *Environment; 00036 00037 // Program - The currently loaded program, or null if none is loaded. 00038 Module *Program; 00039 00040 // Process - The currently executing inferior process. 00041 InferiorProcess *Process; 00042 00043 Debugger(const Debugger &); // DO NOT IMPLEMENT 00044 void operator=(const Debugger &); // DO NOT IMPLEMENT 00045 public: 00046 Debugger(); 00047 ~Debugger(); 00048 00049 //===------------------------------------------------------------------===// 00050 // Methods for manipulating and inspecting the execution environment. 00051 // 00052 00053 /// initializeEnvironment - Specify the environment the program should run 00054 /// with. This is used to initialize the environment of the program to the 00055 /// environment of the debugger. 00056 void initializeEnvironment(const char *const *envp) { 00057 Environment = envp; 00058 } 00059 00060 /// setWorkingDirectory - Specify the working directory for the program to 00061 /// be started from. 00062 void setWorkingDirectory(const std::string &Dir) { 00063 // FIXME: implement 00064 } 00065 00066 template<typename It> 00067 void setProgramArguments(It I, It E) { 00068 ProgramArguments.assign(I, E); 00069 } 00070 unsigned getNumProgramArguments() const { 00071 return static_cast<unsigned>(ProgramArguments.size()); 00072 } 00073 const std::string &getProgramArgument(unsigned i) const { 00074 return ProgramArguments[i]; 00075 } 00076 00077 00078 //===------------------------------------------------------------------===// 00079 // Methods for manipulating and inspecting the program currently loaded. 00080 // 00081 00082 /// isProgramLoaded - Return true if there is a program currently loaded. 00083 /// 00084 bool isProgramLoaded() const { return Program != 0; } 00085 00086 /// getProgram - Return the LLVM module corresponding to the program. 00087 /// 00088 Module *getProgram() const { return Program; } 00089 00090 /// getProgramPath - Get the path of the currently loaded program, or an 00091 /// empty string if none is loaded. 00092 std::string getProgramPath() const; 00093 00094 /// loadProgram - If a program is currently loaded, unload it. Then search 00095 /// the PATH for the specified program, loading it when found. If the 00096 /// specified program cannot be found, an exception is thrown to indicate 00097 /// the error. 00098 void loadProgram(const std::string &Path); 00099 00100 /// unloadProgram - If a program is running, kill it, then unload all traces 00101 /// of the current program. If no program is loaded, this method silently 00102 /// succeeds. 00103 void unloadProgram(); 00104 00105 //===------------------------------------------------------------------===// 00106 // Methods for manipulating and inspecting the program currently running. 00107 // 00108 // If the program is running, and the debugger is active, then we know that 00109 // the program has stopped. This being the case, we can inspect the 00110 // program, ask it for its source location, set breakpoints, etc. 00111 // 00112 00113 /// isProgramRunning - Return true if a program is loaded and has a 00114 /// currently active instance. 00115 bool isProgramRunning() const { return Process != 0; } 00116 00117 /// getRunningProcess - If there is no program running, throw an exception. 00118 /// Otherwise return the running process so that it can be inspected by the 00119 /// debugger. 00120 const InferiorProcess &getRunningProcess() const { 00121 if (Process == 0) throw "No process running."; 00122 return *Process; 00123 } 00124 00125 /// createProgram - Create an instance of the currently loaded program, 00126 /// killing off any existing one. This creates the program and stops it at 00127 /// the first possible moment. If there is no program loaded or if there is 00128 /// a problem starting the program, this method throws an exception. 00129 void createProgram(); 00130 00131 /// killProgram - If the program is currently executing, kill off the 00132 /// process and free up any state related to the currently running program. 00133 /// If there is no program currently running, this just silently succeeds. 00134 /// If something horrible happens when killing the program, an exception 00135 /// gets thrown. 00136 void killProgram(); 00137 00138 00139 //===------------------------------------------------------------------===// 00140 // Methods for continuing execution. These methods continue the execution 00141 // of the program by some amount. If the program is successfully stopped, 00142 // execution returns, otherwise an exception is thrown. 00143 // 00144 // NOTE: These methods should always be used in preference to directly 00145 // accessing the Dbg object, because these will delete the Process object if 00146 // the process unexpectedly dies. 00147 // 00148 00149 /// stepProgram - Implement the 'step' command, continuing execution until 00150 /// the next possible stop point. 00151 void stepProgram(); 00152 00153 /// nextProgram - Implement the 'next' command, continuing execution until 00154 /// the next possible stop point that is in the current function. 00155 void nextProgram(); 00156 00157 /// finishProgram - Implement the 'finish' command, continuing execution 00158 /// until the specified frame ID returns. 00159 void finishProgram(void *Frame); 00160 00161 /// contProgram - Implement the 'cont' command, continuing execution until 00162 /// the next breakpoint is encountered. 00163 void contProgram(); 00164 }; 00165 00166 class NonErrorException { 00167 std::string Message; 00168 public: 00169 NonErrorException(const std::string &M) : Message(M) {} 00170 const std::string &getMessage() const { return Message; } 00171 }; 00172 00173 } // end namespace llvm 00174 00175 #endif