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 18 enum 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 26 class CpuState; 27 class Image; 28 class FunctionInstance; 29 class StackFrameDebugInfo; 30 class StackFrameValueInfos; 31 class StackFrameValues; 32 class TypeComponentPath; 33 class Variable; 34 35 36 class StackFrame : public BReferenceable { 37 public: 38 class Listener; 39 40 public: 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 Type()50 stack_frame_type Type() const { return fType; } GetCpuState()51 CpuState* GetCpuState() const { return fCpuState; } FrameAddress()52 target_addr_t FrameAddress() const { return fFrameAddress; } DebugInfo()53 StackFrameDebugInfo* DebugInfo() const { return fDebugInfo; } 54 InstructionPointer()55 target_addr_t InstructionPointer() const 56 { return fInstructionPointer; } 57 PreviousCpuState()58 CpuState* PreviousCpuState() const 59 { return fPreviousCpuState; } 60 void SetPreviousCpuState(CpuState* state); 61 ReturnAddress()62 target_addr_t ReturnAddress() const { return fReturnAddress; } 63 void SetReturnAddress(target_addr_t address); 64 GetImage()65 Image* GetImage() const { return fImage; } 66 void SetImage(Image* image); 67 Function()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 Values()79 StackFrameValues* Values() const { return fValues; } ValueInfos()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 89 private: 90 typedef BObjectList<Variable> VariableList; 91 typedef DoublyLinkedList<Listener> ListenerList; 92 93 private: 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 111 class StackFrame::Listener : public DoublyLinkedListLinkImpl<Listener> { 112 public: 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