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