Debugger: Create UiUtils helper class

Currently only a method to get a description for a thread state lives
there (code pulled from ThreadListView).
This commit is contained in:
Ingo Weinhold 2012-07-23 23:50:18 +02:00
parent a6de32b06c
commit 533a73766d
4 changed files with 65 additions and 29 deletions

View File

@ -30,6 +30,7 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) user_interface gui team_window ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) user_interface gui teams_window ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) user_interface gui teams_window ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) user_interface gui util ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) user_interface gui util ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) user_interface gui value ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) user_interface gui value ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) user_interface util ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) util ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) util ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) value ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) value ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) value type_handlers ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) value type_handlers ] ;
@ -221,6 +222,9 @@ Application Debugger :
TableCellValueRenderer.cpp TableCellValueRenderer.cpp
TableCellValueRendererUtils.cpp TableCellValueRendererUtils.cpp
# user_interface/util
UiUtils.cpp
# util # util
ArchivingUtils.cpp ArchivingUtils.cpp
BitBuffer.cpp BitBuffer.cpp

View File

@ -18,6 +18,7 @@
#include "GUISettingsUtils.h" #include "GUISettingsUtils.h"
#include "table/TableColumns.h" #include "table/TableColumns.h"
#include "UiUtils.h"
enum { enum {
@ -114,35 +115,10 @@ public:
return true; return true;
case 1: case 1:
{ {
switch (thread->State()) { const char* string = UiUtils::ThreadStateToString(
case THREAD_STATE_RUNNING: thread->State(), thread->StoppedReason());
value.SetTo("Running", B_VARIANT_DONT_COPY_DATA); value.SetTo(string, B_VARIANT_DONT_COPY_DATA);
return true; return true;
case THREAD_STATE_STOPPED:
break;
case THREAD_STATE_UNKNOWN:
default:
value.SetTo("?", B_VARIANT_DONT_COPY_DATA);
return true;
}
// thread is stopped -- get the reason
switch (thread->StoppedReason()) {
case THREAD_STOPPED_DEBUGGER_CALL:
value.SetTo("Call", B_VARIANT_DONT_COPY_DATA);
return true;
case THREAD_STOPPED_EXCEPTION:
value.SetTo("Exception", B_VARIANT_DONT_COPY_DATA);
return true;
case THREAD_STOPPED_BREAKPOINT:
case THREAD_STOPPED_WATCHPOINT:
case THREAD_STOPPED_SINGLE_STEP:
case THREAD_STOPPED_DEBUGGED:
case THREAD_STOPPED_UNKNOWN:
default:
value.SetTo("Debugged", B_VARIANT_DONT_COPY_DATA);
return true;
}
} }
case 2: case 2:
value.SetTo(thread->Name(), B_VARIANT_DONT_COPY_DATA); value.SetTo(thread->Name(), B_VARIANT_DONT_COPY_DATA);

View File

@ -0,0 +1,37 @@
/*
* Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include "UiUtils.h"
/*static*/ const char*
UiUtils::ThreadStateToString(int state, int stoppedReason)
{
switch (state) {
case THREAD_STATE_RUNNING:
return "Running";
case THREAD_STATE_STOPPED:
break;
case THREAD_STATE_UNKNOWN:
default:
return "?";
}
// thread is stopped -- get the reason
switch (stoppedReason) {
case THREAD_STOPPED_DEBUGGER_CALL:
return "Call";
case THREAD_STOPPED_EXCEPTION:
return "Exception";
case THREAD_STOPPED_BREAKPOINT:
case THREAD_STOPPED_WATCHPOINT:
case THREAD_STOPPED_SINGLE_STEP:
case THREAD_STOPPED_DEBUGGED:
case THREAD_STOPPED_UNKNOWN:
default:
return "Debugged";
}
}

View File

@ -0,0 +1,19 @@
/*
* Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef UI_UTILS_H
#define UI_UTILS_H
#include "Thread.h"
class UiUtils {
public:
static const char* ThreadStateToString(int state,
int stoppedReason);
};
#endif // UI_UTILS_H