haiku/src/apps/debugger/model/Team.h

177 lines
4.3 KiB
C
Raw Normal View History

/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef TEAM_H
#define TEAM_H
#include <Locker.h>
#include "Image.h"
#include "ImageInfo.h"
#include "Thread.h"
#include "ThreadInfo.h"
// team event types
enum {
TEAM_EVENT_THREAD_ADDED,
TEAM_EVENT_THREAD_REMOVED,
TEAM_EVENT_IMAGE_ADDED,
TEAM_EVENT_IMAGE_REMOVED,
TEAM_EVENT_THREAD_STATE_CHANGED,
TEAM_EVENT_THREAD_CPU_STATE_CHANGED,
TEAM_EVENT_THREAD_STACK_TRACE_CHANGED,
TEAM_EVENT_IMAGE_DEBUG_INFO_CHANGED
};
Very much work in progress, not in a particularly working state. Haiku munged a good part of the source tree, so I rather get those changes into the repository before continuing. The general aim of the work is to deal with multiple instances of the same function, e.g. inlined or non-inlined inline functions or those weird duplicates gcc (4 at least) seems to be generating for no apparent reason. * Added classes FunctionInstance (wrapping FunctionDebugInfo) and Function. FunctionInstance represents a physical instance of a function (e.g. inlined function at a particular address). A Function collects all FunctionInstances referring to the same source code location. * Moved the SourceCode property from FunctionDebugInfo to Function accordingly. * Since SourceCode is no longer associated with a concrete function instance, several methods dealing with statements have been removed and the functionality has been provided through other means (e.g. TeamDebugModel or SpecificImageDebugModel). This part is not yet completed. * Introduced UserBreakpoint and UserBreakpointInstance. The user sets a breakpoint at a source code location, which is represented by a UserBreakpoint. Since that source location can be mapped to one address per instance of the respective function, UserBreakpoint has a UserBreakpointInstance per such function instance, which in turn refers to a Breakpoint (an actual breakpoint at an address). * Adjusted Breakpoint, BreakpointManager, and TeamDebugger accordingly. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31447 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-07-08 00:47:39 +04:00
class FunctionInstance;
class LocatableFile;
* Finished the transformation of the SourceCode interface: - Replaced StatementAtLine() by GetStatementLocationRange(), which doesn't return a statement (i.e. also target addresses), but just a range in the source code. This can also be implemented by FileSourceCode, which can therefore be used for more than one instance of a function. - Added GetStatementAtLocation() which kind of is also a replacement for StatementAtLine(), but is optional and only provided by DisassembledSourceCode. - Added GetSourceFile(), which has to be provided when GetStatementAtLocation() is not implemented. - Kicked the statement stuff out of FileSourceCode. It only knows source ranges, now. * Team: Added GetStatementAtSourceLocation(), which is the real replacement for SourceCode::StatementAtLine() in cases where a statement is actually needed. It uses SourceCode::GetStatementAtLocation(), if available and otherwise finds a function at the source location, and gets a statement for one of its instances. * TeamDebugInfo: Does now manage a source file -> functions map allowing to look up functions at source file locations. * DwarfImageDebugInfo: - Switched the path in the source code hash table key for a LocatableFile, which is cheaper to hash and to compare. - Fixed bugs where the relocation delta was ignored. - Replace a -1 in the SourceLocation column component by 0 to avoid mismatches. * SourceLocation: Changed component types from uint32 to int32. Otherwise -1 is not representable. Things mostly work as before starting the refactoring to support function instances. All is not well yet, though. E.g. we don't merge the source code information for common source files (like headers) provided by different compilation units (or even images) yet. We need to do that, since the debug info for a compilation unit only contains line number information for inline functions (in headers) that are actually used. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31495 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-07-10 04:08:45 +04:00
class SourceCode;
class SourceLocation;
Very much work in progress, not in a particularly working state. Haiku munged a good part of the source tree, so I rather get those changes into the repository before continuing. The general aim of the work is to deal with multiple instances of the same function, e.g. inlined or non-inlined inline functions or those weird duplicates gcc (4 at least) seems to be generating for no apparent reason. * Added classes FunctionInstance (wrapping FunctionDebugInfo) and Function. FunctionInstance represents a physical instance of a function (e.g. inlined function at a particular address). A Function collects all FunctionInstances referring to the same source code location. * Moved the SourceCode property from FunctionDebugInfo to Function accordingly. * Since SourceCode is no longer associated with a concrete function instance, several methods dealing with statements have been removed and the functionality has been provided through other means (e.g. TeamDebugModel or SpecificImageDebugModel). This part is not yet completed. * Introduced UserBreakpoint and UserBreakpointInstance. The user sets a breakpoint at a source code location, which is represented by a UserBreakpoint. Since that source location can be mapped to one address per instance of the respective function, UserBreakpoint has a UserBreakpointInstance per such function instance, which in turn refers to a Breakpoint (an actual breakpoint at an address). * Adjusted Breakpoint, BreakpointManager, and TeamDebugger accordingly. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31447 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-07-08 00:47:39 +04:00
class Statement;
class TeamDebugInfo;
class Team : public BLocker {
public:
class Event;
class ThreadEvent;
class ImageEvent;
class Listener;
public:
Team(team_id teamID, TeamDebugInfo* debugInfo);
~Team();
status_t Init();
team_id ID() const { return fID; }
TeamDebugInfo* DebugInfo() const { return fDebugInfo; }
const char* Name() const { return fName.String(); }
void SetName(const BString& name);
void AddThread(Thread* thread);
status_t AddThread(const ThreadInfo& threadInfo,
Thread** _thread = NULL);
void RemoveThread(Thread* thread);
bool RemoveThread(thread_id threadID);
Thread* ThreadByID(thread_id threadID) const;
const ThreadList& Threads() const;
status_t AddImage(const ImageInfo& imageInfo,
LocatableFile* imageFile,
Image** _image = NULL);
void RemoveImage(Image* image);
bool RemoveImage(image_id imageID);
Image* ImageByID(image_id imageID) const;
Image* ImageByAddress(target_addr_t address) const;
const ImageList& Images() const;
Very much work in progress, not in a particularly working state. Haiku munged a good part of the source tree, so I rather get those changes into the repository before continuing. The general aim of the work is to deal with multiple instances of the same function, e.g. inlined or non-inlined inline functions or those weird duplicates gcc (4 at least) seems to be generating for no apparent reason. * Added classes FunctionInstance (wrapping FunctionDebugInfo) and Function. FunctionInstance represents a physical instance of a function (e.g. inlined function at a particular address). A Function collects all FunctionInstances referring to the same source code location. * Moved the SourceCode property from FunctionDebugInfo to Function accordingly. * Since SourceCode is no longer associated with a concrete function instance, several methods dealing with statements have been removed and the functionality has been provided through other means (e.g. TeamDebugModel or SpecificImageDebugModel). This part is not yet completed. * Introduced UserBreakpoint and UserBreakpointInstance. The user sets a breakpoint at a source code location, which is represented by a UserBreakpoint. Since that source location can be mapped to one address per instance of the respective function, UserBreakpoint has a UserBreakpointInstance per such function instance, which in turn refers to a Breakpoint (an actual breakpoint at an address). * Adjusted Breakpoint, BreakpointManager, and TeamDebugger accordingly. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31447 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-07-08 00:47:39 +04:00
status_t GetStatementAtAddress(target_addr_t address,
FunctionInstance*& _function,
Statement*& _statement);
// returns a reference to the statement,
// not to the functions instance, though,
// caller must lock
* Finished the transformation of the SourceCode interface: - Replaced StatementAtLine() by GetStatementLocationRange(), which doesn't return a statement (i.e. also target addresses), but just a range in the source code. This can also be implemented by FileSourceCode, which can therefore be used for more than one instance of a function. - Added GetStatementAtLocation() which kind of is also a replacement for StatementAtLine(), but is optional and only provided by DisassembledSourceCode. - Added GetSourceFile(), which has to be provided when GetStatementAtLocation() is not implemented. - Kicked the statement stuff out of FileSourceCode. It only knows source ranges, now. * Team: Added GetStatementAtSourceLocation(), which is the real replacement for SourceCode::StatementAtLine() in cases where a statement is actually needed. It uses SourceCode::GetStatementAtLocation(), if available and otherwise finds a function at the source location, and gets a statement for one of its instances. * TeamDebugInfo: Does now manage a source file -> functions map allowing to look up functions at source file locations. * DwarfImageDebugInfo: - Switched the path in the source code hash table key for a LocatableFile, which is cheaper to hash and to compare. - Fixed bugs where the relocation delta was ignored. - Replace a -1 in the SourceLocation column component by 0 to avoid mismatches. * SourceLocation: Changed component types from uint32 to int32. Otherwise -1 is not representable. Things mostly work as before starting the refactoring to support function instances. All is not well yet, though. E.g. we don't merge the source code information for common source files (like headers) provided by different compilation units (or even images) yet. We need to do that, since the debug info for a compilation unit only contains line number information for inline functions (in headers) that are actually used. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31495 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-07-10 04:08:45 +04:00
status_t GetStatementAtSourceLocation(
SourceCode* sourceCode,
const SourceLocation& location,
Statement*& _statement);
// returns a reference to the statement
// (any matching statement!),
// caller must lock,
Very much work in progress, not in a particularly working state. Haiku munged a good part of the source tree, so I rather get those changes into the repository before continuing. The general aim of the work is to deal with multiple instances of the same function, e.g. inlined or non-inlined inline functions or those weird duplicates gcc (4 at least) seems to be generating for no apparent reason. * Added classes FunctionInstance (wrapping FunctionDebugInfo) and Function. FunctionInstance represents a physical instance of a function (e.g. inlined function at a particular address). A Function collects all FunctionInstances referring to the same source code location. * Moved the SourceCode property from FunctionDebugInfo to Function accordingly. * Since SourceCode is no longer associated with a concrete function instance, several methods dealing with statements have been removed and the functionality has been provided through other means (e.g. TeamDebugModel or SpecificImageDebugModel). This part is not yet completed. * Introduced UserBreakpoint and UserBreakpointInstance. The user sets a breakpoint at a source code location, which is represented by a UserBreakpoint. Since that source location can be mapped to one address per instance of the respective function, UserBreakpoint has a UserBreakpointInstance per such function instance, which in turn refers to a Breakpoint (an actual breakpoint at an address). * Adjusted Breakpoint, BreakpointManager, and TeamDebugger accordingly. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31447 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-07-08 00:47:39 +04:00
void AddListener(Listener* listener);
void RemoveListener(Listener* listener);
// service methods for Thread
void NotifyThreadStateChanged(Thread* thread);
void NotifyThreadCpuStateChanged(Thread* thread);
void NotifyThreadStackTraceChanged(Thread* thread);
// service methods for Image
void NotifyImageDebugInfoChanged(Image* image);
private:
typedef DoublyLinkedList<Listener> ListenerList;
private:
void _NotifyThreadAdded(Thread* thread);
void _NotifyThreadRemoved(Thread* thread);
void _NotifyImageAdded(Image* image);
void _NotifyImageRemoved(Image* image);
private:
team_id fID;
TeamDebugInfo* fDebugInfo;
BString fName;
ThreadList fThreads;
ImageList fImages;
ListenerList fListeners;
};
class Team::Event {
public:
Event(uint32 type, Team* team);
uint32 EventType() const { return fEventType; }
Team* GetTeam() const { return fTeam; }
protected:
uint32 fEventType;
Team* fTeam;
};
class Team::ThreadEvent : public Event {
public:
ThreadEvent(uint32 type, Thread* thread);
Thread* GetThread() const { return fThread; }
protected:
Thread* fThread;
};
class Team::ImageEvent : public Event {
public:
ImageEvent(uint32 type, Image* image);
Image* GetImage() const { return fImage; }
protected:
Image* fImage;
};
class Team::Listener : public DoublyLinkedListLinkImpl<Team::Listener> {
public:
virtual ~Listener();
virtual void ThreadAdded(const Team::ThreadEvent& event);
virtual void ThreadRemoved(const Team::ThreadEvent& event);
virtual void ImageAdded(const Team::ImageEvent& event);
virtual void ImageRemoved(const Team::ImageEvent& event);
virtual void ThreadStateChanged(
const Team::ThreadEvent& event);
virtual void ThreadCpuStateChanged(
const Team::ThreadEvent& event);
virtual void ThreadStackTraceChanged(
const Team::ThreadEvent& event);
virtual void ImageDebugInfoChanged(
const Team::ImageEvent& event);
};
#endif // TEAM_H