diff --git a/src/apps/debugger/Debugger.cpp b/src/apps/debugger/Debugger.cpp index 295b0542c8..9b2db4333a 100644 --- a/src/apps/debugger/Debugger.cpp +++ b/src/apps/debugger/Debugger.cpp @@ -1,6 +1,6 @@ /* * 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. */ @@ -15,6 +15,8 @@ #include #include +#include +#include #include #include @@ -279,7 +281,8 @@ get_debugged_program(const Options& options, DebuggedProgramInfo& _info) static TeamDebugger* start_team_debugger(team_id teamID, SettingsManager* settingsManager, 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) 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", teamID, strerror(error)); delete debugger; - return NULL; + debugger = NULL; } else printf("debugger for team %" B_PRId32 " created and initialized " "successfully!\n", teamID); + if (_result != NULL) + *_result = error; return debugger; } @@ -342,6 +347,9 @@ private: TeamDebugger* _FindTeamDebugger(team_id teamID) const; + status_t _StartNewTeam(const char* path, const char* args); + status_t _StartOrFindTeam(Options& options); + private: SettingsManager fSettingsManager; TeamDebuggerList fTeamDebuggers; @@ -433,6 +441,20 @@ Debugger::MessageReceived(BMessage* message) start_team_debugger(teamID, &fSettingsManager, this); 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: { int32 threadID; @@ -467,20 +489,8 @@ Debugger::ArgvReceived(int32 argc, char** argv) return; } - DebuggedProgramInfo programInfo; - if (!get_debugged_program(options, programInfo)) - return; + _StartOrFindTeam(options); - 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