2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
6 #include "StackFrame.h"
11 #include "FunctionInstance.h"
13 #include "StackFrameDebugInfo.h"
14 #include "StackFrameValueInfos.h"
15 #include "StackFrameValues.h"
19 // #pragma mark - StackFrame
22 StackFrame::StackFrame(stack_frame_type type
, CpuState
* cpuState
,
23 target_addr_t frameAddress
, target_addr_t instructionPointer
,
24 StackFrameDebugInfo
* debugInfo
)
28 fPreviousCpuState(NULL
),
29 fFrameAddress(frameAddress
),
30 fInstructionPointer(instructionPointer
),
32 fDebugInfo(debugInfo
),
38 fCpuState
->AcquireReference();
39 fDebugInfo
->AcquireReference();
43 StackFrame::~StackFrame()
45 for (int32 i
= 0; Variable
* variable
= fParameters
.ItemAt(i
); i
++)
46 variable
->ReleaseReference();
48 for (int32 i
= 0; Variable
* variable
= fLocalVariables
.ItemAt(i
); i
++)
49 variable
->ReleaseReference();
53 SetPreviousCpuState(NULL
);
55 fDebugInfo
->ReleaseReference();
56 fCpuState
->ReleaseReference();
64 fValues
= new(std::nothrow
) StackFrameValues
;
68 status_t error
= fValues
->Init();
72 // create value infos map
73 fValueInfos
= new(std::nothrow
) StackFrameValueInfos
;
74 if (fValueInfos
== NULL
)
77 error
= fValueInfos
->Init();
86 StackFrame::SetPreviousCpuState(CpuState
* state
)
88 if (fPreviousCpuState
!= NULL
)
89 fPreviousCpuState
->ReleaseReference();
91 fPreviousCpuState
= state
;
93 if (fPreviousCpuState
!= NULL
)
94 fPreviousCpuState
->AcquireReference();
98 StackFrame::SetReturnAddress(target_addr_t address
)
100 fReturnAddress
= address
;
105 StackFrame::SetImage(Image
* image
)
108 fImage
->ReleaseReference();
113 fImage
->AcquireReference();
118 StackFrame::SetFunction(FunctionInstance
* function
)
120 if (fFunction
!= NULL
)
121 fFunction
->ReleaseReference();
123 fFunction
= function
;
125 if (fFunction
!= NULL
)
126 fFunction
->AcquireReference();
131 StackFrame::CountParameters() const
133 return fParameters
.CountItems();
138 StackFrame::ParameterAt(int32 index
) const
140 return fParameters
.ItemAt(index
);
145 StackFrame::AddParameter(Variable
* parameter
)
147 if (!fParameters
.AddItem(parameter
))
150 parameter
->AcquireReference();
156 StackFrame::CountLocalVariables() const
158 return fLocalVariables
.CountItems();
163 StackFrame::LocalVariableAt(int32 index
) const
165 return fLocalVariables
.ItemAt(index
);
170 StackFrame::AddLocalVariable(Variable
* variable
)
172 if (!fLocalVariables
.AddItem(variable
))
175 variable
->AcquireReference();
181 StackFrame::AddListener(Listener
* listener
)
183 fListeners
.Add(listener
);
188 StackFrame::RemoveListener(Listener
* listener
)
190 fListeners
.Remove(listener
);
195 StackFrame::NotifyValueRetrieved(Variable
* variable
, TypeComponentPath
* path
)
197 for (ListenerList::Iterator it
= fListeners
.GetIterator();
198 Listener
* listener
= it
.Next();) {
199 listener
->StackFrameValueRetrieved(this, variable
, path
);
204 // #pragma mark - StackFrame
207 StackFrame::Listener::~Listener()
213 StackFrame::Listener::StackFrameValueRetrieved(StackFrame
* stackFrame
,
214 Variable
* variable
, TypeComponentPath
* path
)