2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
5 #ifndef DWARF_EXPRESSION_EVALUATOR_H
6 #define DWARF_EXPRESSION_EVALUATOR_H
9 #include "DataReader.h"
13 class DwarfTargetInterface
;
15 struct ValuePieceLocation
;
18 class DwarfExpressionEvaluationContext
{
20 DwarfExpressionEvaluationContext(
21 const DwarfTargetInterface
* targetInterface
,
23 target_addr_t relocationDelta
);
24 virtual ~DwarfExpressionEvaluationContext();
26 const DwarfTargetInterface
* TargetInterface() const
27 { return fTargetInterface
; }
28 uint8
AddressSize() const { return fAddressSize
; }
30 target_addr_t
RelocationDelta() const
31 { return fRelocationDelta
; }
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
)
37 virtual bool GetTLSAddress(target_addr_t localAddress
,
38 target_addr_t
& _address
) = 0;
40 virtual status_t
GetCallTarget(uint64 offset
,
41 uint8 refType
, const void*& _block
,
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
49 const DwarfTargetInterface
* fTargetInterface
;
51 target_addr_t fRelocationDelta
;
55 class DwarfExpressionEvaluator
{
57 DwarfExpressionEvaluator(
58 DwarfExpressionEvaluationContext
* context
);
59 ~DwarfExpressionEvaluator();
61 status_t
Push(target_addr_t value
);
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).
72 struct EvaluationException
;
75 inline void _AssertMinStackSize(size_t size
) const;
77 inline void _Push(target_addr_t value
);
78 inline target_addr_t
_Pop();
80 status_t
_Evaluate(ValuePieceLocation
* _piece
);
81 void _DereferenceAddress(uint8 addressSize
);
82 void _DereferenceAddressSpaceAddress(
84 void _PushRegister(uint32 reg
, target_addr_t offset
);
85 void _Call(uint64 offset
, uint8 refType
);
88 DwarfExpressionEvaluationContext
* fContext
;
89 target_addr_t
* fStack
;
91 size_t fStackCapacity
;
92 DataReader fDataReader
;
93 target_addr_t fObjectAddress
;
94 target_addr_t fFrameAddress
;
95 bool fObjectAddressValid
;
96 bool fFrameAddressValid
;
100 #endif // DWARF_EXPRESSION_EVALUATOR_H