[Haiku-commits] r31100 - in haiku/trunk/src/apps/debugger: . debugger_interface

bonefish at BerliOS bonefish at mail.berlios.de
Thu Jun 18 19:57:39 CEST 2009


Author: bonefish
Date: 2009-06-18 19:57:37 +0200 (Thu, 18 Jun 2009)
New Revision: 31100
ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=31100&view=rev

Added:
   haiku/trunk/src/apps/debugger/CpuState.cpp
   haiku/trunk/src/apps/debugger/CpuState.h
   haiku/trunk/src/apps/debugger/ImageInfo.cpp
   haiku/trunk/src/apps/debugger/ImageInfo.h
   haiku/trunk/src/apps/debugger/ThreadInfo.cpp
   haiku/trunk/src/apps/debugger/ThreadInfo.h
   haiku/trunk/src/apps/debugger/debugger_interface/
   haiku/trunk/src/apps/debugger/debugger_interface/DebugEvent.cpp
   haiku/trunk/src/apps/debugger/debugger_interface/DebugEvent.h
   haiku/trunk/src/apps/debugger/debugger_interface/DebuggerInterface.cpp
   haiku/trunk/src/apps/debugger/debugger_interface/DebuggerInterface.h
Modified:
   haiku/trunk/src/apps/debugger/Image.cpp
   haiku/trunk/src/apps/debugger/Image.h
   haiku/trunk/src/apps/debugger/Jamfile
   haiku/trunk/src/apps/debugger/Team.cpp
   haiku/trunk/src/apps/debugger/Team.h
   haiku/trunk/src/apps/debugger/TeamDebugger.cpp
   haiku/trunk/src/apps/debugger/TeamDebugger.h
Log:
Moved all interaction with the kernel/debugger interface into new class
DebuggerInterface. This will simplify adding support for remote debugging
eventually.


Added: haiku/trunk/src/apps/debugger/CpuState.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/CpuState.cpp	2009-06-18 17:19:32 UTC (rev 31099)
+++ haiku/trunk/src/apps/debugger/CpuState.cpp	2009-06-18 17:57:37 UTC (rev 31100)
@@ -0,0 +1,11 @@
+/*
+ * Copyright 2009, Ingo Weinhold, ingo_weinhold at gmx.de.
+ * Distributed under the terms of the MIT License.
+ */
+
+#include "CpuState.h"
+
+
+CpuState::~CpuState()
+{
+}

Added: haiku/trunk/src/apps/debugger/CpuState.h
===================================================================
--- haiku/trunk/src/apps/debugger/CpuState.h	2009-06-18 17:19:32 UTC (rev 31099)
+++ haiku/trunk/src/apps/debugger/CpuState.h	2009-06-18 17:57:37 UTC (rev 31100)
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2009, Ingo Weinhold, ingo_weinhold at gmx.de.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef CPU_STATE_H
+#define CPU_STATE_H
+
+#include <OS.h>
+
+#include <Referenceable.h>
+
+
+class CpuState : public Referenceable {
+public:
+	virtual						~CpuState();
+};
+
+
+#endif	// CPU_STATE_H

Modified: haiku/trunk/src/apps/debugger/Image.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/Image.cpp	2009-06-18 17:19:32 UTC (rev 31099)
+++ haiku/trunk/src/apps/debugger/Image.cpp	2009-06-18 17:57:37 UTC (rev 31100)
@@ -6,7 +6,7 @@
 #include "Image.h"
 
 
-Image::Image(Team* team,const image_info& imageInfo)
+Image::Image(Team* team,const ImageInfo& imageInfo)
 	:
 	fTeam(team),
 	fInfo(imageInfo)

Modified: haiku/trunk/src/apps/debugger/Image.h
===================================================================
--- haiku/trunk/src/apps/debugger/Image.h	2009-06-18 17:19:32 UTC (rev 31099)
+++ haiku/trunk/src/apps/debugger/Image.h	2009-06-18 17:57:37 UTC (rev 31100)
@@ -10,26 +10,28 @@
 #include <Referenceable.h>
 #include <util/DoublyLinkedList.h>
 
+#include "ImageInfo.h"
 
+
 class Team;
 
 
 class Image : public Referenceable, public DoublyLinkedListLinkImpl<Image> {
 public:
-								Image(Team* team, const image_info& imageInfo);
+								Image(Team* team, const ImageInfo& imageInfo);
 								~Image();
 
 			status_t			Init();
 
-			
+
 			Team*				GetTeam() const	{ return fTeam; }
-			image_id			ID() const		{ return fInfo.id; }
-			const char*			Name() const	{ return fInfo.name; }
-			const image_info&	Info() const	{ return fInfo; }
+			image_id			ID() const		{ return fInfo.ImageID(); }
+			const char*			Name() const	{ return fInfo.Name(); }
+			const ImageInfo&	Info() const	{ return fInfo; }
 
 private:
 			Team*				fTeam;
-			image_info			fInfo;
+			ImageInfo			fInfo;
 };
 
 

