LLVM API Documentation
00001 //===-- RuntimeInfo.cpp - Compute and cache info about running program ----===// 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 implements the RuntimeInfo and related classes, by querying and 00011 // cachine information from the running inferior process. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #include "llvm/Debugger/InferiorProcess.h" 00016 #include "llvm/Debugger/ProgramInfo.h" 00017 #include "llvm/Debugger/RuntimeInfo.h" 00018 using namespace llvm; 00019 00020 //===----------------------------------------------------------------------===// 00021 // StackFrame class implementation 00022 00023 StackFrame::StackFrame(RuntimeInfo &ri, void *ParentFrameID) 00024 : RI(ri), SourceInfo(0) { 00025 FrameID = RI.getInferiorProcess().getPreviousFrame(ParentFrameID); 00026 if (FrameID == 0) throw "Stack frame does not exist!"; 00027 00028 // Compute lazily as needed. 00029 FunctionDesc = 0; 00030 } 00031 00032 const GlobalVariable *StackFrame::getFunctionDesc() { 00033 if (FunctionDesc == 0) 00034 FunctionDesc = RI.getInferiorProcess().getSubprogramDesc(FrameID); 00035 return FunctionDesc; 00036 } 00037 00038 /// getSourceLocation - Return the source location that this stack frame is 00039 /// sitting at. 00040 void StackFrame::getSourceLocation(unsigned &lineNo, unsigned &colNo, 00041 const SourceFileInfo *&sourceInfo) { 00042 if (SourceInfo == 0) { 00043 const GlobalVariable *SourceDesc = 0; 00044 RI.getInferiorProcess().getFrameLocation(FrameID, LineNo,ColNo, SourceDesc); 00045 SourceInfo = &RI.getProgramInfo().getSourceFile(SourceDesc); 00046 } 00047 00048 lineNo = LineNo; 00049 colNo = ColNo; 00050 sourceInfo = SourceInfo; 00051 } 00052 00053 //===----------------------------------------------------------------------===// 00054 // RuntimeInfo class implementation 00055 00056 /// materializeFrame - Create and process all frames up to and including the 00057 /// specified frame number. This throws an exception if the specified frame 00058 /// ID is nonexistant. 00059 void RuntimeInfo::materializeFrame(unsigned ID) { 00060 assert(ID >= CallStack.size() && "no need to materialize this frame!"); 00061 void *CurFrame = 0; 00062 if (!CallStack.empty()) 00063 CurFrame = CallStack.back().getFrameID(); 00064 00065 while (CallStack.size() <= ID) { 00066 CallStack.push_back(StackFrame(*this, CurFrame)); 00067 CurFrame = CallStack.back().getFrameID(); 00068 } 00069 }