Skip to content

Commit

Permalink
Debugger: Add dedicated functions for global {un}init.
Browse files Browse the repository at this point in the history
- Add new source file DebuggerGlobals, which contains the relevant
  functions for initializing/destroying the various singleton rosters
  that the core subsystems rely upon. It is the app's responsibility
  to ensure these are called before anything else, and as final cleanup
  at exit.
- The GUI/CLI app objects now take care of initializing the settings factory
  and ValueHandlerRoster, as those are entirely app-specific.
- Refactor calls to init functions appropriately.
  • Loading branch information
anevilyak committed Jun 4, 2016
1 parent 5c8ba74 commit e6687e8
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 44 deletions.
69 changes: 25 additions & 44 deletions src/apps/debugger/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
#include "CoreFile.h"
#include "CoreFileDebuggerInterface.h"
#include "CommandLineUserInterface.h"
#include "DebuggerGlobals.h"
#include "DebuggerInterface.h"
#include "DebuggerSettingsManager.h"
#include "DebuggerUiSettingsFactory.h"
#include "GraphicalUserInterface.h"
#include "ImageDebugLoadingStateHandlerRoster.h"
#include "MessageCodes.h"
#include "ReportUserInterface.h"
#include "SignalSet.h"
Expand All @@ -38,7 +38,6 @@
#include "TargetHostInterfaceRoster.h"
#include "TeamDebugger.h"
#include "TeamsWindow.h"
#include "TypeHandlerRoster.h"
#include "ValueHandlerRoster.h"


Expand Down Expand Up @@ -231,42 +230,6 @@ parse_arguments(int argc, const char* const* argv, bool noOutput,
}


static status_t
global_init(TargetHostInterfaceRoster::Listener* listener)
{
status_t error = DebuggerUiSettingsFactory::CreateDefault();
if (error != B_OK)
return error;

error = TypeHandlerRoster::CreateDefault();
if (error != B_OK)
return error;

error = ValueHandlerRoster::CreateDefault();
if (error != B_OK)
return error;

error = ImageDebugLoadingStateHandlerRoster::CreateDefault();
if (error != B_OK)
return error;

error = TargetHostInterfaceRoster::CreateDefault(listener);
if (error != B_OK)
return error;

// for now, always create an instance of the local interface
// by default
TargetHostInterface* hostInterface;
TargetHostInterfaceRoster* roster = TargetHostInterfaceRoster::Default();
error = roster->CreateInterface(roster->InterfaceInfoAt(0), NULL,
hostInterface);
if (error != B_OK)
return error;

return B_OK;
}


// #pragma mark - Debugger application class


Expand Down Expand Up @@ -338,16 +301,23 @@ Debugger::~Debugger()
{
DebuggerUiSettingsFactory::DeleteDefault();
ValueHandlerRoster::DeleteDefault();
TypeHandlerRoster::DeleteDefault();
ImageDebugLoadingStateHandlerRoster::DeleteDefault();
TargetHostInterfaceRoster::DeleteDefault();

debugger_global_uninit();
}


status_t
Debugger::Init()
{
status_t error = global_init(this);
status_t error = debugger_global_init(this);
if (error != B_OK)
return error;

error = DebuggerUiSettingsFactory::CreateDefault();
if (error != B_OK)
return error;

error = ValueHandlerRoster::CreateDefault();
if (error != B_OK)
return error;

Expand Down Expand Up @@ -642,6 +612,8 @@ CliDebugger::CliDebugger()

CliDebugger::~CliDebugger()
{
DebuggerUiSettingsFactory::DeleteDefault();
debugger_global_uninit();
}


Expand All @@ -654,13 +626,21 @@ CliDebugger::Run(const Options& options)
SignalSet(SIGINT).BlockInCurrentThread();

// initialize global objects and settings manager
status_t error = global_init(this);
status_t error = debugger_global_init(this);
if (error != B_OK) {
fprintf(stderr, "Error: Global initialization failed: %s\n",
strerror(error));
return false;
}

error = DebuggerUiSettingsFactory::CreateDefault();
if (error != B_OK) {
fprintf(stderr, "Error: Failed to create default settings factory: "
"%s\n", strerror(error));
return false;
}


DebuggerSettingsManager settingsManager;
error = settingsManager.Init(DebuggerUiSettingsFactory::Default());
if (error != B_OK) {
Expand Down Expand Up @@ -715,14 +695,15 @@ ReportDebugger::ReportDebugger()

ReportDebugger::~ReportDebugger()
{
debugger_global_uninit();
}


bool
ReportDebugger::Run(const Options& options)
{
// initialize global objects and settings manager
status_t error = global_init(this);
status_t error = debugger_global_init(this);
if (error != B_OK) {
fprintf(stderr, "Error: Global initialization failed: %s\n",
strerror(error));
Expand Down
48 changes: 48 additions & 0 deletions src/apps/debugger/DebuggerGlobals.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2009-2016, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2011-2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/

#include "DebuggerGlobals.h"

#include "ImageDebugLoadingStateHandlerRoster.h"
#include "TargetHostInterface.h"
#include "TypeHandlerRoster.h"


status_t
debugger_global_init(TargetHostInterfaceRoster::Listener* listener)
{
status_t error = TypeHandlerRoster::CreateDefault();
if (error != B_OK)
return error;

error = ImageDebugLoadingStateHandlerRoster::CreateDefault();
if (error != B_OK)
return error;

error = TargetHostInterfaceRoster::CreateDefault(listener);
if (error != B_OK)
return error;

// for now, always create an instance of the local interface
// by default
TargetHostInterface* hostInterface;
TargetHostInterfaceRoster* roster = TargetHostInterfaceRoster::Default();
error = roster->CreateInterface(roster->InterfaceInfoAt(0), NULL,
hostInterface);
if (error != B_OK)
return error;

return B_OK;
}


void
debugger_global_uninit()
{
TargetHostInterfaceRoster::DeleteDefault();
ImageDebugLoadingStateHandlerRoster::DeleteDefault();
TypeHandlerRoster::DeleteDefault();
}
16 changes: 16 additions & 0 deletions src/apps/debugger/DebuggerGlobals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2009-2016, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2011-2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef DEBUGGER_GLOBALS_H
#define DEBUGGER_GLOBALS_H

#include "TargetHostInterfaceRoster.h"


status_t debugger_global_init(TargetHostInterfaceRoster::Listener* listener);

void debugger_global_uninit();

#endif // DEBUGGER_GLOBALS_H
1 change: 1 addition & 0 deletions src/apps/debugger/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ SourceHdrs

local sources =
Debugger.cpp
DebuggerGlobals.cpp

# arch
Architecture.cpp
Expand Down

0 comments on commit e6687e8

Please sign in to comment.