1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2011, 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
10#include "ImageDebugInfoProvider.h"
11#include "Types.h"
12#include "Worker.h"
13
14
15class Architecture;
16class BVariant;
17class CpuState;
18class DebuggerInterface;
19class Function;
20class FunctionInstance;
21class Image;
22class StackFrame;
23class StackFrameValues;
24class Team;
25class TeamMemory;
26class TeamMemoryBlock;
27class TeamTypeInformation;
28class Thread;
29class Type;
30class TypeComponentPath;
31class ValueLocation;
32class ValueNode;
33class ValueNodeChild;
34class ValueNodeContainer;
35class Variable;
36
37
38// job types
39enum {
40	JOB_TYPE_GET_THREAD_STATE,
41	JOB_TYPE_GET_CPU_STATE,
42	JOB_TYPE_GET_STACK_TRACE,
43	JOB_TYPE_LOAD_IMAGE_DEBUG_INFO,
44	JOB_TYPE_LOAD_SOURCE_CODE,
45	JOB_TYPE_GET_STACK_FRAME_VALUE,
46	JOB_TYPE_RESOLVE_VALUE_NODE_VALUE,
47	JOB_TYPE_GET_MEMORY_BLOCK
48};
49
50
51class GetThreadStateJob : public Job {
52public:
53								GetThreadStateJob(
54									DebuggerInterface* debuggerInterface,
55									Thread* thread);
56	virtual						~GetThreadStateJob();
57
58	virtual	const JobKey&		Key() const;
59	virtual	status_t			Do();
60
61private:
62			SimpleJobKey		fKey;
63			DebuggerInterface*	fDebuggerInterface;
64			Thread*				fThread;
65};
66
67
68class GetCpuStateJob : public Job {
69public:
70								GetCpuStateJob(
71									DebuggerInterface* debuggerInterface,
72									Thread* thread);
73	virtual						~GetCpuStateJob();
74
75	virtual	const JobKey&		Key() const;
76	virtual	status_t			Do();
77
78private:
79			SimpleJobKey		fKey;
80			DebuggerInterface*	fDebuggerInterface;
81			Thread*				fThread;
82};
83
84
85class GetStackTraceJob : public Job, private ImageDebugInfoProvider {
86public:
87								GetStackTraceJob(
88									DebuggerInterface* debuggerInterface,
89									Architecture* architecture, Thread* thread);
90	virtual						~GetStackTraceJob();
91
92	virtual	const JobKey&		Key() const;
93	virtual	status_t			Do();
94
95private:
96	// ImageDebugInfoProvider
97	virtual	status_t			GetImageDebugInfo(Image* image,
98									ImageDebugInfo*& _info);
99
100private:
101			SimpleJobKey		fKey;
102			DebuggerInterface*	fDebuggerInterface;
103			Architecture*		fArchitecture;
104			Thread*				fThread;
105			CpuState*			fCpuState;
106};
107
108
109class LoadImageDebugInfoJob : public Job {
110public:
111								LoadImageDebugInfoJob(Image* image);
112	virtual						~LoadImageDebugInfoJob();
113
114	virtual	const JobKey&		Key() const;
115	virtual	status_t			Do();
116
117	static	status_t			ScheduleIfNecessary(Worker* worker,
118									Image* image,
119									ImageDebugInfo** _imageDebugInfo = NULL);
120										// If already loaded returns a
121										// reference, if desired. If not loaded
122										// schedules a job, but does not wait;
123										// returns B_OK and NULL. An error,
124										// if scheduling the job failed, or the
125										// debug info already failed to load
126										// earlier.
127
128private:
129			SimpleJobKey		fKey;
130			Image*				fImage;
131};
132
133
134class LoadSourceCodeJob : public Job {
135public:
136								LoadSourceCodeJob(
137									DebuggerInterface* debuggerInterface,
138									Architecture* architecture, Team* team,
139									FunctionInstance* functionInstance,
140									bool loadForFunction);
141	virtual						~LoadSourceCodeJob();
142
143	virtual	const JobKey&		Key() const;
144	virtual	status_t			Do();
145
146private:
147			SimpleJobKey		fKey;
148			DebuggerInterface*	fDebuggerInterface;
149			Architecture*		fArchitecture;
150			Team*				fTeam;
151			FunctionInstance*	fFunctionInstance;
152			bool				fLoadForFunction;
153};
154
155
156class ResolveValueNodeValueJob : public Job {
157public:
158								ResolveValueNodeValueJob(
159									DebuggerInterface* debuggerInterface,
160									Architecture* architecture,
161									CpuState* cpuState,
162									TeamTypeInformation* typeInformation,
163									ValueNodeContainer*	container,
164									ValueNode* valueNode);
165	virtual						~ResolveValueNodeValueJob();
166
167	virtual	const JobKey&		Key() const;
168	virtual	status_t			Do();
169
170private:
171			status_t			_ResolveNodeValue();
172			status_t			_ResolveNodeChildLocation(
173									ValueNodeChild* nodeChild);
174			status_t			_ResolveParentNodeValue(ValueNode* parentNode);
175
176
177private:
178			SimpleJobKey		fKey;
179			DebuggerInterface*	fDebuggerInterface;
180			Architecture*		fArchitecture;
181			CpuState*			fCpuState;
182			TeamTypeInformation*
183								fTypeInformation;
184			ValueNodeContainer*	fContainer;
185			ValueNode*			fValueNode;
186};
187
188
189class RetrieveMemoryBlockJob : public Job {
190public:
191								RetrieveMemoryBlockJob(Team* team,
192									TeamMemory* teamMemory,
193									TeamMemoryBlock* memoryBlock);
194	virtual						~RetrieveMemoryBlockJob();
195
196	virtual const JobKey&		Key() const;
197	virtual status_t			Do();
198
199private:
200			SimpleJobKey		fKey;
201			Team*				fTeam;
202			TeamMemory*			fTeamMemory;
203			TeamMemoryBlock*	fMemoryBlock;
204};
205
206
207#endif	// JOBS_H
208