2 * Copyright 2014-2016, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
10 #include <AutoLocker.h>
12 #include "DebuggerInterface.h"
13 #include "ExpressionInfo.h"
14 #include "model/Thread.h"
15 #include "SourceLanguage.h"
16 #include "StackFrame.h"
20 #include "ValueNode.h"
21 #include "ValueNodeManager.h"
25 ExpressionEvaluationJob::ExpressionEvaluationJob(Team
* team
,
26 DebuggerInterface
* debuggerInterface
, SourceLanguage
* language
,
27 ExpressionInfo
* info
, StackFrame
* frame
,
30 fKey(info
->Expression(), JOB_TYPE_EVALUATE_EXPRESSION
),
32 fDebuggerInterface(debuggerInterface
),
33 fArchitecture(debuggerInterface
->GetArchitecture()),
34 fTypeInformation(team
->GetTeamTypeInformation()),
36 fExpressionInfo(info
),
42 fLanguage
->AcquireReference();
43 fExpressionInfo
->AcquireReference();
46 fFrame
->AcquireReference();
48 fThread
->AcquireReference();
52 ExpressionEvaluationJob::~ExpressionEvaluationJob()
54 fLanguage
->ReleaseReference();
55 fExpressionInfo
->ReleaseReference();
57 fFrame
->ReleaseReference();
59 fThread
->ReleaseReference();
61 fManager
->ReleaseReference();
62 if (fResultValue
!= NULL
)
63 fResultValue
->ReleaseReference();
68 ExpressionEvaluationJob::Key() const
75 ExpressionEvaluationJob::Do()
77 BReference
<Value
> reference
;
78 status_t result
= B_OK
;
79 if (fFrame
!= NULL
&& fManager
== NULL
) {
80 fManager
= new(std::nothrow
) ValueNodeManager();
84 result
= fManager
->SetStackFrame(fThread
, fFrame
);
88 fExpressionInfo
->NotifyExpressionEvaluated(result
, NULL
);
92 ValueNode
* neededNode
= NULL
;
93 result
= fLanguage
->EvaluateExpression(fExpressionInfo
->Expression(),
94 fManager
, fTeam
->GetTeamTypeInformation(), fResultValue
, neededNode
);
95 if (neededNode
!= NULL
) {
96 result
= ResolveNodeValue(neededNode
);
97 if (State() == JOB_STATE_WAITING
)
99 // if result != B_OK, fall through
102 fExpressionInfo
->NotifyExpressionEvaluated(result
, fResultValue
);
109 ExpressionEvaluationJob::ResolveNodeValue(ValueNode
* node
)
111 AutoLocker
<Worker
> workerLocker(GetWorker());
112 SimpleJobKey
jobKey(node
, JOB_TYPE_RESOLVE_VALUE_NODE_VALUE
);
114 status_t error
= B_OK
;
115 if (GetWorker()->GetJob(jobKey
) == NULL
) {
116 workerLocker
.Unlock();
119 error
= GetWorker()->ScheduleJob(
120 new(std::nothrow
) ResolveValueNodeValueJob(fDebuggerInterface
,
121 fArchitecture
, fThread
->GetCpuState(), fTypeInformation
,
122 fManager
->GetContainer(), node
));
124 // scheduling failed -- set the value to invalid
125 node
->SetLocationAndValue(NULL
, NULL
, error
);
130 // wait for the job to finish
131 workerLocker
.Unlock();
134 switch (WaitFor(jobKey
)) {
135 case JOB_DEPENDENCY_SUCCEEDED
:
136 case JOB_DEPENDENCY_NOT_FOUND
:
137 case JOB_DEPENDENCY_ACTIVE
:
140 case JOB_DEPENDENCY_FAILED
:
141 case JOB_DEPENDENCY_ABORTED
: