[Haiku-commits] r31147 - haiku/trunk/src/apps/debugger/gui/team_window

bonefish at BerliOS bonefish at mail.berlios.de
Sat Jun 20 21:26:48 CEST 2009


Author: bonefish
Date: 2009-06-20 21:26:47 +0200 (Sat, 20 Jun 2009)
New Revision: 31147
ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=31147&view=rev

Modified:
   haiku/trunk/src/apps/debugger/gui/team_window/StackTraceView.cpp
   haiku/trunk/src/apps/debugger/gui/team_window/StackTraceView.h
   haiku/trunk/src/apps/debugger/gui/team_window/TeamWindow.cpp
   haiku/trunk/src/apps/debugger/gui/team_window/TeamWindow.h
   haiku/trunk/src/apps/debugger/gui/team_window/ThreadListView.cpp
   haiku/trunk/src/apps/debugger/gui/team_window/ThreadListView.h
Log:
* If a stack frame is selected show its registers instead those of the top
  frame.
* Some cleanup in ThreadListView.
* Unregister view listeners in the window destructor.


Modified: haiku/trunk/src/apps/debugger/gui/team_window/StackTraceView.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/gui/team_window/StackTraceView.cpp	2009-06-20 18:45:20 UTC (rev 31146)
+++ haiku/trunk/src/apps/debugger/gui/team_window/StackTraceView.cpp	2009-06-20 19:26:47 UTC (rev 31147)
@@ -135,6 +135,11 @@
 		}
 	}
 
+	StackFrame* FrameAt(int32 index) const
+	{
+		return fStackTrace != NULL ? fStackTrace->FrameAt(index) : NULL;
+	}
+
 private:
 	StackTrace*				fStackTrace;
 };
@@ -143,11 +148,12 @@
 // #pragma mark - StackTraceView
 
 
-StackTraceView::StackTraceView()
+StackTraceView::StackTraceView(Listener* listener)
 	:
 	BGroupView(B_VERTICAL),
 	fFramesTable(NULL),
-	fFramesTableModel(NULL)
+	fFramesTableModel(NULL),
+	fListener(listener)
 {
 	SetName("Stack Trace");
 }
@@ -162,9 +168,9 @@
 
 
 /*static*/ StackTraceView*
