1 /*
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.
5 */
6
7 #include "Jobs.h"
8
9 #include <AutoLocker.h>
10
11 #include "Architecture.h"
12 #include "CpuState.h"
13 #include "DebuggerInterface.h"
14 #include "TeamTypeInformation.h"
15 #include "Tracing.h"
16 #include "Value.h"
17 #include "ValueLocation.h"
18 #include "ValueNode.h"
19 #include "ValueNodeContainer.h"
20 #include "ValueWriter.h"
21
22
WriteValueNodeValueJob(DebuggerInterface * debuggerInterface,Architecture * architecture,CpuState * cpuState,TeamTypeInformation * typeInformation,ValueNode * valueNode,Value * newValue)23 WriteValueNodeValueJob::WriteValueNodeValueJob(
24 DebuggerInterface* debuggerInterface, Architecture* architecture,
25 CpuState* cpuState, TeamTypeInformation* typeInformation,
26 ValueNode* valueNode, Value* newValue)
27 :
28 fKey(valueNode, JOB_TYPE_WRITE_VALUE_NODE_VALUE),
29 fDebuggerInterface(debuggerInterface),
30 fArchitecture(architecture),
31 fCpuState(cpuState),
32 fTypeInformation(typeInformation),
33 fValueNode(valueNode),
34 fNewValue(newValue)
35 {
36 if (fCpuState != NULL)
37 fCpuState->AcquireReference();
38 fValueNode->AcquireReference();
39 fNewValue->AcquireReference();
40 }
41
42
~WriteValueNodeValueJob()43 WriteValueNodeValueJob::~WriteValueNodeValueJob()
44 {
45 if (fCpuState != NULL)
46 fCpuState->ReleaseReference();
47 fValueNode->ReleaseReference();
48 fNewValue->ReleaseReference();
49 }
50
51
52 const JobKey&
Key() const53 WriteValueNodeValueJob::Key() const
54 {
55 return fKey;
56 }
57
58
59 status_t
Do()60 WriteValueNodeValueJob::Do()
61 {
62 ValueNodeContainer* container = fValueNode->Container();
63 if (container == NULL)
64 return B_BAD_VALUE;
65
66 ValueWriter writer(fArchitecture, fDebuggerInterface,
67 fCpuState, -1);
68
69 BVariant value;
70 fNewValue->ToVariant(value);
71
72 status_t error = writer.WriteValue(fValueNode->Location(), value);
73 if (error != B_OK)
74 return error;
75
76 AutoLocker<ValueNodeContainer> containerLocker(container);
77 fValueNode->SetLocationAndValue(fValueNode->Location(), fNewValue, B_OK);
78
79 return B_OK;
80 }
81