1 //===- RuntimeInfo.h - Information about running program --------*- 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 classes that capture various pieces of information about
11 // the currently executing, but stopped, program. One instance of this object
12 // is created every time a program is stopped, and destroyed every time it
13 // starts running again. This object's main goal is to make access to runtime
14 // information easy and efficient, by caching information as requested.
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_DEBUGGER_RUNTIMEINFO_H
19 #define LLVM_DEBUGGER_RUNTIMEINFO_H
26 class InferiorProcess;
30 /// StackFrame - One instance of this structure is created for each stack
31 /// frame that is active in the program.
36 const GlobalVariable *FunctionDesc;
38 /// LineNo, ColNo, FileInfo - This information indicates WHERE in the source
39 /// code for the program the stack frame is located.
40 unsigned LineNo, ColNo;
41 const SourceFileInfo *SourceInfo;
43 StackFrame(RuntimeInfo &RI, void *ParentFrameID);
45 StackFrame &operator=(const StackFrame &RHS) {
46 FrameID = RHS.FrameID;
47 FunctionDesc = RHS.FunctionDesc;
51 /// getFrameID - return the low-level opaque frame ID of this stack frame.
53 void *getFrameID() const { return FrameID; }
55 /// getFunctionDesc - Return the descriptor for the function that contains
56 /// this stack frame, or null if it is unknown.
58 const GlobalVariable *getFunctionDesc();
60 /// getSourceLocation - Return the source location that this stack frame is
62 void getSourceLocation(unsigned &LineNo, unsigned &ColNo,
63 const SourceFileInfo *&SourceInfo);
67 /// RuntimeInfo - This class collects information about the currently running
68 /// process. It is created whenever the program stops execution for the
69 /// debugger, and destroyed whenver execution continues.
71 /// ProgInfo - This object contains static information about the program.
73 ProgramInfo *ProgInfo;
75 /// IP - This object contains information about the actual inferior process
76 /// that we are communicating with and aggregating information from.
77 const InferiorProcess &IP;
79 /// CallStack - This caches information about the current stack trace of the
80 /// program. This is lazily computed as needed.
81 std::vector<StackFrame> CallStack;
83 /// CurrentFrame - The user can traverse the stack frame with the
84 /// up/down/frame family of commands. This index indicates the current
86 unsigned CurrentFrame;
89 RuntimeInfo(ProgramInfo *PI, const InferiorProcess &ip)
90 : ProgInfo(PI), IP(ip), CurrentFrame(0) {
91 // Make sure that the top of stack has been materialized. If this throws
92 // an exception, something is seriously wrong and the RuntimeInfo object
93 // would be unusable anyway.
97 ProgramInfo &getProgramInfo() { return *ProgInfo; }
98 const InferiorProcess &getInferiorProcess() const { return IP; }
100 //===------------------------------------------------------------------===//
101 // Methods for inspecting the call stack of the program.
104 /// getStackFrame - Materialize the specified stack frame and return it. If
105 /// the specified ID is off of the bottom of the stack, throw an exception
106 /// indicating the problem.
107 StackFrame &getStackFrame(unsigned ID) {
108 if (ID >= CallStack.size())
109 materializeFrame(ID);
110 return CallStack[ID];
113 /// getCurrentFrame - Return the current stack frame object that the user is
115 StackFrame &getCurrentFrame() {
116 assert(CallStack.size() > CurrentFrame &&
117 "Must have materialized frame before making it current!");
118 return CallStack[CurrentFrame];
121 /// getCurrentFrameIdx - Return the current frame the user is inspecting.
123 unsigned getCurrentFrameIdx() const { return CurrentFrame; }
125 /// setCurrentFrameIdx - Set the current frame index to the specified value.
126 /// Note that the specified frame must have been materialized with
127 /// getStackFrame before it can be made current.
128 void setCurrentFrameIdx(unsigned Idx) {
129 assert(Idx < CallStack.size() &&
130 "Must materialize frame before making it current!");
134 /// materializeFrame - Create and process all frames up to and including the
135 /// specified frame number. This throws an exception if the specified frame
136 /// ID is nonexistant.
137 void materializeFrame(unsigned ID);