-StackTraceView::Create()
+StackTraceView::Create(Listener* listener)
 {
-	StackTraceView* self = new StackTraceView();
+	StackTraceView* self = new StackTraceView(listener);
 
 	try {
 		self->_Init();
@@ -178,6 +184,13 @@
 
 
 void
+StackTraceView::UnsetListener()
+{
+	fListener = NULL;
+}
+
+
+void
 StackTraceView::SetStackTrace(StackTrace* stackTrace)
 {
 	if (stackTrace == fStackTrace)
@@ -196,6 +209,19 @@
 
 
 void
+StackTraceView::TableSelectionChanged(Table* table)
+{
+	if (fListener == NULL)
+		return;
+
+	StackFrame* frame
+		= fFramesTableModel->FrameAt(table->SelectionModel()->RowAt(0));
+
+	fListener->StackFrameSelectionChanged(frame);
+}
+
+
+void
 StackTraceView::TableRowInvoked(Table* table, int32 rowIndex)
 {
 }
@@ -213,11 +239,20 @@
 		1000, B_TRUNCATE_END, B_ALIGN_RIGHT));
 	fFramesTable->AddColumn(new TargetAddressValueColumn(1, "IP", 80, 40, 1000,
 		B_TRUNCATE_END, B_ALIGN_RIGHT));
-	fFramesTable->AddColumn(new StringTableColumn(2, "Function", 80, 40, 1000,
+	fFramesTable->AddColumn(new StringTableColumn(2, "Function", 300, 100, 1000,
 		B_TRUNCATE_END, B_ALIGN_LEFT));
 
 	fFramesTableModel = new FramesTableModel();
 	fFramesTable->SetTableModel(fFramesTableModel);
 
+	fFramesTable->SetSelectionMode(B_SINGLE_SELECTION_LIST);
 	fFramesTable->AddTableListener(this);
 }
+
+
+// #pragma mark - Listener
+
+
+StackTraceView::Listener::~Listener()
+{
+}

Modified: haiku/trunk/src/apps/debugger/gui/team_window/StackTraceView.h
===================================================================
--- haiku/trunk/src/apps/debugger/gui/team_window/StackTraceView.h	2009-06-20 18:45:20 UTC (rev 31146)
+++ haiku/trunk/src/apps/debugger/gui/team_window/StackTraceView.h	2009-06-20 19:26:47 UTC (rev 31147)
@@ -11,14 +11,22 @@
 #include "Team.h"
 
 
+class StackFrame;
+
+
 class StackTraceView : public BGroupView, private TableListener {
 public:
-								StackTraceView();
+	class Listener;
+
+public:
+								StackTraceView(Listener* listener);
 								~StackTraceView();
 
-	static	StackTraceView*		Create();
+	static	StackTraceView*		Create(Listener* listener);
 									// throws
 
+			void				UnsetListener();
+
 			void				SetStackTrace(StackTrace* stackTrace);
 
 private:
@@ -26,6 +34,7 @@
 
 private:
 	// TableListener
+	virtual	void				TableSelectionChanged(Table* table);
 	virtual	void				TableRowInvoked(Table* table, int32 rowIndex);
 
 			void				_Init();
@@ -34,7 +43,17 @@
 			StackTrace*			fStackTrace;
 			Table*				fFramesTable;
 			FramesTableModel*	fFramesTableModel;
+			Listener*			fListener;
 };
 
 
+class StackTraceView::Listener {
+public:
+	virtual						~Listener();
+
+	virtual	void				StackFrameSelectionChanged(
+									StackFrame* frame) = 0;
+};
+
+
 #endif	// STACK_TRACE_VIEW_H

Modified: haiku/trunk/src/apps/debugger/gui/team_window/TeamWindow.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/gui/team_window/TeamWindow.cpp	2009-06-20 18:45:20 UTC (rev 31146)
+++ haiku/trunk/src/apps/debugger/gui/team_window/TeamWindow.cpp	2009-06-20 19:26:47 UTC (rev 31147)
@@ -34,6 +34,7 @@
 		B_ASYNCHRONOUS_CONTROLS),
 	fDebugModel(debugModel),
 	fActiveThread(NULL),
+	fActiveStackFrame(NULL),
 	fListener(listener),
 	fTabView(NULL),
 	fLocalsTabView(NULL),
@@ -58,6 +59,11 @@
 
 TeamWindow::~TeamWindow()
 {
+	if (fThreadListView != NULL)
+		fThreadListView->UnsetListener();
+	if (fStackTraceView != NULL)
+		fStackTraceView->UnsetListener();
+
 	fDebugModel->GetTeam()->RemoveListener(this);
 }
 
@@ -144,6 +150,13 @@
 
 
 void
+TeamWindow::StackFrameSelectionChanged(StackFrame* frame)
+{
+	_SetActiveStackFrame(frame);
+}
+
+
+void
 TeamWindow::ThreadStateChanged(const Team::ThreadEvent& event)
 {
 	BMessage message(MSG_THREAD_STATE_CHANGED);
@@ -197,7 +210,7 @@
 	fTabView->AddTab(threadGroup);
 	BLayoutBuilder::Split<>(threadGroup)
 		.Add(fThreadListView = ThreadListView::Create(this))
-		.Add(fStackTraceView = StackTraceView::Create());
+		.Add(fStackTraceView = StackTraceView::Create(this));
 
 	// add images tab
 	BSplitView* imagesGroup = new BSplitView(B_HORIZONTAL);
@@ -243,11 +256,6 @@
 	AutoLocker<TeamDebugModel> locker(fDebugModel);
 	_UpdateRunButtons();
 
-	CpuState* cpuState = fActiveThread != NULL
-		? fActiveThread->GetCpuState() : NULL;
-	Reference<CpuState> cpuStateReference(cpuState);
-		// hold a reference until the register view has one
-
 	StackTrace* stackTrace = fActiveThread != NULL
 		? fActiveThread->GetStackTrace() : NULL;
 	Reference<StackTrace> stackTraceReference(stackTrace);
@@ -255,12 +263,53 @@
 
 	locker.Unlock();
 
-	fRegisterView->SetCpuState(cpuState);
 	fStackTraceView->SetStackTrace(stackTrace);
+	_UpdateCpuState();
 }
 
 
 void
+TeamWindow::_SetActiveStackFrame(StackFrame* frame)
+{
+	if (frame == fActiveStackFrame)
+		return;
+
+	if (fActiveStackFrame != NULL)
+		fActiveStackFrame->RemoveReference();
+
+	fActiveStackFrame = frame;
+
+	if (fActiveStackFrame != NULL)
+		fActiveStackFrame->AddReference();
+
+	_UpdateCpuState();
+}
+
+
+void
+TeamWindow::_UpdateCpuState()
+{
+	// get the CPU state
+	CpuState* cpuState = NULL;
+	Reference<CpuState> cpuStateReference;
+		// hold a reference until the register view has one
+
+	if (fActiveThread != NULL) {
+		// Get the CPU state from the active stack frame or the thread directly.
+		if (fActiveStackFrame == NULL) {
+			AutoLocker<TeamDebugModel> locker(fDebugModel);
+			cpuState = fActiveThread->GetCpuState();
+			cpuStateReference.SetTo(cpuState);
+			locker.Unlock();
+		} else
+			cpuState = fActiveStackFrame->GetCpuState();
+	}
+
+	fRegisterView->SetCpuState(cpuState);
+}
+
+
+void
 TeamWindow::_UpdateRunButtons()
 {
 	uint32 threadState = fActiveThread != NULL
@@ -312,16 +361,7 @@
 	if (fActiveThread == NULL || threadID != fActiveThread->ID())
 		return;
 
-	AutoLocker<TeamDebugModel> locker(fDebugModel);
-
-	CpuState* cpuState = fActiveThread != NULL
-		? fActiveThread->GetCpuState() : NULL;
-	Reference<CpuState> reference(cpuState);
-		// hold a reference until the register view has one
-
-	locker.Unlock();
-
-	fRegisterView->SetCpuState(cpuState);
+	_UpdateCpuState();
 }
 
 

Modified: haiku/trunk/src/apps/debugger/gui/team_window/TeamWindow.h
===================================================================
--- haiku/trunk/src/apps/debugger/gui/team_window/TeamWindow.h	2009-06-20 18:45:20 UTC (rev 31146)
+++ haiku/trunk/src/apps/debugger/gui/team_window/TeamWindow.h	2009-06-20 19:26:47 UTC (rev 31147)
@@ -8,6 +8,7 @@
 #include <String.h>
 #include <Window.h>
 
+#include "StackTraceView.h"
 #include "Team.h"
 #include "ThreadListView.h"
 
@@ -16,12 +17,11 @@
 class BTabView;
 class ImageListView;
 class RegisterView;
-class StackTraceView;
 class TeamDebugModel;
 
 
 class TeamWindow : public BWindow, private ThreadListView::Listener,
-	Team::Listener {
+	StackTraceView::Listener, Team::Listener {
 public:
 	class Listener;
 
@@ -41,6 +41,9 @@
 	// ThreadListView::Listener
 	virtual	void				ThreadSelectionChanged(::Thread* thread);
 
+	// StackTraceView::Listener
+	virtual	void				StackFrameSelectionChanged(StackFrame* frame);
+
 	// Team::Listener
 	virtual	void				ThreadStateChanged(
 									const Team::ThreadEvent& event);
@@ -52,6 +55,8 @@
 			void				_Init();
 
 			void				_SetActiveThread(::Thread* thread);
+			void				_SetActiveStackFrame(StackFrame* frame);
+			void				_UpdateCpuState();
 			void				_UpdateRunButtons();
 
 			void				_HandleThreadStateChanged(thread_id threadID);
@@ -61,6 +66,7 @@
 private:
 			TeamDebugModel*		fDebugModel;
 			::Thread*			fActiveThread;
+			StackFrame*			fActiveStackFrame;
 			Listener*			fListener;
 			BTabView*			fTabView;
 			BTabView*			fLocalsTabView;

Modified: haiku/trunk/src/apps/debugger/gui/team_window/ThreadListView.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/gui/team_window/ThreadListView.cpp	2009-06-20 18:45:20 UTC (rev 31146)
+++ haiku/trunk/src/apps/debugger/gui/team_window/ThreadListView.cpp	2009-06-20 19:26:47 UTC (rev 31147)
@@ -166,6 +166,13 @@
 
 
 void
+ThreadListView::UnsetListener()
+{
+	fListener = NULL;
+}
+
+
+void
 ThreadListView::SetTeam(Team* team)
 {
 	if (team == fTeam)
@@ -222,6 +229,9 @@
 void
 ThreadListView::TableSelectionChanged(Table* table)
 {
+	if (fListener == NULL)
+		return;
+
 	Thread* thread = NULL;
 	if (fThreadsTableModel != NULL) {
 		TableSelectionModel* selectionModel = table->SelectionModel();
@@ -233,17 +243,6 @@
 
 
 void
-ThreadListView::TableRowInvoked(Table* table, int32 rowIndex)
-{
-//	if (fThreadsTableModel != NULL) {
-//		Thread* thread = fThreadsTableModel->ThreadAt(rowIndex);
-//		if (thread != NULL)
-//			fParent->OpenThreadWindow(thread);
-//	}
-}
-
-
-void
 ThreadListView::_Init()
 {
 	fThreadsTable = new Table("threads list", 0);

Modified: haiku/trunk/src/apps/debugger/gui/team_window/ThreadListView.h
===================================================================
--- haiku/trunk/src/apps/debugger/gui/team_window/ThreadListView.h	2009-06-20 18:45:20 UTC (rev 31146)
+++ haiku/trunk/src/apps/debugger/gui/team_window/ThreadListView.h	2009-06-20 19:26:47 UTC (rev 31147)
@@ -26,6 +26,8 @@
 	static	ThreadListView*		Create(Listener* listener);
 									// throws
 
+			void				UnsetListener();
+
 			void				SetTeam(Team* team);
 
 	virtual	void				MessageReceived(BMessage* message);
@@ -40,7 +42,6 @@
 
 	// TableListener
 	virtual	void				TableSelectionChanged(Table* table);
-	virtual	void				TableRowInvoked(Table* table, int32 rowIndex);
 
 			void				_Init();
 




More information about the Haiku-commits mailing list