1 //===- InferiorProcess.h - Represent the program being debugged -*- 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 InferiorProcess class, which is used to represent,
11 // inspect, and manipulate a process under the control of the LLVM debugger.
13 // This is an abstract class which should allow various different types of
14 // implementations. Initially we implement a unix specific debugger backend
15 // that does not require code generator support, but we could eventually use
16 // code generator support with ptrace, support windows based targets, supported
17 // remote targets, etc.
19 // If the inferior process unexpectedly dies, an attempt to communicate with it
20 // will cause an InferiorProcessDead exception to be thrown, indicating the exit
21 // code of the process. When this occurs, no methods on the InferiorProcess
22 // class should be called except for the destructor.
24 //===----------------------------------------------------------------------===//
26 #ifndef LLVM_DEBUGGER_INFERIORPROCESS_H
27 #define LLVM_DEBUGGER_INFERIORPROCESS_H
36 /// InferiorProcessDead exception - This class is thrown by methods that
37 /// communicate with the interior process if the process unexpectedly exits or
38 /// dies. The instance variable indicates what the exit code of the process
39 /// was, or -1 if unknown.
40 class InferiorProcessDead {
43 InferiorProcessDead(int EC) : ExitCode(EC) {}
44 int getExitCode() const { return ExitCode; }
47 /// InferiorProcess class - This class represents the process being debugged
48 /// by the debugger. Objects of this class should not be stack allocated,
49 /// because the destructor can throw exceptions.
51 class InferiorProcess {
54 InferiorProcess(Module *m) : M(m) {}
56 /// create - Create an inferior process of the specified module, and
57 /// stop it at the first opportunity. If there is a problem starting the
58 /// program (for example, it has no main), throw an exception.
59 static InferiorProcess *create(Module *M,
60 const std::vector<std::string> &Arguments,
61 const char * const *envp);
63 // InferiorProcess destructor - Kill the current process. If something
64 // terrible happens, we throw an exception from the destructor.
65 virtual ~InferiorProcess() {}
67 //===------------------------------------------------------------------===//
68 // Status methods - These methods return information about the currently
72 /// getStatus - Return a status message that is specific to the current type
73 /// of inferior process that is created. This can return things like the
74 /// PID of the inferior or other potentially interesting things.
75 virtual std::string getStatus() const {
79 //===------------------------------------------------------------------===//
80 // Methods for inspecting the call stack.
83 /// getPreviousFrame - Given the descriptor for the current stack frame,
84 /// return the descriptor for the caller frame. This returns null when it
85 /// runs out of frames. If Frame is null, the initial frame should be
87 virtual void *getPreviousFrame(void *Frame) const = 0;
89 /// getSubprogramDesc - Return the subprogram descriptor for the current
91 virtual const GlobalVariable *getSubprogramDesc(void *Frame) const = 0;
93 /// getFrameLocation - This method returns the source location where each
94 /// stack frame is stopped.
95 virtual void getFrameLocation(void *Frame, unsigned &LineNo,
97 const GlobalVariable *&SourceDesc) const = 0;
99 //===------------------------------------------------------------------===//
100 // Methods for manipulating breakpoints.
103 /// addBreakpoint - This method adds a breakpoint at the specified line,
104 /// column, and source file, and returns a unique identifier for it.
106 /// It is up to the debugger to determine whether or not there is actually a
107 /// stop-point that corresponds with the specified location.
108 virtual unsigned addBreakpoint(unsigned LineNo, unsigned ColNo,
109 const GlobalVariable *SourceDesc) = 0;
111 /// removeBreakpoint - This deletes the breakpoint with the specified ID
113 virtual void removeBreakpoint(unsigned ID) = 0;
116 //===------------------------------------------------------------------===//
117 // Execution methods - These methods cause the program to continue execution
118 // by some amount. If the program successfully stops, this returns.
119 // Otherwise, if the program unexpectedly terminates, an InferiorProcessDead
120 // exception is thrown.
123 /// stepProgram - Implement the 'step' command, continuing execution until
124 /// the next possible stop point.
125 virtual void stepProgram() = 0;
127 /// finishProgram - Implement the 'finish' command, continuing execution
128 /// until the current function returns.
129 virtual void finishProgram(void *Frame) = 0;
131 /// contProgram - Implement the 'cont' command, continuing execution until
132 /// a breakpoint is encountered.
133 virtual void contProgram() = 0;
135 } // end namespace llvm