Factor out _StartTeamDebugger() so it can be shared between the GUI and
CLI initialization. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43160 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
|
* Copyright 2011, Rene Gollent, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@
|
|||||||
|
|
||||||
#include "debug_utils.h"
|
#include "debug_utils.h"
|
||||||
|
|
||||||
|
#include "CommandLineUserInterface.h"
|
||||||
#include "GraphicalUserInterface.h"
|
#include "GraphicalUserInterface.h"
|
||||||
#include "MessageCodes.h"
|
#include "MessageCodes.h"
|
||||||
#include "SettingsManager.h"
|
#include "SettingsManager.h"
|
||||||
@@ -173,6 +175,44 @@ parse_arguments(int argc, const char* const* argv, bool noOutput,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static TeamDebugger*
|
||||||
|
start_team_debugger(team_id teamID, SettingsManager* settingsManager,
|
||||||
|
TeamDebugger::Listener* listener, thread_id threadID = -1,
|
||||||
|
bool stopInMain = false, bool useCLI = false)
|
||||||
|
{
|
||||||
|
if (teamID < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
UserInterface* userInterface = useCLI
|
||||||
|
? (UserInterface*)new(std::nothrow) CommandLineUserInterface
|
||||||
|
: (UserInterface*)new(std::nothrow) GraphicalUserInterface;
|
||||||
|
|
||||||
|
if (userInterface == NULL) {
|
||||||
|
// TODO: Notify the user!
|
||||||
|
fprintf(stderr, "Error: Out of memory!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
BReference<UserInterface> userInterfaceReference(userInterface, true);
|
||||||
|
|
||||||
|
status_t error = B_NO_MEMORY;
|
||||||
|
|
||||||
|
TeamDebugger* debugger = new(std::nothrow) TeamDebugger(listener,
|
||||||
|
userInterface, settingsManager);
|
||||||
|
if (debugger)
|
||||||
|
error = debugger->Init(teamID, threadID, stopInMain);
|
||||||
|
|
||||||
|
if (error != B_OK) {
|
||||||
|
printf("Error: debugger for team %ld failed to init: %s!\n",
|
||||||
|
teamID, strerror(error));
|
||||||
|
delete debugger;
|
||||||
|
return NULL;
|
||||||
|
} else
|
||||||
|
printf("debugger for team %ld created and initialized successfully!\n",
|
||||||
|
teamID);
|
||||||
|
|
||||||
|
return debugger;
|
||||||
|
}
|
||||||
|
|
||||||
// #pragma mark - Debugger application class
|
// #pragma mark - Debugger application class
|
||||||
|
|
||||||
|
|
||||||
@@ -198,9 +238,7 @@ private:
|
|||||||
virtual void Quit();
|
virtual void Quit();
|
||||||
|
|
||||||
TeamDebugger* _FindTeamDebugger(team_id teamID) const;
|
TeamDebugger* _FindTeamDebugger(team_id teamID) const;
|
||||||
TeamDebugger* _StartTeamDebugger(team_id teamID,
|
|
||||||
thread_id threadID = -1,
|
|
||||||
bool stopInMain = false);
|
|
||||||
private:
|
private:
|
||||||
SettingsManager fSettingsManager;
|
SettingsManager fSettingsManager;
|
||||||
TeamDebuggerList fTeamDebuggers;
|
TeamDebuggerList fTeamDebuggers;
|
||||||
@@ -273,7 +311,7 @@ Debugger::MessageReceived(BMessage* message)
|
|||||||
if (message->FindInt32("team", &teamID) != B_OK)
|
if (message->FindInt32("team", &teamID) != B_OK)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
_StartTeamDebugger(teamID);
|
start_team_debugger(teamID, &fSettingsManager, this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_TEAM_DEBUGGER_QUIT:
|
case MSG_TEAM_DEBUGGER_QUIT:
|
||||||
@@ -359,7 +397,7 @@ Debugger::ArgvReceived(int32 argc, char** argv)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_StartTeamDebugger(team, thread, stopInMain);
|
start_team_debugger(team, &fSettingsManager, this, thread, stopInMain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -441,62 +479,34 @@ Debugger::_FindTeamDebugger(team_id teamID) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TeamDebugger*
|
|
||||||
Debugger::_StartTeamDebugger(team_id teamID, thread_id threadID,
|
|
||||||
bool stopInMain)
|
|
||||||
{
|
|
||||||
if (teamID < 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
UserInterface* userInterface = new(std::nothrow) GraphicalUserInterface;
|
|
||||||
if (userInterface == NULL) {
|
|
||||||
// TODO: Notify the user!
|
|
||||||
fprintf(stderr, "Error: Out of memory!\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
BReference<UserInterface> userInterfaceReference(userInterface, true);
|
|
||||||
|
|
||||||
status_t error = B_NO_MEMORY;
|
|
||||||
|
|
||||||
TeamDebugger* debugger = new(std::nothrow) TeamDebugger(this, userInterface,
|
|
||||||
&fSettingsManager);
|
|
||||||
if (debugger)
|
|
||||||
error = debugger->Init(teamID, threadID, stopInMain);
|
|
||||||
|
|
||||||
if (error != B_OK) {
|
|
||||||
printf("Error: debugger for team %ld failed to init: %s!\n",
|
|
||||||
teamID, strerror(error));
|
|
||||||
delete debugger;
|
|
||||||
return NULL;
|
|
||||||
} else
|
|
||||||
printf("debugger for team %ld created and initialized successfully!\n",
|
|
||||||
teamID);
|
|
||||||
|
|
||||||
return debugger;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char* const* argv)
|
main(int argc, const char* const* argv)
|
||||||
{
|
{
|
||||||
// We test-parse the arguments here, so, when we're started from the
|
// We test-parse the arguments here, so that, when we're started from the
|
||||||
// terminal and there's an instance already running, we can print an error
|
// terminal and there's an instance already running, we can print an error
|
||||||
// message to the terminal, if something's wrong with the arguments.
|
// message to the terminal, if something's wrong with the arguments.
|
||||||
{
|
// Otherwise, the arguments are reparsed in the actual application,
|
||||||
Options options;
|
// unless the option to use the command line interface was chosen.
|
||||||
parse_arguments(argc, argv, false, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
Debugger app;
|
Options options;
|
||||||
status_t error = app.Init();
|
parse_arguments(argc, argv, false, options);
|
||||||
if (error != B_OK) {
|
|
||||||
fprintf(stderr, "Error: Failed to init application: %s\n",
|
if (options.useCLI) {
|
||||||
strerror(error));
|
// TODO: implement
|
||||||
|
fprintf(stderr, "Error: Command line interface unimplemented\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
} else {
|
||||||
|
Debugger app;
|
||||||
|
status_t error = app.Init();
|
||||||
|
if (error != B_OK) {
|
||||||
|
fprintf(stderr, "Error: Failed to init application: %s\n",
|
||||||
|
strerror(error));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user