Simplify some code by using blocks_begin(), blocks_end(), and
[oota-llvm.git] / include / llvm / Debugger / Debugger.h
1 //===- Debugger.h - LLVM debugger library interface -------------*- 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 LLVM source-level debugger library interface.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_DEBUGGER_DEBUGGER_H
15 #define LLVM_DEBUGGER_DEBUGGER_H
16
17 #include <string>
18 #include <vector>
19
20 namespace llvm {
21   class Module;
22   class InferiorProcess;
23
24   /// Debugger class - This class implements the LLVM source-level debugger.
25   /// This allows clients to handle the user IO processing without having to
26   /// worry about how the debugger itself works.
27   ///
28   class Debugger {
29     // State the debugger needs when starting and stopping the program.
30     std::vector<std::string> ProgramArguments;
31
32     // The environment to run the program with.  This should eventually be
33     // changed to vector of strings when we allow the user to edit the
34     // environment.
35     const char * const *Environment;
36
37     // Program - The currently loaded program, or null if none is loaded.
38     Module *Program;
39
40     // Process - The currently executing inferior process.
41     InferiorProcess *Process;
42
43     Debugger(const Debugger &);         // DO NOT IMPLEMENT
44     void operator=(const Debugger &);   // DO NOT IMPLEMENT
45   public:
46     Debugger();
47     ~Debugger();
48
49     //===------------------------------------------------------------------===//
50     // Methods for manipulating and inspecting the execution environment.
51     //
52
53     /// initializeEnvironment - Specify the environment the program should run
54     /// with.  This is used to initialize the environment of the program to the
55     /// environment of the debugger.
56     void initializeEnvironment(const char *const *envp) {
57       Environment = envp;
58     }
59
60     /// setWorkingDirectory - Specify the working directory for the program to
61     /// be started from.
62     void setWorkingDirectory(const std::string &Dir) {
63       // FIXME: implement
64     }
65
66     template<typename It>
67     void setProgramArguments(It I, It E) {
68       ProgramArguments.assign(I, E);
69     }
70     unsigned getNumProgramArguments() const {
71       return static_cast<unsigned>(ProgramArguments.size());
72     }
73     const std::string &getProgramArgument(unsigned i) const {
74       return ProgramArguments[i];
75     }
76
77
78     //===------------------------------------------------------------------===//
79     // Methods for manipulating and inspecting the program currently loaded.
80     //
81
82     /// isProgramLoaded - Return true if there is a program currently loaded.
83     ///
84     bool isProgramLoaded() const { return Program != 0; }
85
86     /// getProgram - Return the LLVM module corresponding to the program.
87     ///
88     Module *getProgram() const { return Program; }
89
90     /// getProgramPath - Get the path of the currently loaded program, or an
91     /// empty string if none is loaded.
92     std::string getProgramPath() const;
93
94     /// loadProgram - If a program is currently loaded, unload it.  Then search
95     /// the PATH for the specified program, loading it when found.  If the
96     /// specified program cannot be found, an exception is thrown to indicate
97     /// the error.
98     void loadProgram(const std::string &Path);
99
100     /// unloadProgram - If a program is running, kill it, then unload all traces
101     /// of the current program.  If no program is loaded, this method silently
102     /// succeeds.
103     void unloadProgram();
104
105     //===------------------------------------------------------------------===//
106     // Methods for manipulating and inspecting the program currently running.
107     //
108     // If the program is running, and the debugger is active, then we know that
109     // the program has stopped.  This being the case, we can inspect the
110     // program, ask it for its source location, set breakpoints, etc.
111     //
112
113     /// isProgramRunning - Return true if a program is loaded and has a
114     /// currently active instance.
115     bool isProgramRunning() const { return Process != 0; }
116
117     /// getRunningProcess - If there is no program running, throw an exception.
118     /// Otherwise return the running process so that it can be inspected by the
119     /// debugger.
120     const InferiorProcess &getRunningProcess() const {
121       if (Process == 0) throw "No process running.";
122       return *Process;
123     }
124
125     /// createProgram - Create an instance of the currently loaded program,
126     /// killing off any existing one.  This creates the program and stops it at
127     /// the first possible moment.  If there is no program loaded or if there is
128     /// a problem starting the program, this method throws an exception.
129     void createProgram();
130
131     /// killProgram - If the program is currently executing, kill off the
132     /// process and free up any state related to the currently running program.
133     /// If there is no program currently running, this just silently succeeds.
134     /// If something horrible happens when killing the program, an exception
135     /// gets thrown.
136     void killProgram();
137
138
139     //===------------------------------------------------------------------===//
140     // Methods for continuing execution.  These methods continue the execution
141     // of the program by some amount.  If the program is successfully stopped,
142     // execution returns, otherwise an exception is thrown.
143     //
144     // NOTE: These methods should always be used in preference to directly
145     // accessing the Dbg object, because these will delete the Process object if
146     // the process unexpectedly dies.
147     //
148
149     /// stepProgram - Implement the 'step' command, continuing execution until
150     /// the next possible stop point.
151     void stepProgram();
152
153     /// nextProgram - Implement the 'next' command, continuing execution until
154     /// the next possible stop point that is in the current function.
155     void nextProgram();
156
157     /// finishProgram - Implement the 'finish' command, continuing execution
158     /// until the specified frame ID returns.
159     void finishProgram(void *Frame);
160
161     /// contProgram - Implement the 'cont' command, continuing execution until
162     /// the next breakpoint is encountered.
163     void contProgram();
164   };
165
166   class NonErrorException {
167     std::string Message;
168   public:
169     NonErrorException(const std::string &M) : Message(M) {}
170     const std::string &getMessage() const { return Message; }
171   };
172
173 } // end namespace llvm
174
175 #endif