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