Debugger: Add dedicated functions for global {un}init.
- 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.
This commit is contained in:
parent
5c8ba745e5
commit
e6687e8f3d
@ -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"
|
||||
@ -38,7 +38,6 @@
|
||||
#include "TargetHostInterfaceRoster.h"
|
||||
#include "TeamDebugger.h"
|
||||
#include "TeamsWindow.h"
|
||||
#include "TypeHandlerRoster.h"
|
||||
#include "ValueHandlerRoster.h"
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -642,6 +612,8 @@ CliDebugger::CliDebugger()
|
||||
|
||||
CliDebugger::~CliDebugger()
|
||||
{
|
||||
DebuggerUiSettingsFactory::DeleteDefault();
|
||||
debugger_global_uninit();
|
||||
}
|
||||
|
||||
|
||||
@ -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) {
|
||||
@ -715,6 +695,7 @@ ReportDebugger::ReportDebugger()
|
||||
|
||||
ReportDebugger::~ReportDebugger()
|
||||
{
|
||||
debugger_global_uninit();
|
||||
}
|
||||
|
||||
|
||||
@ -722,7 +703,7 @@ 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));
|
||||
|
48
src/apps/debugger/DebuggerGlobals.cpp
Normal file
48
src/apps/debugger/DebuggerGlobals.cpp
Normal file
@ -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
src/apps/debugger/DebuggerGlobals.h
Normal file
16
src/apps/debugger/DebuggerGlobals.h
Normal file
@ -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
|
@ -81,6 +81,7 @@ SourceHdrs
|
||||
|
||||
local sources =
|
||||
Debugger.cpp
|
||||
DebuggerGlobals.cpp
|
||||
|
||||
# arch
|
||||
Architecture.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user