1 //===- Debugger.h - LLVM debugger library interface -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file defines the LLVM source-level debugger library interface.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_DEBUGGER_DEBUGGER_H
15 #define LLVM_DEBUGGER_DEBUGGER_H
22 class InferiorProcess;
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.
29 // State the debugger needs when starting and stopping the program.
30 std::vector<std::string> ProgramArguments;
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
35 const char * const *Environment;
37 // Program - The currently loaded program, or null if none is loaded.
40 // Process - The currently executing inferior process.
41 InferiorProcess *Process;
43 Debugger(const Debugger &); // DO NOT IMPLEMENT
44 void operator=(const Debugger &); // DO NOT IMPLEMENT
49 //===------------------------------------------------------------------===//
50 // Methods for manipulating and inspecting the execution environment.
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) {
60 /// setWorkingDirectory - Specify the working directory for the program to
62 void setWorkingDirectory(const std::string &Dir) {
67 void setProgramArguments(It I, It E) {
68 ProgramArguments.assign(I, E);
72 //===------------------------------------------------------------------===//
73 // Methods for manipulating and inspecting the program currently loaded.
76 /// isProgramLoaded - Return true if there is a program currently loaded.
78 bool isProgramLoaded() const { return Program != 0; }
80 /// getProgram - Return the LLVM module corresponding to the program.
82 Module *getProgram() const { return Program; }
84 /// getProgramPath - Get the path of the currently loaded program, or an
85 /// empty string if none is loaded.
86 std::string getProgramPath() const;
88 /// loadProgram - If a program is currently loaded, unload it. Then search
89 /// the PATH for the specified program, loading it when found. If the
90 /// specified program cannot be found, an exception is thrown to indicate
92 void loadProgram(const std::string &Path);
94 /// unloadProgram - If a program is running, kill it, then unload all traces
95 /// of the current program. If no program is loaded, this method silently
99 //===------------------------------------------------------------------===//
100 // Methods for manipulating and inspecting the program currently running.
102 // If the program is running, and the debugger is active, then we know that
103 // the program has stopped. This being the case, we can inspect the
104 // program, ask it for its source location, set breakpoints, etc.
107 /// isProgramRunning - Return true if a program is loaded and has a
108 /// currently active instance.
109 bool isProgramRunning() const { return Process != 0; }
111 /// getRunningProcess - If there is no program running, throw an exception.
112 /// Otherwise return the running process so that it can be inspected by the
114 const InferiorProcess &getRunningProcess() const {
115 if (Process == 0) throw "No process running.";
119 /// createProgram - Create an instance of the currently loaded program,
120 /// killing off any existing one. This creates the program and stops it at
121 /// the first possible moment. If there is no program loaded or if there is
122 /// a problem starting the program, this method throws an exception.
123 void createProgram();
125 /// killProgram - If the program is currently executing, kill off the
126 /// process and free up any state related to the currently running program.
127 /// If there is no program currently running, this just silently succeeds.
128 /// If something horrible happens when killing the program, an exception
133 //===------------------------------------------------------------------===//
134 // Methods for continuing execution. These methods continue the execution
135 // of the program by some amount. If the program is successfully stopped,
136 // execution returns, otherwise an exception is thrown.
138 // NOTE: These methods should always be used in preference to directly
139 // accessing the Dbg object, because these will delete the Process object if
140 // the process unexpectedly dies.
143 /// stepProgram - Implement the 'step' command, continuing execution until
144 /// the next possible stop point.
147 /// nextProgram - Implement the 'next' command, continuing execution until
148 /// the next possible stop point that is in the current function.
151 /// finishProgram - Implement the 'finish' command, continuing execution
152 /// until the specified frame ID returns.
153 void finishProgram(void *Frame);
155 /// contProgram - Implement the 'cont' command, continuing execution until
156 /// the next breakpoint is encountered.
160 class NonErrorException {
163 NonErrorException(const std::string &M) : Message(M) {}
164 const std::string &getMessage() const { return Message; }
167 } // end namespace llvm