Added: haiku/trunk/src/apps/debugger/ImageInfo.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/ImageInfo.cpp	2009-06-18 17:19:32 UTC (rev 31099)
+++ haiku/trunk/src/apps/debugger/ImageInfo.cpp	2009-06-18 17:57:37 UTC (rev 31100)
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2009, Ingo Weinhold, ingo_weinhold at gmx.de.
+ * Distributed under the terms of the MIT License.
+ */
+
+#include "ImageInfo.h"
+
+
+ImageInfo::ImageInfo()
+	:
+	fTeam(-1),
+	fImage(-1),
+	fName()
+{
+}
+
+ImageInfo::ImageInfo(const ImageInfo& other)
+	:
+	fTeam(other.fTeam),
+	fImage(other.fImage),
+	fName(other.fName)
+{
+}
+
+
+ImageInfo::ImageInfo(team_id team, image_id image, const BString& name)
+	:
+	fTeam(team),
+	fImage(image),
+	fName(name)
+{
+}
+
+
+void
+ImageInfo::SetTo(team_id team, image_id image, const BString& name)
+{
+	fTeam = team;
+	fImage = image;
+	fName = name;
+}

Added: haiku/trunk/src/apps/debugger/ImageInfo.h
===================================================================
--- haiku/trunk/src/apps/debugger/ImageInfo.h	2009-06-18 17:19:32 UTC (rev 31099)
+++ haiku/trunk/src/apps/debugger/ImageInfo.h	2009-06-18 17:57:37 UTC (rev 31100)
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2009, Ingo Weinhold, ingo_weinhold at gmx.de.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef IMAGE_INFO_H
+#define IMAGE_INFO_H
+
+#include <image.h>
+#include <String.h>
+
+
+class ImageInfo {
+public:
+								ImageInfo();
+								ImageInfo(const ImageInfo& other);
+								ImageInfo(team_id team, image_id image,
+									const BString& name);
+
+			void				SetTo(team_id team, image_id image,
+									const BString& name);
+
+			team_id				TeamID() const	{ return fTeam; }
+			image_id			ImageID() const	{ return fImage; }
+			const char*			Name() const	{ return fName.String(); }
+
+private:
+			thread_id			fTeam;
+			image_id			fImage;
+			BString				fName;
+};
+
+
+#endif	// IMAGE_INFO_H

Modified: haiku/trunk/src/apps/debugger/Jamfile
===================================================================
--- haiku/trunk/src/apps/debugger/Jamfile	2009-06-18 17:19:32 UTC (rev 31099)
+++ haiku/trunk/src/apps/debugger/Jamfile	2009-06-18 17:57:37 UTC (rev 31100)
@@ -6,6 +6,7 @@
 UsePrivateHeaders debug interface kernel shared ;
 UsePrivateSystemHeaders ;
 
+SEARCH_SOURCE += [ FDirName $(SUBDIR) debugger_interface ] ;
 SEARCH_SOURCE += [ FDirName $(SUBDIR) gui team_window ] ;
 
 local debugAnalyzerSources
@@ -16,14 +17,16 @@
 SubDirHdrs [ FDirName $(debugAnalyzerSources) util ] ;
 
 Application Debugger :
+	CpuState.cpp
 	Debugger.cpp
-	ElfFile.cpp
-
+#	ElfFile.cpp
 	Image.cpp
+	ImageInfo.cpp
 	Team.cpp
 	TeamDebugger.cpp
 	TeamDebugModel.cpp
 	Thread.cpp
+	ThreadInfo.cpp
 
 	# DebugAnalyzer:util
 	Variant.cpp
@@ -33,6 +36,10 @@
 	TeamWindow.cpp
 	ThreadListView.cpp
 
+	# debugger_interface
+	DebugEvent.cpp
+	DebuggerInterface.cpp
+
 # DWARF
 #	attribute_classes.cpp
 #	AttributeValue.cpp

Modified: haiku/trunk/src/apps/debugger/Team.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/Team.cpp	2009-06-18 17:19:32 UTC (rev 31099)
+++ haiku/trunk/src/apps/debugger/Team.cpp	2009-06-18 17:57:37 UTC (rev 31100)
@@ -50,12 +50,13 @@
 	fThreads.Add(thread);
 	_NotifyThreadAdded(thread);
 }
