3333#include < thread>
3434
3535#include < fcntl.h>
36-
36+ #if HAVE_TERMIOS_H
37+ #include < termios.h>
38+ #endif
3739#if !defined(OS_WIN32)
3840#include < unistd.h>
3941#endif
@@ -297,6 +299,7 @@ static int GdbserverMain(int argc, char **argv) {
297299
298300 enum class channel_type {
299301 file_descriptor,
302+ character_device,
300303 named_pipe,
301304 network,
302305 };
@@ -322,6 +325,10 @@ static int GdbserverMain(int argc, char **argv) {
322325 connection_type = channel_type::named_pipe;
323326
324327 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
325332
326333 switch (connection_type) {
327334 case channel_type::file_descriptor:
@@ -412,6 +419,35 @@ static int GdbserverMain(int argc, char **argv) {
412419 }
413420 break ;
414421
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
415451 case channel_type::file_descriptor:
416452#if defined(OS_POSIX)
417453 socket = CreateFDSocket (fd);
0 commit comments