blob: 1dbc86ff8e4e288e09bd42088488289d55717c65 [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <fidl/fuchsia.debugger/cpp/fidl.h>
#include <lib/component/outgoing/cpp/outgoing_directory.h>
#include <zircon/processargs.h>
#include <memory>
#include "lib/stdcompat/functional.h"
#include "src/developer/debug/debug_agent/debug_agent.h"
#include "src/developer/debug/debug_agent/debug_agent_server.h"
#include "src/developer/debug/debug_agent/zircon_system_interface.h"
#include "src/developer/debug/shared/platform_message_loop.h"
int main(int argc, const char* argv[]) {
debug::PlatformMessageLoop message_loop;
std::string init_error_message;
if (!message_loop.Init(&init_error_message)) {
LOGS(Error) << init_error_message;
return 1;
}
component::OutgoingDirectory outgoing = component::OutgoingDirectory(message_loop.dispatcher());
// The scope ensures the objects are destroyed before calling Cleanup on the MessageLoop.
{
// Take the server_end of the DebugAgent protocol we are handed from the launcher.
zx::channel server_end(zx_take_startup_handle(PA_HND(PA_USER0, 0)));
FX_CHECK(server_end.is_valid());
auto zircon_system_interface = std::make_unique<debug_agent::ZirconSystemInterface>();
debug_agent::DebugAgent debug_agent(std::move(zircon_system_interface));
auto res = outgoing.AddProtocol<fuchsia_debugger::DebugAgent>(
std::make_unique<debug_agent::DebugAgentServer>(debug_agent.GetWeakPtr()));
FX_CHECK(res.is_ok()) << res.error_value();
res = outgoing.ServeFromStartupInfo();
FX_CHECK(res.is_ok()) << res.error_value();
// Now explicitly bind to the given server_end from the startup handles.
auto debug_agent_server =
std::make_unique<debug_agent::DebugAgentServer>(debug_agent.GetWeakPtr());
fidl::BindServer(
message_loop.dispatcher(),
fidl::ServerEnd<fuchsia_debugger::DebugAgent>(std::move(server_end)),
std::move(debug_agent_server),
cpp20::bind_front(&debug_agent::DebugAgentServer::OnUnboundFn, debug_agent_server.get()));
// Run the loop.
message_loop.Run();
}
message_loop.Cleanup();
// It's very useful to have a simple message that informs the debug_agent exited successfully.
LOGS(Info) << "See you, Space Cowboy...";
return 0;
}