-	
 
+
+
 status_t
-Team::AddThread(const thread_info& threadInfo, Thread** _thread)
+Team::AddThread(const ThreadInfo& threadInfo, Thread** _thread)
 {
-	Thread* thread = new(std::nothrow) Thread(this, threadInfo.thread);
+	Thread* thread = new(std::nothrow) Thread(this, threadInfo.ThreadID());
 	if (thread == NULL)
 		return B_NO_MEMORY;
 
@@ -65,7 +66,7 @@
 		return error;
 	}
 
-	thread->SetName(threadInfo.name);
+	thread->SetName(threadInfo.Name());
 	AddThread(thread);
 
 	if (_thread != NULL)
@@ -75,15 +76,6 @@
 }
 
 
-status_t
-Team::AddThread(thread_id threadID, Thread** _thread)
-{
-	thread_info threadInfo;
-	status_t error = get_thread_info(threadID, &threadInfo);
-	return error == B_OK ? AddThread(threadInfo, _thread) : error;
-}
-
-
 void
 Team::RemoveThread(Thread* thread)
 {
@@ -134,7 +126,7 @@
 
 
 status_t
-Team::AddImage(const image_info& imageInfo, Image** _image)
+Team::AddImage(const ImageInfo& imageInfo, Image** _image)
 {
 	Image* image = new(std::nothrow) Image(this, imageInfo);
 	if (image == NULL)

Modified: haiku/trunk/src/apps/debugger/Team.h
===================================================================
--- haiku/trunk/src/apps/debugger/Team.h	2009-06-18 17:19:32 UTC (rev 31099)
+++ haiku/trunk/src/apps/debugger/Team.h	2009-06-18 17:57:37 UTC (rev 31100)
@@ -8,7 +8,9 @@
 #include <Locker.h>
 
 #include "Image.h"
+#include "ImageInfo.h"
 #include "Thread.h"
+#include "ThreadInfo.h"
 
 
 // team event types
@@ -39,17 +41,15 @@
 			void				SetName(const BString& name);
 
 			void				AddThread(Thread* thread);
-			status_t			AddThread(const thread_info& threadInfo,
+			status_t			AddThread(const ThreadInfo& threadInfo,
 									Thread** _thread = NULL);
-			status_t			AddThread(thread_id threadID,
-									Thread** _thread = NULL);
 			void				RemoveThread(Thread* thread);
 			bool				RemoveThread(thread_id threadID);
 			Thread*				ThreadByID(thread_id threadID) const;
 			const ThreadList&	Threads() const;
 
 			void				AddImage(Image* image);
-			status_t			AddImage(const image_info& imageInfo,
+			status_t			AddImage(const ImageInfo& imageInfo,
 									Image** _image = NULL);
 			void				RemoveImage(Image* image);
 			bool				RemoveImage(image_id imageID);

Modified: haiku/trunk/src/apps/debugger/TeamDebugger.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/TeamDebugger.cpp	2009-06-18 17:19:32 UTC (rev 31099)
+++ haiku/trunk/src/apps/debugger/TeamDebugger.cpp	2009-06-18 17:57:37 UTC (rev 31100)
@@ -15,6 +15,8 @@
 
 #include "debug_utils.h"
 
+#include "CpuState.h"
+#include "DebuggerInterface.h"
 #include "Team.h"
 #include "TeamDebugModel.h"
 
@@ -25,13 +27,11 @@
 	fTeam(NULL),
 	fDebugModel(NULL),
 	fTeamID(-1),
-	fDebuggerPort(-1),
-	fNubPort(-1),
+	fDebuggerInterface(NULL),
 	fDebugEventListener(-1),
 	fTeamWindow(NULL),
 	fTerminating(false)
 {
-	fDebugContext.reply_port = -1;
 }
 
 
@@ -41,18 +41,16 @@
 
 	fTerminating = true;
 
-	if (fDebuggerPort >= 0)
-		delete_port(fDebuggerPort);
+	fDebuggerInterface->Close();
 
 	locker.Unlock();
 
 	if (fDebugEventListener >= 0)
 		wait_for_thread(fDebugEventListener, NULL);
 
-	destroy_debug_context(&fDebugContext);
-
 	delete fDebugModel;
 	delete fTeam;
+	delete fDebuggerInterface;
 }
 
 
@@ -87,54 +85,52 @@
 	if (error != B_OK)
 		return error;
 
-	// create debugger port
-	char buffer[128];
-	snprintf(buffer, sizeof(buffer), "team %ld debugger", fTeamID);
-	fDebuggerPort = create_port(100, buffer);
-	if (fDebuggerPort < 0)
-		return fDebuggerPort;
+	// create debugger interface
+	fDebuggerInterface = new(std::nothrow) DebuggerInterface(fTeamID);
+	if (fDebuggerInterface == NULL)
+		return B_NO_MEMORY;
 
-	// install as team debugger
-	fNubPort = install_team_debugger(fTeamID, fDebuggerPort);
-	if (fNubPort < 0)
-		return fNubPort;
-
-	// init debug context
-	error = init_debug_context(&fDebugContext, fTeamID, fNubPort);
+	error = fDebuggerInterface->Init();
 	if (error != B_OK)
 		return error;
 
 	// set team debugging flags
-	set_team_debugging_flags(fNubPort,
+	fDebuggerInterface->SetTeamDebuggingFlags(
 		B_TEAM_DEBUG_THREADS | B_TEAM_DEBUG_IMAGES);
 
 	// get the initial state of the team
 	AutoLocker< ::Team> teamLocker(fTeam);
 
-	thread_info threadInfo;
-	int32 cookie = 0;
-	while (get_next_thread_info(fTeamID, &cookie, &threadInfo) == B_OK) {
-		::Thread* thread;
-		error = fTeam->AddThread(threadInfo, &thread);
-		if (error != B_OK)
-			return error;
+	{
+		BObjectList<ThreadInfo> threadInfos(20, true);
+		status_t error = fDebuggerInterface->GetThreadInfos(threadInfos);
+		for (int32 i = 0; ThreadInfo* info = threadInfos.ItemAt(i); i++) {
+			::Thread* thread;
+			error = fTeam->AddThread(*info, &thread);
+			if (error != B_OK)
+				return error;
 
-		_UpdateThreadState(thread);
+			_UpdateThreadState(thread);
+		}
 	}
 
-	image_info imageInfo;
-	cookie = 0;
-	while (get_next_image_info(fTeamID, &cookie, &imageInfo) == B_OK) {
-		error = fTeam->AddImage(imageInfo);
-		if (error != B_OK)
-			return error;
+	{
+		BObjectList<ImageInfo> imageInfos(20, true);
+		status_t error = fDebuggerInterface->GetImageInfos(imageInfos);
+		for (int32 i = 0; ImageInfo* info = imageInfos.ItemAt(i); i++) {
+			error = fTeam->AddImage(*info);
+			if (error != B_OK)
+				return error;
+		}
 	}
 
 	// create the debug event listener
+	char buffer[128];
 	snprintf(buffer, sizeof(buffer), "team %ld debug listener", fTeamID);
 	fDebugEventListener = spawn_thread(_DebugEventListenerEntry, buffer,
 		B_NORMAL_PRIORITY, this);
-	if (fDebugEventListener < 0)
+//	if (fDebugEventListener < 0)
+	if (fDebugEventListener < NULL)
 		return fDebugEventListener;
 
 	resume_thread(fDebugEventListener);
@@ -191,31 +187,27 @@
 TeamDebugger::_DebugEventListener()
 {
 	while (!fTerminating) {
-		// read the next message
-		debug_debugger_message_data message;
-		int32 messageCode;
-		ssize_t size = read_port(fDebuggerPort, &messageCode, &message,
-			sizeof(message));
-		if (size < 0) {
-			if (size == B_INTERRUPTED)
-				continue;
-// TODO: Error handling!
+		// get the next event
+		DebugEvent* event;
+		status_t error = fDebuggerInterface->GetNextDebugEvent(event);
+		if (error != B_OK)
 			break;
-		}
+				// TODO: Error handling!
 
-		if (message.origin.team != fTeamID) {
-printf("TeamDebugger for team %ld: received message from team %ld!\n", fTeamID,
-message.origin.team);
+
+		if (event->Team() != fTeamID) {
+printf("TeamDebugger for team %ld: received event from team %ld!\n", fTeamID,
+event->Team());
 			continue;
 		}
 
-		_HandleDebuggerMessage(messageCode, message);
+		_HandleDebuggerMessage(event);
 
-		if (messageCode == B_DEBUGGER_MESSAGE_TEAM_DELETED
-			|| messageCode == B_DEBUGGER_MESSAGE_TEAM_EXEC) {
-			// TODO:...
-			break;
-		}
+//		if (event->EventType() == B_DEBUGGER_MESSAGE_TEAM_DELETED
+//			|| event->EventType() == B_DEBUGGER_MESSAGE_TEAM_EXEC) {
+//			// TODO:...
+//			break;
+//		}
 	}
 
 	return B_OK;
@@ -223,51 +215,54 @@
 
 
 void
-TeamDebugger::_HandleDebuggerMessage(int32 messageCode,
-	const debug_debugger_message_data& message)
+TeamDebugger::_HandleDebuggerMessage(DebugEvent* event)
 {
-printf("TeamDebugger::_HandleDebuggerMessage(): %ld\n", messageCode);
+printf("TeamDebugger::_HandleDebuggerMessage(): %d\n", event->EventType());
 	bool handled = false;
 
-	switch (messageCode) {
+	switch (event->EventType()) {
 		case B_DEBUGGER_MESSAGE_THREAD_DEBUGGED:
-printf("B_DEBUGGER_MESSAGE_THREAD_DEBUGGED: thread: %ld\n", message.origin.thread);
+printf("B_DEBUGGER_MESSAGE_THREAD_DEBUGGED: thread: %ld\n", event->Thread());
 			break;
 		case B_DEBUGGER_MESSAGE_DEBUGGER_CALL:
-printf("B_DEBUGGER_MESSAGE_DEBUGGER_CALL: thread: %ld\n", message.origin.thread);
+printf("B_DEBUGGER_MESSAGE_DEBUGGER_CALL: thread: %ld\n", event->Thread());
 			break;
 		case B_DEBUGGER_MESSAGE_BREAKPOINT_HIT:
-printf("B_DEBUGGER_MESSAGE_BREAKPOINT_HIT: thread: %ld\n", message.origin.thread);
+printf("B_DEBUGGER_MESSAGE_BREAKPOINT_HIT: thread: %ld\n", event->Thread());
 			break;
 		case B_DEBUGGER_MESSAGE_WATCHPOINT_HIT:
-printf("B_DEBUGGER_MESSAGE_WATCHPOINT_HIT: thread: %ld\n", message.origin.thread);
+printf("B_DEBUGGER_MESSAGE_WATCHPOINT_HIT: thread: %ld\n", event->Thread());
 			break;
 		case B_DEBUGGER_MESSAGE_SINGLE_STEP:
-printf("B_DEBUGGER_MESSAGE_SINGLE_STEP: thread: %ld\n", message.origin.thread);
+printf("B_DEBUGGER_MESSAGE_SINGLE_STEP: thread: %ld\n", event->Thread());
 			break;
 		case B_DEBUGGER_MESSAGE_EXCEPTION_OCCURRED:
-printf("B_DEBUGGER_MESSAGE_EXCEPTION_OCCURRED: thread: %ld\n", message.origin.thread);
+printf("B_DEBUGGER_MESSAGE_EXCEPTION_OCCURRED: thread: %ld\n", event->Thread());
 			break;
-		case B_DEBUGGER_MESSAGE_TEAM_CREATED:
-printf("B_DEBUGGER_MESSAGE_TEAM_CREATED: team: %ld\n", message.team_created.new_team);
-			break;
+//		case B_DEBUGGER_MESSAGE_TEAM_CREATED:
+//printf("B_DEBUGGER_MESSAGE_TEAM_CREATED: team: %ld\n", message.team_created.new_team);
+//			break;
 		case B_DEBUGGER_MESSAGE_TEAM_DELETED:
-printf("B_DEBUGGER_MESSAGE_TEAM_DELETED: team: %ld\n", message.origin.team);
+printf("B_DEBUGGER_MESSAGE_TEAM_DELETED: team: %ld\n", event->Team());
 			break;
 		case B_DEBUGGER_MESSAGE_TEAM_EXEC:
-printf("B_DEBUGGER_MESSAGE_TEAM_EXEC: team: %ld\n", message.origin.team);
+printf("B_DEBUGGER_MESSAGE_TEAM_EXEC: team: %ld\n", event->Team());
 			break;
 		case B_DEBUGGER_MESSAGE_THREAD_CREATED:
-			handled = _HandleThreadCreated(message.thread_created);
+			handled = _HandleThreadCreated(
+				dynamic_cast<ThreadCreatedEvent*>(event));
 			break;
 		case B_DEBUGGER_MESSAGE_THREAD_DELETED:
-			handled = _HandleThreadDeleted(message.thread_deleted);
+			handled = _HandleThreadDeleted(
+				dynamic_cast<ThreadDeletedEvent*>(event));
 			break;
 		case B_DEBUGGER_MESSAGE_IMAGE_CREATED:
-			handled = _HandleImageCreated(message.image_created);
+			handled = _HandleImageCreated(
+				dynamic_cast<ImageCreatedEvent*>(event));
 			break;
 		case B_DEBUGGER_MESSAGE_IMAGE_DELETED:
-			handled = _HandleImageDeleted(message.image_deleted);
+			handled = _HandleImageDeleted(
+				dynamic_cast<ImageDeletedEvent*>(event));
 			break;
 		case B_DEBUGGER_MESSAGE_PRE_SYSCALL:
 		case B_DEBUGGER_MESSAGE_POST_SYSCALL:
@@ -277,48 +272,54 @@
 			// not interested
 			break;
 		default:
-			printf("TeamDebugger for team %ld: unknown message from kernel: "
-				"%ld\n", fTeamID, messageCode);
+			printf("TeamDebugger for team %ld: unknown event type: "
+				"%d\n", fTeamID, event->EventType());
 			break;
 	}
 
-	if (!handled && message.origin.thread >= 0 && message.origin.nub_port >= 0)
-		continue_thread(message.origin.nub_port, message.origin.thread);
+	if (!handled && event->ThreadStopped())
+		fDebuggerInterface->ContinueThread(event->Thread());
 }
 
 
 bool
-TeamDebugger::_HandleThreadCreated(const debug_thread_created& message)
+TeamDebugger::_HandleThreadCreated(ThreadCreatedEvent* event)
 {
 	AutoLocker< ::Team> locker(fTeam);
-	fTeam->AddThread(message.new_thread);
+
+	ThreadInfo info;
+	status_t error = fDebuggerInterface->GetThreadInfo(event->NewThread(),
+		info);
+	if (error == B_OK)
+		fTeam->AddThread(info);
+
 	return false;
 }
 
 
 bool
-TeamDebugger::_HandleThreadDeleted(const debug_thread_deleted& message)
+TeamDebugger::_HandleThreadDeleted(ThreadDeletedEvent* event)
 {
 	AutoLocker< ::Team> locker(fTeam);
-	fTeam->RemoveThread(message.origin.thread);
+	fTeam->RemoveThread(event->Thread());
 	return false;
 }
 
 
 bool
-TeamDebugger::_HandleImageCreated(const debug_image_created& message)
+TeamDebugger::_HandleImageCreated(ImageCreatedEvent* event)
 {
 	AutoLocker< ::Team> locker(fTeam);
-	fTeam->AddImage(message.info);
+	fTeam->AddImage(event->GetImageInfo());
 	return false;
 }
 
 
 bool
-TeamDebugger::_HandleImageDeleted(const debug_image_deleted& message)
+TeamDebugger::_HandleImageDeleted(ImageDeletedEvent* event)
 {
 	AutoLocker< ::Team> locker(fTeam);
-	fTeam->RemoveImage(message.info.id);
+	fTeam->RemoveImage(event->GetImageInfo().ImageID());
 	return false;
 }
 
@@ -326,23 +327,15 @@
 void
 TeamDebugger::_UpdateThreadState(::Thread* thread)
 {
-	debug_nub_get_cpu_state message;
-	message.reply_port = fDebugContext.reply_port;
-	message.thread = thread->ID();
+	CpuState* state = NULL;
+	status_t error = fDebuggerInterface->GetCpuState(thread->ID(), state);
 
-	debug_nub_get_cpu_state_reply reply;
-
-	status_t error = send_debug_message(&fDebugContext,
-		B_DEBUG_MESSAGE_GET_CPU_STATE, &message, sizeof(message), &reply,
-		sizeof(reply));
-
 	uint32 newState = THREAD_STATE_UNKNOWN;
 	if (error == B_OK) {
-		if (reply.error == B_OK)
-			newState = THREAD_STATE_STOPPED;
-		else if (reply.error == B_BAD_THREAD_STATE)
-			newState = THREAD_STATE_RUNNING;
-	}
+		newState = THREAD_STATE_STOPPED;
+		state->RemoveReference();
+	} else if (error == B_BAD_THREAD_STATE)
+		newState = THREAD_STATE_RUNNING;
 
 	thread->SetState(newState);
 }

Modified: haiku/trunk/src/apps/debugger/TeamDebugger.h
===================================================================
--- haiku/trunk/src/apps/debugger/TeamDebugger.h	2009-06-18 17:19:32 UTC (rev 31099)
+++ haiku/trunk/src/apps/debugger/TeamDebugger.h	2009-06-18 17:57:37 UTC (rev 31100)
@@ -11,9 +11,11 @@
 #include <debug_support.h>
 #include <util/DoublyLinkedList.h>
 
+#include "DebugEvent.h"
 #include "TeamWindow.h"
 
 
+class DebuggerInterface;
 class Team;
 class TeamDebugModel;
 
@@ -36,17 +38,16 @@
 	static	status_t			_DebugEventListenerEntry(void* data);
 			status_t			_DebugEventListener();
 
-			void				_HandleDebuggerMessage(int32 messageCode,
-									const debug_debugger_message_data& message);
+			void				_HandleDebuggerMessage(DebugEvent* event);
 
 			bool				_HandleThreadCreated(
-									const debug_thread_created& message);
+									ThreadCreatedEvent* event);
 			bool				_HandleThreadDeleted(
-									const debug_thread_deleted& message);
+									ThreadDeletedEvent* event);
 			bool				_HandleImageCreated(
-									const debug_image_created& message);
+									ImageCreatedEvent* event);
 			bool				_HandleImageDeleted(
-									const debug_image_deleted& message);
+									ImageDeletedEvent* event);
 
 			void				_UpdateThreadState(::Thread* thread);
 
@@ -54,9 +55,8 @@
 			::Team*				fTeam;
 			TeamDebugModel*		fDebugModel;
 			team_id				fTeamID;
-			port_id				fDebuggerPort;
 			port_id				fNubPort;
-			debug_context		fDebugContext;
+			DebuggerInterface*	fDebuggerInterface;
 			thread_id			fDebugEventListener;
 			TeamWindow*			fTeamWindow;
 	volatile bool				fTerminating;

Added: haiku/trunk/src/apps/debugger/ThreadInfo.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/ThreadInfo.cpp	2009-06-18 17:19:32 UTC (rev 31099)
+++ haiku/trunk/src/apps/debugger/ThreadInfo.cpp	2009-06-18 17:57:37 UTC (rev 31100)
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2009, Ingo Weinhold, ingo_weinhold at gmx.de.
+ * Distributed under the terms of the MIT License.
+ */
+
+#include "ThreadInfo.h"
+
+
+ThreadInfo::ThreadInfo()
+	:
+	fTeam(-1),
+	fThread(-1),
+	fName()
+{
+}
+
+
+ThreadInfo::ThreadInfo(const ThreadInfo& other)
+	:
+	fTeam(other.fTeam),
+	fThread(other.fThread),
+	fName(other.fName)
+{
+}
+
+
+ThreadInfo::ThreadInfo(team_id team, thread_id thread, const BString& name)
+	:
+	fTeam(team),
+	fThread(thread),
+	fName(name)
+{
+}
+
+
+void
+ThreadInfo::SetTo(team_id team, thread_id thread, const BString& name)
+{
+	fTeam = team;
+	fThread = thread;
+	fName = name;
+}

Added: haiku/trunk/src/apps/debugger/ThreadInfo.h
===================================================================
--- haiku/trunk/src/apps/debugger/ThreadInfo.h	2009-06-18 17:19:32 UTC (rev 31099)
+++ haiku/trunk/src/apps/debugger/ThreadInfo.h	2009-06-18 17:57:37 UTC (rev 31100)
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2009, Ingo Weinhold, ingo_weinhold at gmx.de.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef THREAD_INFO_H
+#define THREAD_INFO_H
+
+#include <OS.h>
+#include <String.h>
+
+
+class ThreadInfo {
+public:
+								ThreadInfo();
+								ThreadInfo(const ThreadInfo& other);
+								ThreadInfo(team_id team, thread_id thread,
+									const BString& name);
+
+			void				SetTo(team_id team, thread_id thread,
+									const BString& name);
+
+			team_id				TeamID() const		{ return fTeam; }
+			thread_id			ThreadID() const	{ return fThread; }
+			const char*			Name() const	{ return fName.String(); }
+
+private:
+			team_id				fTeam;
+			thread_id			fThread;
+			BString				fName;
+};
+
+
+#endif	// THREAD_INFO_H

Added: haiku/trunk/src/apps/debugger/debugger_interface/DebugEvent.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/debugger_interface/DebugEvent.cpp	2009-06-18 17:19:32 UTC (rev 31099)
+++ haiku/trunk/src/apps/debugger/debugger_interface/DebugEvent.cpp	2009-06-18 17:57:37 UTC (rev 31100)
@@ -0,0 +1,201 @@
+/*
+ * Copyright 2009, Ingo Weinhold, ingo_weinhold at gmx.de.
+ * Distributed under the terms of the MIT License.
+ */
+
+#include "DebugEvent.h"
+
+#include "CpuState.h"
+
+
+// #pragma mark - DebugEvent
+
+
+DebugEvent::DebugEvent(debug_debugger_message eventType, team_id team,
+	thread_id thread)
+	:
+	fEventType(eventType),
+	fTeam(team),
+	fThread(thread),
+	fThreadStopped(false)
+{
+}
+
+
+DebugEvent::~DebugEvent()
+{
+}
+
+
+void
+DebugEvent::SetThreadStopped(bool stopped)
+{
+	fThreadStopped = stopped;
+}
+
+
+// #pragma mark - CpuStateEvent
+
+
+CpuStateEvent::CpuStateEvent(debug_debugger_message eventType, team_id team,
+	thread_id thread, CpuState* state)
+	:
+	DebugEvent(eventType, team, thread),
+	fCpuState(state)
+{
+	if (fCpuState != NULL)
+		fCpuState->AddReference();
+}
+
+
+CpuStateEvent::~CpuStateEvent()
+{
+	if (fCpuState != NULL)
+		fCpuState->RemoveReference();
+}
+
+
+// #pragma mark - ThreadDebuggedEvent
+
+
+ThreadDebuggedEvent::ThreadDebuggedEvent(team_id team, thread_id thread)
+	:
+	DebugEvent(B_DEBUGGER_MESSAGE_THREAD_DEBUGGED, team, thread)
+{
+}
+
+
+// #pragma mark - DebuggerCallEvent
+
+
+DebuggerCallEvent::DebuggerCallEvent(team_id team, thread_id thread,
+	target_addr_t message)
+	:
+	DebugEvent(B_DEBUGGER_MESSAGE_DEBUGGER_CALL, team, thread),
+	fMessage(message)
+{
+}
+
+
+// #pragma mark - BreakpointHitEvent
+
+
+BreakpointHitEvent::BreakpointHitEvent(team_id team, thread_id thread,
+	CpuState* state)
+	:
+	CpuStateEvent(B_DEBUGGER_MESSAGE_BREAKPOINT_HIT, team, thread, state)
+{
+}
+
+
+// #pragma mark - WatchpointHitEvent
+
+
+WatchpointHitEvent::WatchpointHitEvent(team_id team, thread_id thread,
+	CpuState* state)
+	:
+	CpuStateEvent(B_DEBUGGER_MESSAGE_WATCHPOINT_HIT, team, thread, state)
+{
+}
+
+
+
+// #pragma mark - SingleStepEvent
+
+
+SingleStepEvent::SingleStepEvent(team_id team, thread_id thread,
+	CpuState* state)
+	:
+	CpuStateEvent(B_DEBUGGER_MESSAGE_SINGLE_STEP, team, thread, state)
+{
+}
+
+
+// #pragma mark - ExceptionOccurredEvent
+
+
+ExceptionOccurredEvent::ExceptionOccurredEvent(team_id team, thread_id thread,
+	uint32 exception)
+	:
+	DebugEvent(B_DEBUGGER_MESSAGE_EXCEPTION_OCCURRED, team, thread),
+	fException(exception)
+{
+}
+
+
+// #pragma mark - TeamDeletedEvent
+
+
+TeamDeletedEvent::TeamDeletedEvent(team_id team, thread_id thread)
+	:
+	DebugEvent(B_DEBUGGER_MESSAGE_TEAM_DELETED, team, thread)
+{
+}
+
+
+// #pragma mark - TeamExecEvent
+
+
+TeamExecEvent::TeamExecEvent(team_id team, thread_id thread)
+	:
+	DebugEvent(B_DEBUGGER_MESSAGE_TEAM_EXEC, team, thread)
+{
+}
+
+
+// #pragma mark - ThreadCreatedEvent
+
+
+ThreadCreatedEvent::ThreadCreatedEvent(team_id team, thread_id thread,
+	thread_id newThread)
+	:
+	DebugEvent(B_DEBUGGER_MESSAGE_THREAD_CREATED, team, thread),
+	fNewThread(newThread)
+{
+}
+
+
+// #pragma mark - ThreadDeletedEvent
+
+
+ThreadDeletedEvent::ThreadDeletedEvent(team_id team, thread_id thread)
+	:
+	DebugEvent(B_DEBUGGER_MESSAGE_THREAD_DELETED, team, thread)
+{
+}
+
+
+// #pragma mark - ImageCreatedEvent
+
+
+ImageCreatedEvent::ImageCreatedEvent(team_id team, thread_id thread,
+	const ImageInfo& info)
+	:
+	DebugEvent(B_DEBUGGER_MESSAGE_IMAGE_CREATED, team, thread),
+	fInfo(info)
+{
+}
+
+
+// #pragma mark - ImageDeletedEvent
+
+
+ImageDeletedEvent::ImageDeletedEvent(team_id team, thread_id thread,
+	const ImageInfo& info)
+	:
+	DebugEvent(B_DEBUGGER_MESSAGE_IMAGE_DELETED, team, thread),
+	fInfo(info)
+{
+}
+
+

[... truncated: 553 lines follow ...]



More information about the Haiku-commits mailing list