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
27 class InferiorProcess;
31 /// StackFrame - One instance of this structure is created for each stack
32 /// frame that is active in the program.
37 const GlobalVariable *FunctionDesc;
39 /// LineNo, ColNo, FileInfo - This information indicates WHERE in the source
40 /// code for the program the stack frame is located.
41 unsigned LineNo, ColNo;
42 const SourceFileInfo *SourceInfo;
44 StackFrame(RuntimeInfo &RI, void *ParentFrameID);
46 StackFrame &operator=(const StackFrame &RHS) {
47 FrameID = RHS.FrameID;
48 FunctionDesc = RHS.FunctionDesc;
52 /// getFrameID - return the low-level opaque frame ID of this stack frame.
54 void *getFrameID() const { return FrameID; }
56 /// getFunctionDesc - Return the descriptor for the function that contains
57 /// this stack frame, or null if it is unknown.
59 const GlobalVariable *getFunctionDesc();
61 /// getSourceLocation - Return the source location that this stack frame is
63 void getSourceLocation(unsigned &LineNo, unsigned &ColNo,
64 const SourceFileInfo *&SourceInfo);
68 /// RuntimeInfo - This class collects information about the currently running
69 /// process. It is created whenever the program stops execution for the
70 /// debugger, and destroyed whenver execution continues.
72 /// ProgInfo - This object contains static information about the program.
74 ProgramInfo *ProgInfo;
76 /// IP - This object contains information about the actual inferior process
77 /// that we are communicating with and aggregating information from.
78 const InferiorProcess &IP;
80 /// CallStack - This caches information about the current stack trace of the
81 /// program. This is lazily computed as needed.
82 std::vector<StackFrame> CallStack;
84 /// CurrentFrame - The user can traverse the stack frame with the
85 /// up/down/frame family of commands. This index indicates the current
87 unsigned CurrentFrame;
90 RuntimeInfo(ProgramInfo *PI, const InferiorProcess &ip)
91 : ProgInfo(PI), IP(ip), CurrentFrame(0) {
92 // Make sure that the top of stack has been materialized. If this throws
93 // an exception, something is seriously wrong and the RuntimeInfo object
94 // would be unusable anyway.
98 ProgramInfo &getProgramInfo() { return *ProgInfo; }
99 const InferiorProcess &getInferiorProcess() const { return IP; }
101 //===------------------------------------------------------------------===//
102 // Methods for inspecting the call stack of the program.
105 /// getStackFrame - Materialize the specified stack frame and return it. If
106 /// the specified ID is off of the bottom of the stack, throw an exception
107 /// indicating the problem.
108 StackFrame &getStackFrame(unsigned ID) {
109 if (ID >= CallStack.size())
110 materializeFrame(ID);
111 return CallStack[ID];
114 /// getCurrentFrame - Return the current stack frame object that the user is
116 StackFrame &getCurrentFrame() {
117 assert(CallStack.size() > CurrentFrame &&
118 "Must have materialized frame before making it current!");
119 return CallStack[CurrentFrame];
122 /// getCurrentFrameIdx - Return the current frame the user is inspecting.
124 unsigned getCurrentFrameIdx() const { return CurrentFrame; }
126 /// setCurrentFrameIdx - Set the current frame index to the specified value.
127 /// Note that the specified frame must have been materialized with
128 /// getStackFrame before it can be made current.
129 void setCurrentFrameIdx(unsigned Idx) {
130 assert(Idx < CallStack.size() &&
131 "Must materialize frame before making it current!");
135 /// materializeFrame - Create and process all frames up to and including the
136 /// specified frame number. This throws an exception if the specified frame
137 /// ID is nonexistant.
138 void materializeFrame(unsigned ID);