1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2011-2016, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
5 */
6#ifndef JOBS_H
7#define JOBS_H
8
9#include <Entry.h>
10#include <String.h>
11
12#include "ImageDebugInfoLoadingState.h"
13#include "ImageDebugInfoProvider.h"
14#include "Types.h"
15#include "Worker.h"
16
17
18class Architecture;
19class BVariant;
20class CpuState;
21class DebuggerInterface;
22class ExpressionInfo;
23class ExpressionResult;
24class Function;
25class FunctionInstance;
26class Image;
27class SourceLanguage;
28class StackFrame;
29class StackFrameValues;
30class Team;
31class TeamMemory;
32class TeamMemoryBlock;
33class TeamTypeInformation;
34class Thread;
35class Type;
36class TypeComponentPath;
37class Value;
38class ValueLocation;
39class ValueNode;
40class ValueNodeChild;
41class ValueNodeContainer;
42class ValueNodeManager;
43class Variable;
44
45
46// job types
47enum {
48	JOB_TYPE_GET_THREAD_STATE,
49	JOB_TYPE_GET_CPU_STATE,
50	JOB_TYPE_GET_STACK_TRACE,
51	JOB_TYPE_LOAD_IMAGE_DEBUG_INFO,
52	JOB_TYPE_LOAD_SOURCE_CODE,
53	JOB_TYPE_GET_STACK_FRAME_VALUE,
54	JOB_TYPE_RESOLVE_VALUE_NODE_VALUE,
55	JOB_TYPE_WRITE_VALUE_NODE_VALUE,
56	JOB_TYPE_GET_MEMORY_BLOCK,
57	JOB_TYPE_WRITE_MEMORY,
58	JOB_TYPE_EVALUATE_EXPRESSION,
59	JOB_TYPE_WRITE_CORE_FILE
60};
61
62
63class GetThreadStateJob : public Job {
64public:
65								GetThreadStateJob(
66									DebuggerInterface* debuggerInterface,
67									Thread* thread);
68	virtual						~GetThreadStateJob();
69
70	virtual	const JobKey&		Key() const;
71	virtual	status_t			Do();
72
73private:
74			SimpleJobKey		fKey;
75			DebuggerInterface*	fDebuggerInterface;
76			Thread*				fThread;
77};
78
79
80class GetCpuStateJob : public Job {
81public:
82								GetCpuStateJob(
83									DebuggerInterface* debuggerInterface,
84									::Thread* thread);
85	virtual						~GetCpuStateJob();
86
87	virtual	const JobKey&		Key() const;
88	virtual	status_t			Do();
89
90private:
91			SimpleJobKey		fKey;
92			DebuggerInterface*	fDebuggerInterface;
93			::Thread*			fThread;
94};
95
96
97class GetStackTraceJob : public Job, private ImageDebugInfoProvider {
98public:
99								GetStackTraceJob(
100									DebuggerInterface* debuggerInterface,
101									JobListener* jobListener,
102									Architecture* architecture,
103									::Thread* thread);
104	virtual						~GetStackTraceJob();
105
106	virtual	const JobKey&		Key() const;
107	virtual	status_t			Do();
108
109private:
110	// ImageDebugInfoProvider
111	virtual	status_t			GetImageDebugInfo(Image* image,
112									ImageDebugInfo*& _info);
113
114private:
115			SimpleJobKey		fKey;
116			DebuggerInterface*	fDebuggerInterface;
117			JobListener*		fJobListener;
118			Architecture*		fArchitecture;
119			::Thread*			fThread;
120			CpuState*			fCpuState;
121};
122
123
124class LoadImageDebugInfoJob : public Job {
125public:
126								LoadImageDebugInfoJob(Image* image);
127	virtual						~LoadImageDebugInfoJob();
128
129	virtual	const JobKey&		Key() const;
130	virtual	status_t			Do();
131
132	static	status_t			ScheduleIfNecessary(Worker* worker,
133									Image* image,
134									JobListener* jobListener,
135									ImageDebugInfo** _imageDebugInfo = NULL);
136										// If already loaded returns a
137										// reference, if desired. If not loaded
138										// schedules a job, but does not wait;
139										// returns B_OK and NULL. An error,
140										// if scheduling the job failed, or the
141										// debug info already failed to load
142										// earlier.
143
144			ImageDebugInfoLoadingState*
145									GetLoadingState()
146										{ return &fState; }
147
148private:
149			SimpleJobKey		fKey;
150			Image*				fImage;
151			ImageDebugInfoLoadingState
152								fState;
153};
154
155
156class LoadSourceCodeJob : public Job {
157public:
158								LoadSourceCodeJob(
159									DebuggerInterface* debuggerInterface,
160									Architecture* architecture, Team* team,
161									FunctionInstance* functionInstance,
162									bool loadForFunction);
163	virtual						~LoadSourceCodeJob();
164
165	virtual	const JobKey&		Key() const;
166	virtual	status_t			Do();
167
168private:
169			SimpleJobKey		fKey;
170			DebuggerInterface*	fDebuggerInterface;
171			Architecture*		fArchitecture;
172			Team*				fTeam;
173			FunctionInstance*	fFunctionInstance;
174			bool				fLoadForFunction;
175};
176
177
178class ResolveValueNodeValueJob : public Job {
179public:
180								ResolveValueNodeValueJob(
181									DebuggerInterface* debuggerInterface,
182									Architecture* architecture,
183									CpuState* cpuState,
184									TeamTypeInformation* typeInformation,
185									ValueNodeContainer*	container,
186									ValueNode* valueNode);
187	virtual						~ResolveValueNodeValueJob();
188
189	virtual	const JobKey&		Key() const;
190	virtual	status_t			Do();
191
192private:
193			status_t			_ResolveNodeValue();
194			status_t			_ResolveNodeChildLocation(
195									ValueNodeChild* nodeChild);
196			status_t			_ResolveParentNodeValue(ValueNode* parentNode);
197
198
199private:
200			SimpleJobKey		fKey;
201			DebuggerInterface*	fDebuggerInterface;
202			Architecture*		fArchitecture;
203			CpuState*			fCpuState;
204			TeamTypeInformation*
205								fTypeInformation;
206			ValueNodeContainer*	fContainer;
207			ValueNode*			fValueNode;
208};
209
210
211class WriteValueNodeValueJob : public Job {
212public:
213								WriteValueNodeValueJob(
214									DebuggerInterface* debuggerInterface,
215									Architecture* architecture,
216									CpuState* cpuState,
217									TeamTypeInformation* typeInformation,
218									ValueNode* valueNode,
219									Value* newValue);
220	virtual						~WriteValueNodeValueJob();
221
222	virtual	const JobKey&		Key() const;
223	virtual	status_t			Do();
224
225private:
226			SimpleJobKey		fKey;
227			DebuggerInterface*	fDebuggerInterface;
228			Architecture*		fArchitecture;
229			CpuState*			fCpuState;
230			TeamTypeInformation*
231								fTypeInformation;
232			ValueNode*			fValueNode;
233			Value*				fNewValue;
234};
235
236
237class RetrieveMemoryBlockJob : public Job {
238public:
239								RetrieveMemoryBlockJob(Team* team,
240									TeamMemory* teamMemory,
241									TeamMemoryBlock* memoryBlock);
242	virtual						~RetrieveMemoryBlockJob();
243
244	virtual const JobKey&		Key() const;
245	virtual status_t			Do();
246
247private:
248			SimpleJobKey		fKey;
249			Team*				fTeam;
250			TeamMemory*			fTeamMemory;
251			TeamMemoryBlock*	fMemoryBlock;
252};
253
254
255class WriteMemoryJob : public Job {
256public:
257								WriteMemoryJob(Team* team,
258									TeamMemory* teamMemory,
259									target_addr_t address, void* data,
260									target_size_t size);
261	virtual						~WriteMemoryJob();
262
263	virtual const JobKey&		Key() const;
264	virtual status_t			Do();
265
266private:
267			SimpleJobKey		fKey;
268			Team*				fTeam;
269			TeamMemory*			fTeamMemory;
270			target_addr_t		fTargetAddress;
271			void*				fData;
272			target_size_t		fSize;
273};
274
275
276class ExpressionEvaluationJob : public Job {
277public:
278								ExpressionEvaluationJob(Team* team,
279									DebuggerInterface* debuggerInterface,
280									SourceLanguage* language,
281									ExpressionInfo* info,
282									StackFrame* frame,
283									Thread* thread);
284	virtual						~ExpressionEvaluationJob();
285
286	virtual	const JobKey&		Key() const;
287	virtual	status_t			Do();
288
289			ExpressionResult*	GetResult() const { return fResultValue; }
290
291private:
292			status_t			ResolveNodeValue(ValueNode* node);
293
294private:
295			SimpleJobKey		fKey;
296			Team*				fTeam;
297			DebuggerInterface*	fDebuggerInterface;
298			Architecture*		fArchitecture;
299			TeamTypeInformation* fTypeInformation;
300			SourceLanguage*		fLanguage;
301			ExpressionInfo*		fExpressionInfo;
302			StackFrame*			fFrame;
303			Thread*				fThread;
304			ValueNodeManager*	fManager;
305			ExpressionResult*	fResultValue;
306};
307
308
309class WriteCoreFileJob : public Job {
310public:
311								WriteCoreFileJob(Team* team,
312									DebuggerInterface* debuggerInterface,
313									const entry_ref& targetPath);
314	virtual						~WriteCoreFileJob();
315
316	virtual	const JobKey&		Key() const;
317	virtual	status_t			Do();
318
319private:
320			SimpleJobKey		fKey;
321			Team*				fTeam;
322			DebuggerInterface*	fDebuggerInterface;
323			entry_ref			fTargetPath;
324};
325
326
327#endif	// JOBS_H
328