2 * Copyright 2015, Rene Gollent, rene@gollent.com.
3 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
4 * Distributed under the terms of the MIT License.
8 #include "AddressValueNode.h"
12 #include "AddressValue.h"
13 #include "Architecture.h"
16 #include "ValueLoader.h"
17 #include "ValueLocation.h"
18 #include "ValueNodeContainer.h"
21 // #pragma mark - AddressValueNode
24 AddressValueNode::AddressValueNode(ValueNodeChild
* nodeChild
,
31 fType
->AcquireReference();
35 AddressValueNode::~AddressValueNode()
38 fChild
->ReleaseReference();
39 fType
->ReleaseReference();
44 AddressValueNode::GetType() const
51 AddressValueNode::ResolvedLocationAndValue(ValueLoader
* valueLoader
,
52 ValueLocation
*& _location
, Value
*& _value
)
55 ValueLocation
* location
= NodeChild()->Location();
59 TRACE_LOCALS(" TYPE_ADDRESS\n");
63 if (valueLoader
->GetArchitecture()->AddressSize() == 4) {
64 valueType
= B_UINT32_TYPE
;
65 TRACE_LOCALS(" -> 32 bit\n");
67 valueType
= B_UINT64_TYPE
;
68 TRACE_LOCALS(" -> 64 bit\n");
71 // load the value data
73 status_t error
= valueLoader
->LoadValue(location
, valueType
, false,
78 // create the type object
79 Value
* value
= new(std::nothrow
) AddressValue(valueData
);
83 location
->AcquireReference();
91 AddressValueNode::CreateChildren(TeamTypeInformation
* info
)
96 // For function pointers, don't bother creating a child, as there
97 // currently isn't any useful information that can be presented there,
98 // and the address node's value already indicates the instruction pointer
99 // of the target function.
100 // TODO: an eventual future possibility might be for a child node to
101 // indicate the name of the function being pointed to, if target address
103 Type
* baseType
= fType
->BaseType();
104 if (baseType
!= NULL
&& baseType
->Kind() == TYPE_FUNCTION
)
112 fChild
= new(std::nothrow
) AddressValueNodeChild(this, name
,
117 fChild
->SetContainer(fContainer
);
119 if (fContainer
!= NULL
)
120 fContainer
->NotifyValueNodeChildrenCreated(this);
127 AddressValueNode::CountChildren() const
129 return fChild
!= NULL
? 1 : 0;
134 AddressValueNode::ChildAt(int32 index
) const
136 return index
== 0 ? fChild
: NULL
;
140 // #pragma mark - AddressValueNodeChild
143 AddressValueNodeChild::AddressValueNodeChild(AddressValueNode
* parent
,
144 const BString
& name
, Type
* type
)
150 fType
->AcquireReference();
154 AddressValueNodeChild::~AddressValueNodeChild()
156 fType
->ReleaseReference();
161 AddressValueNodeChild::Name() const
168 AddressValueNodeChild::GetType() const
175 AddressValueNodeChild::Parent() const
182 AddressValueNodeChild::ResolveLocation(ValueLoader
* valueLoader
,
183 ValueLocation
*& _location
)
185 // The parent's value is an address pointing to this component.
186 AddressValue
* parentValue
= dynamic_cast<AddressValue
*>(
187 fParent
->GetValue());
188 if (parentValue
== NULL
)
191 // resolve the location
192 ValueLocation
* location
;
193 status_t error
= fType
->ResolveObjectDataLocation(parentValue
->ToUInt64(),
196 TRACE_LOCALS("AddressValueNodeChild::ResolveLocation(): "
197 "ResolveObjectDataLocation() failed: %s\n", strerror(error
));
201 _location
= location
;