5d45104b50afea92d516b8c5b4d5f88bc50b6dcf
[oota-llvm.git] / lib / Debugger / RuntimeInfo.cpp
1 //===-- RuntimeInfo.cpp - Compute and cache info about running program ----===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the RuntimeInfo and related classes, by querying and
11 // cachine information from the running inferior process.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/Debugger/InferiorProcess.h"
16 #include "llvm/Debugger/ProgramInfo.h"
17 #include "llvm/Debugger/RuntimeInfo.h"
18 using namespace llvm;
19
20 //===----------------------------------------------------------------------===//
21 // StackFrame class implementation
22
23 StackFrame::StackFrame(RuntimeInfo &ri, void *ParentFrameID)
24   : RI(ri), SourceInfo(0) {
25   FrameID = RI.getInferiorProcess().getPreviousFrame(ParentFrameID);
26   if (FrameID == 0) throw "Stack frame does not exist!";
27
28   // Compute lazily as needed.
29   FunctionDesc = 0;
30 }
31
32 const GlobalVariable *StackFrame::getFunctionDesc() {
33   if (FunctionDesc == 0)
34     FunctionDesc = RI.getInferiorProcess().getSubprogramDesc(FrameID);
35   return FunctionDesc;
36 }
37
38 /// getSourceLocation - Return the source location that this stack frame is
39 /// sitting at.
40 void StackFrame::getSourceLocation(unsigned &lineNo, unsigned &colNo,
41                                    const SourceFileInfo *&sourceInfo) {
42   if (SourceInfo == 0) {
43     const GlobalVariable *SourceDesc = 0;
44     RI.getInferiorProcess().getFrameLocation(FrameID, LineNo,ColNo, SourceDesc);
45     SourceInfo = &RI.getProgramInfo().getSourceFile(SourceDesc);
46   }
47
48   lineNo = LineNo;
49   colNo = ColNo;
50   sourceInfo = SourceInfo;
51 }
52
53 //===----------------------------------------------------------------------===//
54 // RuntimeInfo class implementation
55
56 /// materializeFrame - Create and process all frames up to and including the
57 /// specified frame number.  This throws an exception if the specified frame
58 /// ID is nonexistant.
59 void RuntimeInfo::materializeFrame(unsigned ID) {
60   assert(ID >= CallStack.size() && "no need to materialize this frame!");
61   void *CurFrame = 0;
62   if (!CallStack.empty())
63     CurFrame = CallStack.back().getFrameID();
64
65   while (CallStack.size() <= ID) {
66     CallStack.push_back(StackFrame(*this, CurFrame));
67     CurFrame = CallStack.back().getFrameID();
68   }
69 }