1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef STACK_FRAME_H
6#define STACK_FRAME_H
7
8
9#include <OS.h>
10
11#include <ObjectList.h>
12#include <Referenceable.h>
13#include <util/DoublyLinkedList.h>
14
15#include "Types.h"
16
17
18enum stack_frame_type {
19	STACK_FRAME_TYPE_SYSCALL,		// syscall frame
20	STACK_FRAME_TYPE_STANDARD,		// standard frame
21	STACK_FRAME_TYPE_SIGNAL,		// signal handler frame
22	STACK_FRAME_TYPE_FRAMELESS		// dummy frame for a frameless function
23};
24
25
26class CpuState;
27class Image;
28class FunctionInstance;
29class StackFrameDebugInfo;
30class StackFrameValueInfos;
31class StackFrameValues;
32class TypeComponentPath;
33class Variable;
34
35
36class StackFrame : public BReferenceable {
37public:
38	class Listener;
39
40public:
41								StackFrame(stack_frame_type type,
42									CpuState* cpuState,
43									target_addr_t frameAddress,
44									target_addr_t instructionPointer,
45									StackFrameDebugInfo* debugInfo);
46								~StackFrame();
47
48			status_t			Init();
49
50			stack_frame_type	Type() const			{ return fType; }
51			CpuState*			GetCpuState() const		{ return fCpuState; }
52			target_addr_t		FrameAddress() const { return fFrameAddress; }
53			StackFrameDebugInfo* DebugInfo() const		{ return fDebugInfo; }
54
55			target_addr_t		InstructionPointer() const
56									{ return fInstructionPointer; }
57
58			CpuState*			PreviousCpuState() const
59									{ return fPreviousCpuState; }
60			void				SetPreviousCpuState(CpuState* state);
61
62			target_addr_t		ReturnAddress() const { return fReturnAddress; }
63			void				SetReturnAddress(target_addr_t address);
64
65			Image*				GetImage() const		{ return fImage; }
66			void				SetImage(Image* image);
67
68			FunctionInstance*	Function() const		{ return fFunction; }
69			void				SetFunction(FunctionInstance* function);
70
71			int32				CountParameters() const;
72			Variable*			ParameterAt(int32 index) const;
73			bool				AddParameter(Variable* parameter);
74
75			int32				CountLocalVariables() const;
76			Variable*			LocalVariableAt(int32 index) const;
77			bool				AddLocalVariable(Variable* variable);
78
79			StackFrameValues*	Values() const			{ return fValues; }
80			StackFrameValueInfos* ValueInfos() const	{ return fValueInfos; }
81
82			// team lock must be held
83			void				AddListener(Listener* listener);
84			void				RemoveListener(Listener* listener);
85
86			void				NotifyValueRetrieved(Variable* variable,
87									TypeComponentPath* path);
88
89private:
90			typedef BObjectList<Variable> VariableList;
91			typedef DoublyLinkedList<Listener> ListenerList;
92
93private:
94			stack_frame_type	fType;
95			CpuState*			fCpuState;
96			CpuState*			fPreviousCpuState;
97			target_addr_t		fFrameAddress;
98			target_addr_t		fInstructionPointer;
99			target_addr_t		fReturnAddress;
100			StackFrameDebugInfo* fDebugInfo;
101			Image*				fImage;
102			FunctionInstance*	fFunction;
103			VariableList		fParameters;
104			VariableList		fLocalVariables;
105			StackFrameValues*	fValues;
106			StackFrameValueInfos* fValueInfos;
107			ListenerList		fListeners;
108};
109
110
111class StackFrame::Listener : public DoublyLinkedListLinkImpl<Listener> {
112public:
113	virtual						~Listener();
114
115	virtual	void				StackFrameValueRetrieved(StackFrame* stackFrame,
116									Variable* variable,
117									TypeComponentPath* path);
118									// called with lock held
119};
120
121
122#endif	// STACK_FRAME_H
123