xref: /haiku/src/kits/debugger/jobs/Jobs.h (revision 8a6724a0ee3803f1e9f487d8111bb3f6cb8d16db)
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 
18 class Architecture;
19 class BVariant;
20 class CpuState;
21 class DebuggerInterface;
22 class ExpressionInfo;
23 class ExpressionResult;
24 class Function;
25 class FunctionInstance;
26 class Image;
27 class SourceLanguage;
28 class StackFrame;
29 class StackFrameValues;
30 class Team;
31 class TeamMemory;
32 class TeamMemoryBlock;
33 class TeamTypeInformation;
34 class Thread;
35 class Type;
36 class TypeComponentPath;
37 class Value;
38 class ValueLocation;
39 class ValueNode;
40 class ValueNodeChild;
41 class ValueNodeContainer;
42 class ValueNodeManager;
43 class Variable;
44 
45 
46 // job types
47 enum {
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 
63 class GetThreadStateJob : public Job {
64 public:
65 								GetThreadStateJob(
66 									DebuggerInterface* debuggerInterface,
67 									Thread* thread);
68 	virtual						~GetThreadStateJob();
69 
70 	virtual	const JobKey&		Key() const;
71 	virtual	status_t			Do();
72 
73 private:
74 			SimpleJobKey		fKey;
75 			DebuggerInterface*	fDebuggerInterface;
76 			Thread*				fThread;
77 };
78 
79 
80 class GetCpuStateJob : public Job {
81 public:
82 								GetCpuStateJob(
83 									DebuggerInterface* debuggerInterface,
84 									::Thread* thread);
85 	virtual						~GetCpuStateJob();
86 
87 	virtual	const JobKey&		Key() const;
88 	virtual	status_t			Do();
89 
90 private:
91 			SimpleJobKey		fKey;
92 			DebuggerInterface*	fDebuggerInterface;
93 			::Thread*			fThread;
94 };
95 
96 
97 class GetStackTraceJob : public Job, private ImageDebugInfoProvider {
98 public:
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 
109 private:
110 	// ImageDebugInfoProvider
111 	virtual	status_t			GetImageDebugInfo(Image* image,
112 									ImageDebugInfo*& _info);
113 
114 private:
115 			SimpleJobKey		fKey;
116 			DebuggerInterface*	fDebuggerInterface;
117 			JobListener*		fJobListener;
118 			Architecture*		fArchitecture;
119 			::Thread*			fThread;
120 			CpuState*			fCpuState;
121 };
122 
123 
124 class LoadImageDebugInfoJob : public Job {
125 public:
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 
148 private:
149 			SimpleJobKey		fKey;
150 			Image*				fImage;
151 			ImageDebugInfoLoadingState
152 								fState;
153 };
154 
155 
156 class LoadSourceCodeJob : public Job {
157 public:
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 
168 private:
169 			SimpleJobKey		fKey;
170 			DebuggerInterface*	fDebuggerInterface;
171 			Architecture*		fArchitecture;
172 			Team*				fTeam;
173 			FunctionInstance*	fFunctionInstance;
174 			bool				fLoadForFunction;
175 };
176 
177 
178 class ResolveValueNodeValueJob : public Job {
179 public:
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 
192 private:
193 			status_t			_ResolveNodeValue();
194 			status_t			_ResolveNodeChildLocation(
195 									ValueNodeChild* nodeChild);
196 			status_t			_ResolveParentNodeValue(ValueNode* parentNode);
197 
198 
199 private:
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 
211 class WriteValueNodeValueJob : public Job {
212 public:
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 
225 private:
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 
237 class RetrieveMemoryBlockJob : public Job {
238 public:
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 
247 private:
248 			SimpleJobKey		fKey;
249 			Team*				fTeam;
250 			TeamMemory*			fTeamMemory;
251 			TeamMemoryBlock*	fMemoryBlock;
252 };
253 
254 
255 class WriteMemoryJob : public Job {
256 public:
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 
266 private:
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 
276 class ExpressionEvaluationJob : public Job {
277 public:
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 
291 private:
292 			status_t			ResolveNodeValue(ValueNode* node);
293 
294 private:
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 
309 class WriteCoreFileJob : public Job {
310 public:
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 
319 private:
320 			SimpleJobKey		fKey;
321 			Team*				fTeam;
322 			DebuggerInterface*	fDebuggerInterface;
323 			entry_ref			fTargetPath;
324 };
325 
326 
327 #endif	// JOBS_H
328