2 * Copyright 2010, Rene Gollent, rene@gollent.com
3 * Distributed under the terms of the MIT License.
7 #include "CStringValueNode.h"
11 #include "Architecture.h"
12 #include "StringValue.h"
15 #include "ValueLoader.h"
16 #include "ValueLocation.h"
17 #include "ValueNodeContainer.h"
20 // #pragma mark - CStringValueNode
23 CStringValueNode::CStringValueNode(ValueNodeChild
* nodeChild
,
26 ChildlessValueNode(nodeChild
),
29 fType
->AcquireReference();
33 CStringValueNode::~CStringValueNode()
35 fType
->ReleaseReference();
40 CStringValueNode::GetType() const
47 CStringValueNode::ResolvedLocationAndValue(ValueLoader
* valueLoader
,
48 ValueLocation
*& _location
, Value
*& _value
)
51 ValueLocation
* location
= NodeChild()->Location();
55 TRACE_LOCALS(" TYPE_ADDRESS (C string)\n");
59 if (valueLoader
->GetArchitecture()->AddressSize() == 4) {
60 valueType
= B_UINT32_TYPE
;
61 TRACE_LOCALS(" -> 32 bit\n");
63 valueType
= B_UINT64_TYPE
;
64 TRACE_LOCALS(" -> 64 bit\n");
67 // load the value data
71 status_t error
= B_OK
;
73 if (dynamic_cast<AddressType
*>(fType
) != NULL
) {
74 error
= valueLoader
->LoadValue(location
, valueType
, false,
79 addressData
.SetTo(location
->PieceAt(0).address
);
80 maxSize
= dynamic_cast<ArrayType
*>(fType
)
81 ->DimensionAt(0)->CountElements();
84 ValuePieceLocation piece
;
85 piece
.SetToMemory(addressData
.ToUInt64());
87 TRACE_LOCALS(" Address found: %#" B_PRIx64
"\n",
88 addressData
.ToUInt64());
90 error
= valueLoader
->LoadStringValue(addressData
, maxSize
, valueData
);
94 piece
.size
= valueData
.Length();
96 TRACE_LOCALS(" String value found, length: %" B_PRIu64
"bytes\n",
99 ValueLocation
* stringLocation
= new(std::nothrow
) ValueLocation(
100 valueLoader
->GetArchitecture()->IsBigEndian(), piece
);
102 if (stringLocation
== NULL
)
105 BReference
<ValueLocation
> locationReference(stringLocation
, true);
107 error
= valueLoader
->LoadStringValue(addressData
, maxSize
, valueData
);
111 // create the type object
112 Value
* value
= new(std::nothrow
) StringValue(valueData
);
116 NodeChild()->SetLocation(stringLocation
, B_OK
);
117 _location
= locationReference
.Detach();