From 880a646413bb06b0c1a55f1ac2cf38c1b17d937b Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Wed, 18 May 2016 22:16:58 -0400 Subject: [PATCH] Debugger: Cleanup. TargetHostInterface: - Adjust _StartTeamDebugger to always require a user interface object to be passed in rather than implicitly falling back to GUI if unspecified. Debugger: - Refactor to be in compliance with the above. --- src/apps/debugger/Debugger.cpp | 28 ++++++++++++++++--- .../TargetHostInterface.cpp | 13 ++------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/apps/debugger/Debugger.cpp b/src/apps/debugger/Debugger.cpp index 0570f37fe7..eb4f484d04 100644 --- a/src/apps/debugger/Debugger.cpp +++ b/src/apps/debugger/Debugger.cpp @@ -418,10 +418,17 @@ Debugger::MessageReceived(BMessage* message) options.requestType = TEAM_DEBUGGER_REQUEST_ATTACH; options.settingsManager = &fSettingsManager; options.team = teamID; + options.userInterface = new(std::nothrow) GraphicalUserInterface; + if (options.userInterface == NULL) { + // TODO: notify user. + break; + } + BReference uiReference(options.userInterface, true); status_t error = interface->StartTeamDebugger(options); if (error != B_OK) { // TODO: notify user. - } + } else + uiReference.Detach(); break; } case MSG_START_NEW_TEAM: @@ -576,6 +583,10 @@ Debugger::_StartNewTeam(TargetHostInterface* interface, const char* path, TeamDebuggerOptions options; options.requestType = TEAM_DEBUGGER_REQUEST_CREATE; options.settingsManager = &fSettingsManager; + options.userInterface = new(std::nothrow) GraphicalUserInterface; + if (options.userInterface == NULL) + return B_NO_MEMORY; + BReference uiReference(options.userInterface, true); options.commandLineArgc = argVector.ArgumentCount(); if (options.commandLineArgc <= 0) return B_BAD_VALUE; @@ -586,8 +597,10 @@ Debugger::_StartNewTeam(TargetHostInterface* interface, const char* path, MemoryDeleter deleter(argv); status_t error = interface->StartTeamDebugger(options); - if (error == B_OK) + if (error == B_OK) { deleter.Detach(); + uiReference.Detach(); + } return error; } @@ -599,10 +612,17 @@ Debugger::_HandleOptions(const Options& options) TeamDebuggerOptions debuggerOptions; set_debugger_options_from_options(debuggerOptions, options); debuggerOptions.settingsManager = &fSettingsManager; - + debuggerOptions.userInterface = new(std::nothrow) GraphicalUserInterface; + if (debuggerOptions.userInterface == NULL) + return B_NO_MEMORY; + BReference uiReference(debuggerOptions.userInterface, true); TargetHostInterface* hostInterface = TargetHostInterfaceRoster::Default()->ActiveInterfaceAt(0); - return hostInterface->StartTeamDebugger(debuggerOptions); + status_t error = hostInterface->StartTeamDebugger(debuggerOptions); + if (error == B_OK) + uiReference.Detach(); + + return error; } diff --git a/src/apps/debugger/target_host_interface/TargetHostInterface.cpp b/src/apps/debugger/target_host_interface/TargetHostInterface.cpp index a910025aa9..d4034f3a9f 100644 --- a/src/apps/debugger/target_host_interface/TargetHostInterface.cpp +++ b/src/apps/debugger/target_host_interface/TargetHostInterface.cpp @@ -10,7 +10,6 @@ #include #include "DebuggerInterface.h" -#include "GraphicalUserInterface.h" #include "MessageCodes.h" #include "TeamDebugger.h" @@ -238,16 +237,11 @@ status_t TargetHostInterface::_StartTeamDebugger(team_id teamID, const TeamDebuggerOptions& options, bool stopInMain) { - BReference userInterfaceReference; UserInterface* userInterface = options.userInterface; if (userInterface == NULL) { - userInterface = new(std::nothrow) GraphicalUserInterface; - if (userInterface == NULL) { - fprintf(stderr, "Error: Out of memory!\n"); - return B_NO_MEMORY; - } - - userInterfaceReference.SetTo(userInterface, true); + fprintf(stderr, "Error: Requested team debugger start without " + "valid user interface!\n"); + return B_BAD_VALUE; } thread_id threadID = options.thread; @@ -273,7 +267,6 @@ TargetHostInterface::_StartTeamDebugger(team_id teamID, } } - BReference debuggerInterfaceReference(interface, true); debugger = new(std::nothrow) TeamDebugger(this, userInterface,