Add message for starting a new team. Implements #9682.

- The Debugger app now accepts a message asking it to start a new team.
  It attempts to do so given the path and arguments, and passes the
  result back to the sender if desired.
This commit is contained in:
Rene Gollent 2013-05-03 20:16:08 -04:00
parent 9b57eae7e6
commit aad822734d
1 changed files with 77 additions and 16 deletions

View File

@ -1,6 +1,6 @@
/* /*
* Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2011, Rene Gollent, rene@gollent.com. * Copyright 2011-2013, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@ -15,6 +15,8 @@
#include <Application.h> #include <Application.h>
#include <Message.h> #include <Message.h>
#include <ArgumentVector.h>
#include <AutoDeleter.h>
#include <AutoLocker.h> #include <AutoLocker.h>
#include <ObjectList.h> #include <ObjectList.h>
@ -279,7 +281,8 @@ get_debugged_program(const Options& options, DebuggedProgramInfo& _info)
static TeamDebugger* static TeamDebugger*
start_team_debugger(team_id teamID, SettingsManager* settingsManager, start_team_debugger(team_id teamID, SettingsManager* settingsManager,
TeamDebugger::Listener* listener, thread_id threadID = -1, TeamDebugger::Listener* listener, thread_id threadID = -1,
bool stopInMain = false, UserInterface* userInterface = NULL) bool stopInMain = false, UserInterface* userInterface = NULL,
status_t* _result = NULL)
{ {
if (teamID < 0) if (teamID < 0)
return NULL; return NULL;
@ -307,11 +310,13 @@ start_team_debugger(team_id teamID, SettingsManager* settingsManager,
printf("Error: debugger for team %" B_PRId32 " failed to init: %s!\n", printf("Error: debugger for team %" B_PRId32 " failed to init: %s!\n",
teamID, strerror(error)); teamID, strerror(error));
delete debugger; delete debugger;
return NULL; debugger = NULL;
} else } else
printf("debugger for team %" B_PRId32 " created and initialized " printf("debugger for team %" B_PRId32 " created and initialized "
"successfully!\n", teamID); "successfully!\n", teamID);
if (_result != NULL)
*_result = error;
return debugger; return debugger;
} }
@ -342,6 +347,9 @@ private:
TeamDebugger* _FindTeamDebugger(team_id teamID) const; TeamDebugger* _FindTeamDebugger(team_id teamID) const;
status_t _StartNewTeam(const char* path, const char* args);
status_t _StartOrFindTeam(Options& options);
private: private:
SettingsManager fSettingsManager; SettingsManager fSettingsManager;
TeamDebuggerList fTeamDebuggers; TeamDebuggerList fTeamDebuggers;
@ -433,6 +441,20 @@ Debugger::MessageReceived(BMessage* message)
start_team_debugger(teamID, &fSettingsManager, this); start_team_debugger(teamID, &fSettingsManager, this);
break; break;
} }
case MSG_START_NEW_TEAM:
{
const char* teamPath = NULL;
const char* args = NULL;
message->FindString("path", &teamPath);
message->FindString("arguments", &args);
status_t result = _StartNewTeam(teamPath, args);
BMessage reply;
reply.AddInt32("status", result);
message->SendReply(&reply);
break;
}
case MSG_TEAM_DEBUGGER_QUIT: case MSG_TEAM_DEBUGGER_QUIT:
{ {
int32 threadID; int32 threadID;
@ -467,20 +489,8 @@ Debugger::ArgvReceived(int32 argc, char** argv)
return; return;
} }
DebuggedProgramInfo programInfo; _StartOrFindTeam(options);
if (!get_debugged_program(options, programInfo))
return;
TeamDebugger* debugger = _FindTeamDebugger(programInfo.team);
if (debugger != NULL) {
printf("There's already a debugger for team: %" B_PRId32 "\n",
programInfo.team);
debugger->Activate();
return;
}
start_team_debugger(programInfo.team, &fSettingsManager, this,
programInfo.thread, programInfo.stopInMain);
} }
@ -557,6 +567,57 @@ Debugger::_FindTeamDebugger(team_id teamID) const
} }
status_t
Debugger::_StartNewTeam(const char* path, const char* args)
{
if (path == NULL)
return B_BAD_VALUE;
BString data;
data.SetToFormat("%s %s", path, args);
if (data.Length() == 0)
return B_NO_MEMORY;
ArgumentVector argVector;
argVector.Parse(data.String());
Options options;
options.commandLineArgc = argVector.ArgumentCount();
if (options.commandLineArgc <= 0)
return B_BAD_VALUE;
char** argv = argVector.DetachArguments();
options.commandLineArgv = argv;
MemoryDeleter deleter(argv);
return _StartOrFindTeam(options);
}
status_t
Debugger::_StartOrFindTeam(Options& options)
{
DebuggedProgramInfo programInfo;
if (!get_debugged_program(options, programInfo))
return B_BAD_VALUE;
TeamDebugger* debugger = _FindTeamDebugger(programInfo.team);
if (debugger != NULL) {
printf("There's already a debugger for team: %" B_PRId32 "\n",
programInfo.team);
debugger->Activate();
return B_OK;
}
status_t result;
start_team_debugger(programInfo.team, &fSettingsManager, this,
programInfo.thread, programInfo.stopInMain, NULL, &result);
return result;
}
// #pragma mark - CliDebugger // #pragma mark - CliDebugger