33
33
#include < thread>
34
34
35
35
#include < fcntl.h>
36
-
36
+ #if HAVE_TERMIOS_H
37
+ #include < termios.h>
38
+ #endif
37
39
#if !defined(OS_WIN32)
38
40
#include < unistd.h>
39
41
#endif
@@ -297,6 +299,7 @@ static int GdbserverMain(int argc, char **argv) {
297
299
298
300
enum class channel_type {
299
301
file_descriptor,
302
+ character_device,
300
303
named_pipe,
301
304
network,
302
305
};
@@ -322,6 +325,10 @@ static int GdbserverMain(int argc, char **argv) {
322
325
connection_type = channel_type::named_pipe;
323
326
324
327
const std::string &address = opts.getPositional (" [host]:port" );
328
+ #if defined(OS_POSIX)
329
+ if (!address.empty () && address.find_first_of (" :" ) == std::string::npos)
330
+ connection_type = channel_type::character_device;
331
+ #endif
325
332
326
333
switch (connection_type) {
327
334
case channel_type::file_descriptor:
@@ -412,6 +419,35 @@ static int GdbserverMain(int argc, char **argv) {
412
419
}
413
420
break ;
414
421
422
+ case channel_type::character_device:
423
+ #if defined(OS_POSIX)
424
+ if (std::filesystem::exists (address))
425
+ if (std::filesystem::is_character_file (address) ||
426
+ std::filesystem::is_fifo (address))
427
+ fd = ::open (address.c_str (), O_RDWR);
428
+ if (fd < 0 ) {
429
+ DS2LOG (Error, " unable to open %s: %s" , address.c_str (), strerror (errno));
430
+ ::exit (EXIT_FAILURE);
431
+ }
432
+
433
+ #if HAVE_TERMIOS_H
434
+ {
435
+ struct termios termios;
436
+ (void )tcgetattr (fd, &termios);
437
+ termios.c_iflag = 0 ;
438
+ termios.c_oflag = 0 ;
439
+ termios.c_cflag = (termios.c_cflag & ~(CSIZE | PARENB)) | CLOCAL | CS8;
440
+ termios.c_lflag = 0 ;
441
+ termios.c_cc [VMIN] = 1 ;
442
+ termios.c_cc [VTIME] = 0 ;
443
+ (void )tcsetattr (fd, TCSANOW, &termios);
444
+ }
445
+ #endif
446
+
447
+ [[fallthrough]];
448
+ #else
449
+ DS2BUG (" connecting with chardev is not supported on this platform" );
450
+ #endif
415
451
case channel_type::file_descriptor:
416
452
#if defined(OS_POSIX)
417
453
socket = CreateFDSocket (fd);
0 commit comments