17
17
#include " DebugServer2/Host/Platform.h"
18
18
#include " DebugServer2/Host/QueueChannel.h"
19
19
#include " DebugServer2/Host/Socket.h"
20
+ #if defined(OS_POSIX)
21
+ #include " DebugServer2/Host/POSIX/HandleChannel.h"
22
+ #endif
20
23
#include " DebugServer2/Utils/Daemon.h"
21
24
#include " DebugServer2/Utils/Log.h"
22
25
#include " DebugServer2/Utils/OptParse.h"
@@ -197,10 +200,10 @@ static std::unique_ptr<Socket> CreateSocket(std::string const &arg,
197
200
DS2_UNREACHABLE ();
198
201
}
199
202
200
- static int RunDebugServer (Socket *socket , SessionDelegate *impl) {
203
+ static int RunDebugServer (ds2::Host::Channel *channel , SessionDelegate *impl) {
201
204
Session session (gGDBCompat ? ds2::GDBRemote::kCompatibilityModeGDB
202
205
: ds2::GDBRemote::kCompatibilityModeLLDB );
203
- QueueChannel qchannel (socket );
206
+ QueueChannel qchannel (channel );
204
207
SessionThread thread (&qchannel, &session);
205
208
206
209
session.setDelegate (impl);
@@ -392,6 +395,9 @@ static int GdbserverMain(int argc, char **argv) {
392
395
bool reverse = opts.getBool (" reverse-connect" );
393
396
394
397
std::unique_ptr<Socket> socket;
398
+ #if defined(OS_POSIX)
399
+ std::unique_ptr<ds2::Host::HandleChannel> device;
400
+ #endif
395
401
396
402
switch (connection_type) {
397
403
case channel_type::named_pipe:
@@ -419,6 +425,15 @@ static int GdbserverMain(int argc, char **argv) {
419
425
}
420
426
break ;
421
427
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
+
422
437
case channel_type::character_device:
423
438
#if defined(OS_POSIX)
424
439
if (std::filesystem::exists (address))
@@ -444,24 +459,33 @@ static int GdbserverMain(int argc, char **argv) {
444
459
}
445
460
#endif
446
461
447
- [[fallthrough]];
462
+ device = std::make_unique<ds2::Host::HandleChannel>(fd);
463
+ break ;
448
464
#else
449
465
DS2BUG (" connecting with chardev is not supported on this platform" );
450
466
#endif
467
+ }
468
+
469
+ if (gDaemonize ) {
470
+ ds2::Utils::Daemonize ();
471
+ }
472
+
473
+ ds2::Host::Channel *channel;
474
+ switch (connection_type) {
451
475
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:
452
481
#if defined(OS_POSIX)
453
- socket = CreateFDSocket (fd );
482
+ channel = device. get ( );
454
483
#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" );
457
485
#endif
458
486
break ;
459
487
}
460
488
461
- if (gDaemonize ) {
462
- ds2::Utils::Daemonize ();
463
- }
464
-
465
489
std::unique_ptr<DebugSessionImpl> impl;
466
490
467
491
if (attachPid > 0 )
@@ -471,13 +495,7 @@ static int GdbserverMain(int argc, char **argv) {
471
495
else
472
496
impl = ds2::make_unique<DebugSessionImpl>();
473
497
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 ());
481
499
}
482
500
483
501
#if !defined(OS_WIN32)
0 commit comments