LLVM API Documentation
00001 //===- RuntimeInfo.h - Information about running program --------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines classes that capture various pieces of information about 00011 // the currently executing, but stopped, program. One instance of this object 00012 // is created every time a program is stopped, and destroyed every time it 00013 // starts running again. This object's main goal is to make access to runtime 00014 // information easy and efficient, by caching information as requested. 00015 // 00016 //===----------------------------------------------------------------------===// 00017 00018 #ifndef LLVM_DEBUGGER_RUNTIMEINFO_H 00019 #define LLVM_DEBUGGER_RUNTIMEINFO_H 00020 00021 #include <vector> 00022 #include <cassert> 00023 00024 namespace llvm { 00025 class ProgramInfo; 00026 class RuntimeInfo; 00027 class InferiorProcess; 00028 class GlobalVariable; 00029 class SourceFileInfo; 00030 00031 /// StackFrame - One instance of this structure is created for each stack 00032 /// frame that is active in the program. 00033 /// 00034 class StackFrame { 00035 RuntimeInfo &RI; 00036 void *FrameID; 00037 const GlobalVariable *FunctionDesc; 00038 00039 /// LineNo, ColNo, FileInfo - This information indicates WHERE in the source 00040 /// code for the program the stack frame is located. 00041 unsigned LineNo, ColNo; 00042 const SourceFileInfo *SourceInfo; 00043 public: 00044 StackFrame(RuntimeInfo &RI, void *ParentFrameID); 00045 00046 StackFrame &operator=(const StackFrame &RHS) { 00047 FrameID = RHS.FrameID; 00048 FunctionDesc = RHS.FunctionDesc; 00049 return *this; 00050 } 00051 00052 /// getFrameID - return the low-level opaque frame ID of this stack frame. 00053 /// 00054 void *getFrameID() const { return FrameID; } 00055 00056 /// getFunctionDesc - Return the descriptor for the function that contains 00057 /// this stack frame, or null if it is unknown. 00058 /// 00059 const GlobalVariable *getFunctionDesc(); 00060 00061 /// getSourceLocation - Return the source location that this stack frame is 00062 /// sitting at. 00063 void getSourceLocation(unsigned &LineNo, unsigned &ColNo, 00064 const SourceFileInfo *&SourceInfo); 00065 }; 00066 00067 00068 /// RuntimeInfo - This class collects information about the currently running 00069 /// process. It is created whenever the program stops execution for the 00070 /// debugger, and destroyed whenver execution continues. 00071 class RuntimeInfo { 00072 /// ProgInfo - This object contains static information about the program. 00073 /// 00074 ProgramInfo *ProgInfo; 00075 00076 /// IP - This object contains information about the actual inferior process 00077 /// that we are communicating with and aggregating information from. 00078 const InferiorProcess &IP; 00079 00080 /// CallStack - This caches information about the current stack trace of the 00081 /// program. This is lazily computed as needed. 00082 std::vector<StackFrame> CallStack; 00083 00084 /// CurrentFrame - The user can traverse the stack frame with the 00085 /// up/down/frame family of commands. This index indicates the current 00086 /// stack frame. 00087 unsigned CurrentFrame; 00088 00089 public: 00090 RuntimeInfo(ProgramInfo *PI, const InferiorProcess &ip) 00091 : ProgInfo(PI), IP(ip), CurrentFrame(0) { 00092 // Make sure that the top of stack has been materialized. If this throws 00093 // an exception, something is seriously wrong and the RuntimeInfo object 00094 // would be unusable anyway. 00095 getStackFrame(0); 00096 } 00097 00098 ProgramInfo &getProgramInfo() { return *ProgInfo; } 00099 const InferiorProcess &getInferiorProcess() const { return IP; } 00100 00101 //===------------------------------------------------------------------===// 00102 // Methods for inspecting the call stack of the program. 00103 // 00104 00105 /// getStackFrame - Materialize the specified stack frame and return it. If 00106 /// the specified ID is off of the bottom of the stack, throw an exception 00107 /// indicating the problem. 00108 StackFrame &getStackFrame(unsigned ID) { 00109 if (ID >= CallStack.size()) 00110 materializeFrame(ID); 00111 return CallStack[ID]; 00112 } 00113 00114 /// getCurrentFrame - Return the current stack frame object that the user is 00115 /// inspecting. 00116 StackFrame &getCurrentFrame() { 00117 assert(CallStack.size() > CurrentFrame && 00118 "Must have materialized frame before making it current!"); 00119 return CallStack[CurrentFrame]; 00120 } 00121 00122 /// getCurrentFrameIdx - Return the current frame the user is inspecting. 00123 /// 00124 unsigned getCurrentFrameIdx() const { return CurrentFrame; } 00125 00126 /// setCurrentFrameIdx - Set the current frame index to the specified value. 00127 /// Note that the specified frame must have been materialized with 00128 /// getStackFrame before it can be made current. 00129 void setCurrentFrameIdx(unsigned Idx) { 00130 assert(Idx < CallStack.size() && 00131 "Must materialize frame before making it current!"); 00132 CurrentFrame = Idx; 00133 } 00134 private: 00135 /// materializeFrame - Create and process all frames up to and including the 00136 /// specified frame number. This throws an exception if the specified frame 00137 /// ID is nonexistant. 00138 void materializeFrame(unsigned ID); 00139 }; 00140 } 00141 00142 #endif