1717#include " DebugServer2/Host/Platform.h"
1818#include " DebugServer2/Host/QueueChannel.h"
1919#include " DebugServer2/Host/Socket.h"
20+ #if defined(OS_POSIX)
21+ #include " DebugServer2/Host/POSIX/HandleChannel.h"
22+ #endif
2023#include " DebugServer2/Utils/Daemon.h"
2124#include " DebugServer2/Utils/Log.h"
2225#include " DebugServer2/Utils/OptParse.h"
@@ -197,10 +200,10 @@ static std::unique_ptr<Socket> CreateSocket(std::string const &arg,
197200 DS2_UNREACHABLE ();
198201}
199202
200- static int RunDebugServer (Socket *socket , SessionDelegate *impl) {
203+ static int RunDebugServer (ds2::Host::Channel *channel , SessionDelegate *impl) {
201204 Session session (gGDBCompat ? ds2::GDBRemote::kCompatibilityModeGDB
202205 : ds2::GDBRemote::kCompatibilityModeLLDB );
203- QueueChannel qchannel (socket );
206+ QueueChannel qchannel (channel );
204207 SessionThread thread (&qchannel, &session);
205208
206209 session.setDelegate (impl);
@@ -392,6 +395,9 @@ static int GdbserverMain(int argc, char **argv) {
392395 bool reverse = opts.getBool (" reverse-connect" );
393396
394397 std::unique_ptr<Socket> socket;
398+ #if defined(OS_POSIX)
399+ std::unique_ptr<ds2::Host::HandleChannel> device;
400+ #endif
395401
396402 switch (connection_type) {
397403 case channel_type::named_pipe:
@@ -419,6 +425,15 @@ static int GdbserverMain(int argc, char **argv) {
419425 }
420426 break ;
421427
428+ case channel_type::file_descriptor:
429+ #if defined(OS_POSIX)
430+ socket = CreateFDSocket (fd);
431+ #else
432+ (void )fd;
433+ DS2BUG (" connecting with file descriptor is not supported on this platform" );
434+ #endif
435+ break ;
436+
422437 case channel_type::character_device:
423438#if defined(OS_POSIX)
424439 if (std::filesystem::exists (address))
@@ -444,24 +459,33 @@ static int GdbserverMain(int argc, char **argv) {
444459 }
445460#endif
446461
447- [[fallthrough]];
462+ device = std::make_unique<ds2::Host::HandleChannel>(fd);
463+ break ;
448464#else
449465 DS2BUG (" connecting with chardev is not supported on this platform" );
450466#endif
467+ }
468+
469+ if (gDaemonize ) {
470+ ds2::Utils::Daemonize ();
471+ }
472+
473+ ds2::Host::Channel *channel;
474+ switch (connection_type) {
451475 case channel_type::file_descriptor:
476+ case channel_type::named_pipe:
477+ case channel_type::network:
478+ channel = (fd >= 0 || reverse) ? socket.get () : socket->accept ().get ();
479+ break ;
480+ case channel_type::character_device:
452481#if defined(OS_POSIX)
453- socket = CreateFDSocket (fd );
482+ channel = device. get ( );
454483#else
455- (void )fd;
456- DS2BUG (" connecting with file descriptor is not supported on this platform" );
484+ DS2BUG (" connecting with chardev is not supported on this platform" );
457485#endif
458486 break ;
459487 }
460488
461- if (gDaemonize ) {
462- ds2::Utils::Daemonize ();
463- }
464-
465489 std::unique_ptr<DebugSessionImpl> impl;
466490
467491 if (attachPid > 0 )
@@ -471,13 +495,7 @@ static int GdbserverMain(int argc, char **argv) {
471495 else
472496 impl = ds2::make_unique<DebugSessionImpl>();
473497
474- #if defined(OS_POSIX)
475- return RunDebugServer (
476- (fd >= 0 || reverse) ? socket.get () : socket->accept ().get (), impl.get ());
477- #else
478- return RunDebugServer (reverse ? socket.get () : socket->accept ().get (),
479- impl.get ());
480- #endif
498+ return RunDebugServer (channel, impl.get ());
481499}
482500
483501#if !defined(OS_WIN32)
0 commit comments