1 //===-- RuntimeInfo.cpp - Compute and cache info about running program ----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the RuntimeInfo and related classes, by querying and
11 // cachine information from the running inferior process.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Debugger/InferiorProcess.h"
16 #include "llvm/Debugger/ProgramInfo.h"
17 #include "llvm/Debugger/RuntimeInfo.h"
20 //===----------------------------------------------------------------------===//
21 // StackFrame class implementation
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!";
28 // Compute lazily as needed.
32 const GlobalVariable
*StackFrame::getFunctionDesc() {
33 if (FunctionDesc
== 0)
34 FunctionDesc
= RI
.getInferiorProcess().getSubprogramDesc(FrameID
);
38 /// getSourceLocation - Return the source location that this stack frame is
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
);
50 sourceInfo
= SourceInfo
;
53 //===----------------------------------------------------------------------===//
54 // RuntimeInfo class implementation
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!");
62 if (!CallStack
.empty())
63 CurFrame
= CallStack
.back().getFrameID();
65 while (CallStack
.size() <= ID
) {
66 CallStack
.push_back(StackFrame(*this, CurFrame
));
67 CurFrame
= CallStack
.back().getFrameID();