haiku/src/apps/debugger/Worker.h

199 lines
4.0 KiB
C
Raw Normal View History

/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef WORKER_H
#define WORKER_H
#include <Locker.h>
#include <ObjectList.h>
* Worker: - Made Job Referenceable. - Turned JobKey into an abstract base class to add flexibility. The new SimpleJobKey is a subclass with the former functionality. * TeamWindow: Removed the TeamWindow* parameter from the listener hooks. The TeamDebugger knows anyway. * Added IDs to Variable, Function, and FunctionInstance. The latter two generate the ID on the fly, Variable stores it. * SpecificImageDebugInfo::CreateFrame(): Changed FunctionDebugInfo* debug parameter to FunctionInstance* to provide more info (the function ID). * DwarfInterfaceFactory/DwarfImageDebugInfo: - Added class DwarfFunctionParameterID, an ID class implementation for function parameters and set the IDs on the parameter objects. - Retrieve the size of a type (i.e. the size of its objects) and store it in DwarfType. - If a parameter's ValueLocation doesn't have a size, set that of the respective type. - Map the register indicies in the parameters' ValueLocations from DWARF to our indices. * Added class TypeComponentPath for identifying subcomponents in types. * Added class StackFrameValues, a container associating variables and their subcomponents with values. * StackFrame does now have a StackFrameValues object for parameters and local variables and a mechanism to notify listeners when values have been retrieved. * Added GetStackFrameValueJob to retrieve variable values. Lots of functionality is missing yet. Most notably it doesn't retrieves values for subcomponents. * Wired everything to trigger loading of variable values and getting notified when done. * VariablesView: Added a value column. This is all very basic and has to be done differently, but at least values for the parameters can be seen already. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31636 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-07-19 03:52:16 +04:00
#include <Referenceable.h>
#include <util/DoublyLinkedList.h>
#include <util/OpenHashTable.h>
class Job;
class Worker;
enum job_state {
JOB_STATE_UNSCHEDULED,
JOB_STATE_WAITING,
JOB_STATE_ACTIVE,
JOB_STATE_ABORTED,
JOB_STATE_FAILED,
JOB_STATE_SUCCEEDED
};
enum job_wait_status {
JOB_DEPENDENCY_NOT_FOUND,
JOB_DEPENDENCY_SUCCEEDED,
JOB_DEPENDENCY_FAILED,
JOB_DEPENDENCY_ABORTED,
JOB_DEPENDENCY_ACTIVE
// internal only
};
* Worker: - Made Job Referenceable. - Turned JobKey into an abstract base class to add flexibility. The new SimpleJobKey is a subclass with the former functionality. * TeamWindow: Removed the TeamWindow* parameter from the listener hooks. The TeamDebugger knows anyway. * Added IDs to Variable, Function, and FunctionInstance. The latter two generate the ID on the fly, Variable stores it. * SpecificImageDebugInfo::CreateFrame(): Changed FunctionDebugInfo* debug parameter to FunctionInstance* to provide more info (the function ID). * DwarfInterfaceFactory/DwarfImageDebugInfo: - Added class DwarfFunctionParameterID, an ID class implementation for function parameters and set the IDs on the parameter objects. - Retrieve the size of a type (i.e. the size of its objects) and store it in DwarfType. - If a parameter's ValueLocation doesn't have a size, set that of the respective type. - Map the register indicies in the parameters' ValueLocations from DWARF to our indices. * Added class TypeComponentPath for identifying subcomponents in types. * Added class StackFrameValues, a container associating variables and their subcomponents with values. * StackFrame does now have a StackFrameValues object for parameters and local variables and a mechanism to notify listeners when values have been retrieved. * Added GetStackFrameValueJob to retrieve variable values. Lots of functionality is missing yet. Most notably it doesn't retrieves values for subcomponents. * Wired everything to trigger loading of variable values and getting notified when done. * VariablesView: Added a value column. This is all very basic and has to be done differently, but at least values for the parameters can be seen already. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31636 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-07-19 03:52:16 +04:00
class JobKey {
public:
virtual ~JobKey();
virtual uint32 HashValue() const = 0;
virtual bool operator==(const JobKey& other) const = 0;
};
struct SimpleJobKey : public JobKey {
void* object;
uint32 type;
public:
SimpleJobKey(void* object, uint32 type);
SimpleJobKey(const SimpleJobKey& other);
virtual uint32 HashValue() const;
virtual bool operator==(const JobKey& other) const;
SimpleJobKey& operator=(const SimpleJobKey& other);
};
class JobListener {
public:
virtual ~JobListener();
virtual void JobDone(Job* job);
virtual void JobFailed(Job* job);
virtual void JobAborted(Job* job);
};
typedef DoublyLinkedList<Job> JobList;
* Worker: - Made Job Referenceable. - Turned JobKey into an abstract base class to add flexibility. The new SimpleJobKey is a subclass with the former functionality. * TeamWindow: Removed the TeamWindow* parameter from the listener hooks. The TeamDebugger knows anyway. * Added IDs to Variable, Function, and FunctionInstance. The latter two generate the ID on the fly, Variable stores it. * SpecificImageDebugInfo::CreateFrame(): Changed FunctionDebugInfo* debug parameter to FunctionInstance* to provide more info (the function ID). * DwarfInterfaceFactory/DwarfImageDebugInfo: - Added class DwarfFunctionParameterID, an ID class implementation for function parameters and set the IDs on the parameter objects. - Retrieve the size of a type (i.e. the size of its objects) and store it in DwarfType. - If a parameter's ValueLocation doesn't have a size, set that of the respective type. - Map the register indicies in the parameters' ValueLocations from DWARF to our indices. * Added class TypeComponentPath for identifying subcomponents in types. * Added class StackFrameValues, a container associating variables and their subcomponents with values. * StackFrame does now have a StackFrameValues object for parameters and local variables and a mechanism to notify listeners when values have been retrieved. * Added GetStackFrameValueJob to retrieve variable values. Lots of functionality is missing yet. Most notably it doesn't retrieves values for subcomponents. * Wired everything to trigger loading of variable values and getting notified when done. * VariablesView: Added a value column. This is all very basic and has to be done differently, but at least values for the parameters can be seen already. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31636 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-07-19 03:52:16 +04:00
class Job : public Referenceable, public DoublyLinkedListLinkImpl<Job>,
public HashTableLink<Job> {
public:
Job();
virtual ~Job();
* Worker: - Made Job Referenceable. - Turned JobKey into an abstract base class to add flexibility. The new SimpleJobKey is a subclass with the former functionality. * TeamWindow: Removed the TeamWindow* parameter from the listener hooks. The TeamDebugger knows anyway. * Added IDs to Variable, Function, and FunctionInstance. The latter two generate the ID on the fly, Variable stores it. * SpecificImageDebugInfo::CreateFrame(): Changed FunctionDebugInfo* debug parameter to FunctionInstance* to provide more info (the function ID). * DwarfInterfaceFactory/DwarfImageDebugInfo: - Added class DwarfFunctionParameterID, an ID class implementation for function parameters and set the IDs on the parameter objects. - Retrieve the size of a type (i.e. the size of its objects) and store it in DwarfType. - If a parameter's ValueLocation doesn't have a size, set that of the respective type. - Map the register indicies in the parameters' ValueLocations from DWARF to our indices. * Added class TypeComponentPath for identifying subcomponents in types. * Added class StackFrameValues, a container associating variables and their subcomponents with values. * StackFrame does now have a StackFrameValues object for parameters and local variables and a mechanism to notify listeners when values have been retrieved. * Added GetStackFrameValueJob to retrieve variable values. Lots of functionality is missing yet. Most notably it doesn't retrieves values for subcomponents. * Wired everything to trigger loading of variable values and getting notified when done. * VariablesView: Added a value column. This is all very basic and has to be done differently, but at least values for the parameters can be seen already. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31636 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-07-19 03:52:16 +04:00
virtual const JobKey& Key() const = 0;
virtual status_t Do() = 0;
Worker* GetWorker() const { return fWorker; }
job_state State() const { return fState; }
protected:
job_wait_status WaitFor(const JobKey& key);
private:
friend class Worker;
private:
void SetWorker(Worker* worker);
void SetState(job_state state);
Job* Dependency() const { return fDependency; }
void SetDependency(Job* job);
JobList& DependentJobs() { return fDependentJobs; }
job_wait_status WaitStatus() const { return fWaitStatus; }
void SetWaitStatus(job_wait_status status);
status_t AddListener(JobListener* listener);
void RemoveListener(JobListener* listener);
void NotifyListeners();
private:
typedef BObjectList<JobListener> ListenerList;
private:
Worker* fWorker;
job_state fState;
Job* fDependency;
JobList fDependentJobs;
job_wait_status fWaitStatus;
ListenerList fListeners;
};
class Worker {
public:
Worker();
~Worker();
status_t Init();
void ShutDown();
bool Lock() { return fLock.Lock(); }
void Unlock() { fLock.Unlock(); }
status_t ScheduleJob(Job* job,
JobListener* listener = NULL);
* Worker: - Made Job Referenceable. - Turned JobKey into an abstract base class to add flexibility. The new SimpleJobKey is a subclass with the former functionality. * TeamWindow: Removed the TeamWindow* parameter from the listener hooks. The TeamDebugger knows anyway. * Added IDs to Variable, Function, and FunctionInstance. The latter two generate the ID on the fly, Variable stores it. * SpecificImageDebugInfo::CreateFrame(): Changed FunctionDebugInfo* debug parameter to FunctionInstance* to provide more info (the function ID). * DwarfInterfaceFactory/DwarfImageDebugInfo: - Added class DwarfFunctionParameterID, an ID class implementation for function parameters and set the IDs on the parameter objects. - Retrieve the size of a type (i.e. the size of its objects) and store it in DwarfType. - If a parameter's ValueLocation doesn't have a size, set that of the respective type. - Map the register indicies in the parameters' ValueLocations from DWARF to our indices. * Added class TypeComponentPath for identifying subcomponents in types. * Added class StackFrameValues, a container associating variables and their subcomponents with values. * StackFrame does now have a StackFrameValues object for parameters and local variables and a mechanism to notify listeners when values have been retrieved. * Added GetStackFrameValueJob to retrieve variable values. Lots of functionality is missing yet. Most notably it doesn't retrieves values for subcomponents. * Wired everything to trigger loading of variable values and getting notified when done. * VariablesView: Added a value column. This is all very basic and has to be done differently, but at least values for the parameters can be seen already. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31636 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-07-19 03:52:16 +04:00
// always takes over reference
void AbortJob(const JobKey& key);
Job* GetJob(const JobKey& key);
status_t AddListener(const JobKey& key,
JobListener* listener);
void RemoveListener(const JobKey& key,
JobListener* listener);
private:
friend class Job;
struct JobHashDefinition {
typedef JobKey KeyType;
typedef Job ValueType;
size_t HashKey(const JobKey& key) const
{
return key.HashValue();
}
size_t Hash(Job* value) const
{
return HashKey(value->Key());
}
bool Compare(const JobKey& key, Job *value) const
{
return value->Key() == key;
}
HashTableLink<Job>* GetLink(Job* value) const
{
return value;
}
};
typedef OpenHashTable<JobHashDefinition> JobTable;
private:
job_wait_status WaitForJob(Job* waitingJob, const JobKey& key);
static status_t _WorkerLoopEntry(void* data);
status_t _WorkerLoop();
void _ProcessJobs(Job* finalJob);
void _AbortJob(Job* job, bool removeFromTable);
void _FinishJob(Job* job);
private:
BLocker fLock;
JobTable fJobs;
JobList fUnscheduledJobs;
JobList fAbortedJobs;
sem_id fWorkToDoSem;
thread_id fWorkerThread;
volatile bool fTerminating;
};
#endif // WORKER_H