Skip to content

Commit

Permalink
Debugger: Minor refactor.
Browse files Browse the repository at this point in the history
TeamDebugger:
- Rather than instantiating the DebuggerInterface directly, we now
  expect it to be given to us externally. This allows TeamDebugger
  to be agnostic of where the team actually resides.

Debugger:
- Create and initialize DebuggerInterface before passing it on to
  TeamDebugger.

No functional change.
  • Loading branch information
anevilyak committed Apr 2, 2016
1 parent 5632ede commit 6bef41c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
17 changes: 14 additions & 3 deletions src/apps/debugger/Debugger.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2011-2015, Rene Gollent, rene@gollent.com.
* Copyright 2011-2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/

Expand All @@ -23,6 +23,7 @@
#include "debug_utils.h"

#include "CommandLineUserInterface.h"
#include "DebuggerInterface.h"
#include "GraphicalUserInterface.h"
#include "ImageDebugLoadingStateHandlerRoster.h"
#include "MessageCodes.h"
Expand Down Expand Up @@ -310,12 +311,22 @@ start_team_debugger(team_id teamID, SettingsManager* settingsManager,
userInterfaceReference.SetTo(userInterface, true);
}

BReference<DebuggerInterface> interfaceReference;
DebuggerInterface* debuggerInterface
= new(std::nothrow) DebuggerInterface(teamID);
if (debuggerInterface == NULL)
return NULL;
interfaceReference.SetTo(debuggerInterface, true);

if (debuggerInterface->Init() != B_OK)
return NULL;

status_t error = B_NO_MEMORY;

TeamDebugger* debugger = new(std::nothrow) TeamDebugger(listener,
userInterface, settingsManager);
if (debugger) {
error = debugger->Init(teamID, threadID, commandLineArgc,
if (debugger != NULL) {
error = debugger->Init(debuggerInterface, threadID, commandLineArgc,
commandLineArgv, stopInMain);
}

Expand Down
16 changes: 5 additions & 11 deletions src/apps/debugger/controllers/TeamDebugger.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2010-2015, Rene Gollent, rene@gollent.com.
* Copyright 2010-2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/

Expand Down Expand Up @@ -321,7 +321,7 @@ TeamDebugger::~TeamDebugger()


status_t
TeamDebugger::Init(team_id teamID, thread_id threadID, int argc,
TeamDebugger::Init(DebuggerInterface* interface, thread_id threadID, int argc,
const char* const* argv, bool stopInMain)
{
bool targetIsLocal = true;
Expand All @@ -330,20 +330,14 @@ TeamDebugger::Init(team_id teamID, thread_id threadID, int argc,
// the first thing we want to do when running
PostMessage(MSG_LOAD_SETTINGS);

fTeamID = teamID;

status_t error = _HandleSetArguments(argc, argv);
if (error != B_OK)
return error;

// create debugger interface
fDebuggerInterface = new(std::nothrow) DebuggerInterface(fTeamID);
if (fDebuggerInterface == NULL)
return B_NO_MEMORY;
fDebuggerInterface = interface;
fDebuggerInterface->AcquireReference();
fTeamID = interface->TeamID();

error = fDebuggerInterface->Init();
if (error != B_OK)
return error;

// create file manager
fFileManager = new(std::nothrow) FileManager;
Expand Down
6 changes: 3 additions & 3 deletions src/apps/debugger/controllers/TeamDebugger.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2013-2015, Rene Gollent, rene@gollent.com.
* Copyright 2013-2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef TEAM_DEBUGGER_H
Expand Down Expand Up @@ -42,8 +42,8 @@ class TeamDebugger : public BLooper, private UserInterfaceListener,
SettingsManager* settingsManager);
~TeamDebugger();

status_t Init(team_id teamID, thread_id threadID,
int argc,
status_t Init(DebuggerInterface* interface,
thread_id threadID, int argc,
const char* const* argv,
bool stopInMain);

Expand Down
3 changes: 3 additions & 0 deletions src/apps/debugger/debugger_interface/DebuggerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class DebuggerInterface : public TeamMemory {
bool Connected() const
{ return fNubPort >= 0; }

team_id TeamID() const
{ return fTeamID; }

Architecture* GetArchitecture() const
{ return fArchitecture; }

Expand Down

0 comments on commit 6bef41c

Please sign in to comment.