xref: /haiku/src/kits/debugger/dwarf/DwarfExpressionEvaluator.h (revision 3c16ba4e780846dc1973050c97b54d39c2eb854f)
1fce4895dSRene Gollent /*
2fce4895dSRene Gollent  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3fce4895dSRene Gollent  * Distributed under the terms of the MIT License.
4fce4895dSRene Gollent  */
5fce4895dSRene Gollent #ifndef DWARF_EXPRESSION_EVALUATOR_H
6fce4895dSRene Gollent #define DWARF_EXPRESSION_EVALUATOR_H
7fce4895dSRene Gollent 
8fce4895dSRene Gollent 
9fce4895dSRene Gollent #include "DataReader.h"
10fce4895dSRene Gollent #include "Types.h"
11fce4895dSRene Gollent 
12fce4895dSRene Gollent 
13fce4895dSRene Gollent class DwarfTargetInterface;
14fce4895dSRene Gollent class ValueLocation;
15fce4895dSRene Gollent struct ValuePieceLocation;
16fce4895dSRene Gollent 
17fce4895dSRene Gollent 
18fce4895dSRene Gollent class DwarfExpressionEvaluationContext {
19fce4895dSRene Gollent public:
20fce4895dSRene Gollent 								DwarfExpressionEvaluationContext(
21fce4895dSRene Gollent 									const DwarfTargetInterface* targetInterface,
22fce4895dSRene Gollent 									uint8 addressSize,
23*3c16ba4eSDavid Karoly 									bool isBigEndian,
24fce4895dSRene Gollent 									target_addr_t relocationDelta);
25fce4895dSRene Gollent 	virtual						~DwarfExpressionEvaluationContext();
26fce4895dSRene Gollent 
TargetInterface()27fce4895dSRene Gollent 			const DwarfTargetInterface* TargetInterface() const
28fce4895dSRene Gollent 									{ return fTargetInterface; }
AddressSize()29fce4895dSRene Gollent 			uint8				AddressSize() const	{ return fAddressSize; }
IsBigEndian()30*3c16ba4eSDavid Karoly 			bool				IsBigEndian() const { return fIsBigEndian; }
31fce4895dSRene Gollent 
RelocationDelta()32fce4895dSRene Gollent 			target_addr_t			RelocationDelta() const
33fce4895dSRene Gollent 									{ return fRelocationDelta; }
34fce4895dSRene Gollent 
35fce4895dSRene Gollent 	virtual	bool				GetObjectAddress(target_addr_t& _address) = 0;
36fce4895dSRene Gollent 	virtual	bool				GetFrameAddress(target_addr_t& _address) = 0;
37fce4895dSRene Gollent 	virtual	bool				GetFrameBaseAddress(target_addr_t& _address)
38fce4895dSRene Gollent 									= 0;
39fce4895dSRene Gollent 	virtual	bool				GetTLSAddress(target_addr_t localAddress,
40fce4895dSRene Gollent 									target_addr_t& _address) = 0;
41fce4895dSRene Gollent 
42fce4895dSRene Gollent 	virtual	status_t			GetCallTarget(uint64 offset,
43fce4895dSRene Gollent 									uint8 refType, const void*& _block,
44fce4895dSRene Gollent 									off_t& _size) = 0;
45fce4895dSRene Gollent 									// returns error, when an error resolving
46fce4895dSRene Gollent 									// the entry occurs; returns B_OK and a NULL
47fce4895dSRene Gollent 									// block, when the entry doesn't have a
48fce4895dSRene Gollent 									// location attribute
49fce4895dSRene Gollent 
50fce4895dSRene Gollent protected:
51fce4895dSRene Gollent 			const DwarfTargetInterface* fTargetInterface;
52fce4895dSRene Gollent 			uint8				fAddressSize;
53*3c16ba4eSDavid Karoly 			bool				fIsBigEndian;
54fce4895dSRene Gollent 			target_addr_t		fRelocationDelta;
55fce4895dSRene Gollent };
56fce4895dSRene Gollent 
57fce4895dSRene Gollent 
58fce4895dSRene Gollent class DwarfExpressionEvaluator {
59fce4895dSRene Gollent public:
60fce4895dSRene Gollent 								DwarfExpressionEvaluator(
61fce4895dSRene Gollent 									DwarfExpressionEvaluationContext* context);
62fce4895dSRene Gollent 								~DwarfExpressionEvaluator();
63fce4895dSRene Gollent 
64fce4895dSRene Gollent 			status_t			Push(target_addr_t value);
65fce4895dSRene Gollent 
66fce4895dSRene Gollent 			status_t			Evaluate(const void* expression, size_t size,
67fce4895dSRene Gollent 									target_addr_t& _result);
68fce4895dSRene Gollent 			status_t			EvaluateLocation(const void* expression,
69fce4895dSRene Gollent 									size_t size, ValueLocation& _location);
70fce4895dSRene Gollent 									// The returned location will have DWARF
71fce4895dSRene Gollent 									// semantics regarding register numbers and
72fce4895dSRene Gollent 									// bit offsets/sizes (cf. bit pieces).
73fce4895dSRene Gollent 
74fce4895dSRene Gollent private:
75fce4895dSRene Gollent 			struct EvaluationException;
76fce4895dSRene Gollent 
77fce4895dSRene Gollent private:
78fce4895dSRene Gollent 	inline	void				_AssertMinStackSize(size_t size) const;
79fce4895dSRene Gollent 
80fce4895dSRene Gollent 	inline	void				_Push(target_addr_t value);
81fce4895dSRene Gollent 	inline	target_addr_t		_Pop();
82fce4895dSRene Gollent 
83fce4895dSRene Gollent 			status_t			_Evaluate(ValuePieceLocation* _piece);
84fce4895dSRene Gollent 			void				_DereferenceAddress(uint8 addressSize);
85fce4895dSRene Gollent 			void				_DereferenceAddressSpaceAddress(
86fce4895dSRene Gollent 									uint8 addressSize);
87fce4895dSRene Gollent 			void				_PushRegister(uint32 reg, target_addr_t offset);
88fce4895dSRene Gollent 			void				_Call(uint64 offset, uint8 refType);
89fce4895dSRene Gollent 
90fce4895dSRene Gollent private:
91fce4895dSRene Gollent 			DwarfExpressionEvaluationContext* fContext;
92fce4895dSRene Gollent 			target_addr_t*		fStack;
93fce4895dSRene Gollent 			size_t				fStackSize;
94fce4895dSRene Gollent 			size_t				fStackCapacity;
95fce4895dSRene Gollent 			DataReader			fDataReader;
96fce4895dSRene Gollent 			target_addr_t		fObjectAddress;
97fce4895dSRene Gollent 			target_addr_t		fFrameAddress;
98fce4895dSRene Gollent 			bool				fObjectAddressValid;
99fce4895dSRene Gollent 			bool				fFrameAddressValid;
100fce4895dSRene Gollent };
101fce4895dSRene Gollent 
102fce4895dSRene Gollent 
103fce4895dSRene Gollent #endif	// DWARF_EXPRESSION_EVALUATOR_H
104