blob: 2f0ff72a771e90f3a268db74a95958d833a0c09e [file] [log] [blame]
Chris Lattner2eacf262004-01-05 05:25:10 +00001//===-- RuntimeInfo.cpp - Compute and cache info about running program ----===//
Misha Brukmanedf128a2005-04-21 22:36:52 +00002//
Chris Lattner2eacf262004-01-05 05:25:10 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanedf128a2005-04-21 22:36:52 +00007//
Chris Lattner2eacf262004-01-05 05:25:10 +00008//===----------------------------------------------------------------------===//
Misha Brukmanedf128a2005-04-21 22:36:52 +00009//
Chris Lattner2eacf262004-01-05 05:25:10 +000010// 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"
18using namespace llvm;
19
20//===----------------------------------------------------------------------===//
21// StackFrame class implementation
22
23StackFrame::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!";
Misha Brukmanedf128a2005-04-21 22:36:52 +000027
Chris Lattner2eacf262004-01-05 05:25:10 +000028 // Compute lazily as needed.
29 FunctionDesc = 0;
30}
31
32const 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.
40void 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.
59void 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}