LLDB mainline
ConnectionFileDescriptorPosix.cpp
Go to the documentation of this file.
1//===-- ConnectionFileDescriptorPosix.cpp ---------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#if defined(__APPLE__)
10// Enable this special support for Apple builds where we can have unlimited
11// select bounds. We tried switching to poll() and kqueue and we were panicing
12// the kernel, so we have to stick with select for now.
13#define _DARWIN_UNLIMITED_SELECT
14#endif
15
17#include "lldb/Host/Config.h"
19#include "lldb/Host/Socket.h"
24
25#include <cerrno>
26#include <cstdlib>
27#include <cstring>
28#include <fcntl.h>
29#include <sys/types.h>
30
31#if LLDB_ENABLE_POSIX
32#include <termios.h>
33#include <unistd.h>
34#endif
35
36#include <memory>
37#include <sstream>
38
39#include "llvm/Support/Errno.h"
40#include "llvm/Support/ErrorHandling.h"
41#if defined(__APPLE__)
42#include "llvm/ADT/SmallVector.h"
43#endif
44#include "lldb/Host/Host.h"
45#include "lldb/Host/Socket.h"
48#include "lldb/Utility/Log.h"
50#include "lldb/Utility/Timer.h"
51
52using namespace lldb;
53using namespace lldb_private;
54
56 : Connection(), m_pipe(), m_mutex(), m_shutting_down(false) {
58 LLDB_LOGF(log, "%p ConnectionFileDescriptor::ConnectionFileDescriptor ()",
59 static_cast<void *>(this));
60}
61
63 : Connection(), m_pipe(), m_mutex(), m_shutting_down(false) {
64 m_io_sp =
65 std::make_shared<NativeFile>(fd, File::eOpenOptionReadWrite, owns_fd);
66
68 LLDB_LOGF(log,
69 "%p ConnectionFileDescriptor::ConnectionFileDescriptor (fd = "
70 "%i, owns_fd = %i)",
71 static_cast<void *>(this), fd, owns_fd);
73}
74
76 std::unique_ptr<Socket> socket_up)
77 : m_shutting_down(false) {
78 m_uri = socket_up->GetRemoteConnectionURI();
79 m_io_sp = std::move(socket_up);
80}
81
84 LLDB_LOGF(log, "%p ConnectionFileDescriptor::~ConnectionFileDescriptor ()",
85 static_cast<void *>(this));
86 Disconnect(nullptr);
88}
89
92
94 // Make the command file descriptor here:
95 Status result = m_pipe.CreateNew();
96 if (!result.Success()) {
97 LLDB_LOGF(log,
98 "%p ConnectionFileDescriptor::OpenCommandPipe () - could not "
99 "make pipe: %s",
100 static_cast<void *>(this), result.AsCString());
101 } else {
102 LLDB_LOGF(log,
103 "%p ConnectionFileDescriptor::OpenCommandPipe() - success "
104 "readfd=%d writefd=%d",
105 static_cast<void *>(this), m_pipe.GetReadFileDescriptor(),
106 m_pipe.GetWriteFileDescriptor());
107 }
108}
109
112 LLDB_LOGF(log, "%p ConnectionFileDescriptor::CloseCommandPipe()",
113 static_cast<void *>(this));
114
115 m_pipe.Close();
116}
117
119 return m_io_sp && m_io_sp->IsValid();
120}
121
123 Status *error_ptr) {
124 return Connect(path, [](llvm::StringRef) {}, error_ptr);
125}
126
129 socket_id_callback_type socket_id_callback,
130 Status *error_ptr) {
131 std::lock_guard<std::recursive_mutex> guard(m_mutex);
133 LLDB_LOGF(log, "%p ConnectionFileDescriptor::Connect (url = '%s')",
134 static_cast<void *>(this), path.str().c_str());
135
137
138 if (path.empty()) {
139 if (error_ptr)
140 *error_ptr = Status::FromErrorString("invalid connect arguments");
142 }
143
144 llvm::StringRef scheme;
145 std::tie(scheme, path) = path.split("://");
146
147 if (!path.empty()) {
148 auto method =
149 llvm::StringSwitch<ConnectionStatus (ConnectionFileDescriptor::*)(
150 llvm::StringRef, socket_id_callback_type, Status *)>(scheme)
152 .Cases({"accept", "unix-accept"},
154 .Case("unix-abstract-accept",
156 .Cases({"connect", "tcp-connect"},
160 .Case("unix-abstract-connect",
162#if LLDB_ENABLE_POSIX
166#endif
167 .Default(nullptr);
168
169 if (method) {
170 if (error_ptr)
171 *error_ptr = Status();
172 return (this->*method)(path, socket_id_callback, error_ptr);
173 }
174 }
175
176 if (error_ptr)
178 "unsupported connection URL: '%s'", path.str().c_str());
180}
181
183 return !errorToBool(m_pipe.Write("i", 1).takeError());
184}
185
188 LLDB_LOGF(log, "%p ConnectionFileDescriptor::Disconnect ()",
189 static_cast<void *>(this));
190
192
193 if (!IsConnected()) {
194 LLDB_LOGF(
195 log, "%p ConnectionFileDescriptor::Disconnect(): Nothing to disconnect",
196 static_cast<void *>(this));
198 }
199
200 // Try to get the ConnectionFileDescriptor's mutex. If we fail, that is
201 // quite likely because somebody is doing a blocking read on our file
202 // descriptor. If that's the case, then send the "q" char to the command
203 // file channel so the read will wake up and the connection will then know to
204 // shut down.
205 std::unique_lock<std::recursive_mutex> locker(m_mutex, std::defer_lock);
206 if (!locker.try_lock()) {
207 if (m_pipe.CanWrite()) {
208 llvm::Error err = m_pipe.Write("q", 1).takeError();
209 LLDB_LOG(log,
210 "{0}: Couldn't get the lock, sent 'q' to {1}, error = '{2}'.",
211 this, m_pipe.GetWriteFileDescriptor(), err);
212 consumeError(std::move(err));
213 } else {
214 LLDB_LOGF(log,
215 "%p ConnectionFileDescriptor::Disconnect(): Couldn't get the "
216 "lock, but no command pipe is available.",
217 static_cast<void *>(this));
218 }
219 locker.lock();
220 }
221
222 // Prevents reads and writes during shutdown.
223 m_shutting_down = true;
224
225 Status error = m_io_sp->Close();
226 if (error.Fail())
227 status = eConnectionStatusError;
228 if (error_ptr)
229 *error_ptr = std::move(error);
230
231 // Close any pipes we were using for async interrupts
232 m_pipe.Close();
233
234 m_uri.clear();
235 m_shutting_down = false;
236 return status;
237}
238
239size_t ConnectionFileDescriptor::Read(void *dst, size_t dst_len,
240 const Timeout<std::micro> &timeout,
241 ConnectionStatus &status,
242 Status *error_ptr) {
244
245 std::unique_lock<std::recursive_mutex> locker(m_mutex, std::defer_lock);
246 if (!locker.try_lock()) {
247 LLDB_LOGF(log,
248 "%p ConnectionFileDescriptor::Read () failed to get the "
249 "connection lock.",
250 static_cast<void *>(this));
251 if (error_ptr)
252 *error_ptr = Status::FromErrorString(
253 "failed to get the connection lock for read.");
254
256 return 0;
257 }
258
259 if (m_shutting_down) {
260 if (error_ptr)
261 *error_ptr = Status::FromErrorString("shutting down");
262 status = eConnectionStatusError;
263 return 0;
264 }
265
266 status = BytesAvailable(timeout, error_ptr);
267 if (status != eConnectionStatusSuccess)
268 return 0;
269
271 size_t bytes_read = dst_len;
272 error = m_io_sp->Read(dst, bytes_read);
273
274 LLDB_LOG(log,
275 "{0} ConnectionFileDescriptor::Read() fd = {1}"
276 ", dst = {2}, dst_len = {3}) => {4}, error = {5}",
277 this, m_io_sp->GetWaitableHandle(), dst, dst_len, bytes_read,
278 error.AsCString());
279
280 if (bytes_read == 0) {
281 error.Clear(); // End-of-file. Do not automatically close; pass along for
282 // the end-of-file handlers.
284 }
285
286 if (error_ptr)
287 *error_ptr = error.Clone();
288
289 if (error.Fail()) {
290 uint32_t error_value = error.GetError();
291 switch (error_value) {
292 case EAGAIN: // The file was marked for non-blocking I/O, and no data were
293 // ready to be read.
294 if (m_io_sp->GetFdType() == IOObject::eFDTypeSocket)
296 else
298 return 0;
299
300 case EFAULT: // Buf points outside the allocated address space.
301 case EINTR: // A read from a slow device was interrupted before any data
302 // arrived by the delivery of a signal.
303 case EINVAL: // The pointer associated with fildes was negative.
304 case EIO: // An I/O error occurred while reading from the file system.
305 // The process group is orphaned.
306 // The file is a regular file, nbyte is greater than 0, the
307 // starting position is before the end-of-file, and the
308 // starting position is greater than or equal to the offset
309 // maximum established for the open file descriptor
310 // associated with fildes.
311 case EISDIR: // An attempt is made to read a directory.
312 case ENOBUFS: // An attempt to allocate a memory buffer fails.
313 case ENOMEM: // Insufficient memory is available.
314 status = eConnectionStatusError;
315 break; // Break to close....
316
317 case ENOENT: // no such file or directory
318 case EBADF: // fildes is not a valid file or socket descriptor open for
319 // reading.
320 case ENXIO: // An action is requested of a device that does not exist..
321 // A requested action cannot be performed by the device.
322 case ECONNRESET: // The connection is closed by the peer during a read
323 // attempt on a socket.
324 case ENOTCONN: // A read is attempted on an unconnected socket.
326 break; // Break to close....
327
328 case ETIMEDOUT: // A transmission timeout occurs during a read attempt on a
329 // socket.
331 return 0;
332
333 default:
334 LLDB_LOG(log, "this = {0}, unexpected error: {1}", this,
335 llvm::sys::StrError(error_value));
336 status = eConnectionStatusError;
337 break; // Break to close....
338 }
339
340 return 0;
341 }
342 return bytes_read;
343}
344
345size_t ConnectionFileDescriptor::Write(const void *src, size_t src_len,
346 ConnectionStatus &status,
347 Status *error_ptr) {
349 LLDB_LOGF(log,
350 "%p ConnectionFileDescriptor::Write (src = %p, src_len = %" PRIu64
351 ")",
352 static_cast<void *>(this), static_cast<const void *>(src),
353 static_cast<uint64_t>(src_len));
354
355 if (!IsConnected()) {
356 if (error_ptr)
357 *error_ptr = Status::FromErrorString("not connected");
359 return 0;
360 }
361
362 if (m_shutting_down) {
363 if (error_ptr)
364 *error_ptr = Status::FromErrorString("shutting down");
365 status = eConnectionStatusError;
366 return 0;
367 }
368
370
371 size_t bytes_sent = src_len;
372 error = m_io_sp->Write(src, bytes_sent);
373
374 LLDB_LOG(log,
375 "{0} ConnectionFileDescriptor::Write(fd = {1}"
376 ", src = {2}, src_len = {3}) => {4} (error = {5})",
377 this, m_io_sp->GetWaitableHandle(), src, src_len, bytes_sent,
378 error.AsCString());
379
380 if (error_ptr)
381 *error_ptr = error.Clone();
382
383 if (error.Fail()) {
384 switch (error.GetError()) {
385 case EAGAIN:
386 case EINTR:
388 return 0;
389
390 case ECONNRESET: // The connection is closed by the peer during a read
391 // attempt on a socket.
392 case ENOTCONN: // A read is attempted on an unconnected socket.
394 break; // Break to close....
395
396 default:
397 status = eConnectionStatusError;
398 break; // Break to close....
399 }
400
401 return 0;
402 }
403
405 return bytes_sent;
406}
407
409
410// This ConnectionFileDescriptor::BytesAvailable() uses select() via
411// SelectHelper
412//
413// PROS:
414// - select is consistent across most unix platforms
415// - The Apple specific version allows for unlimited fds in the fd_sets by
416// setting the _DARWIN_UNLIMITED_SELECT define prior to including the
417// required header files.
418// CONS:
419// - on non-Apple platforms, only supports file descriptors up to FD_SETSIZE.
420// This implementation will assert if it runs into that hard limit to let
421// users know that another ConnectionFileDescriptor::BytesAvailable() should
422// be used or a new version of ConnectionFileDescriptor::BytesAvailable()
423// should be written for the system that is running into the limitations.
424
427 Status *error_ptr) {
428 // Don't need to take the mutex here separately since we are only called from
429 // Read. If we ever get used more generally we will need to lock here as
430 // well.
431
433 LLDB_LOG(log, "this = {0}, timeout = {1}", this, timeout);
434
435 // Make a copy of the file descriptors to make sure we don't have another
436 // thread change these values out from under us and cause problems in the
437 // loop below where like in FS_SET()
438 const IOObject::WaitableHandle handle = m_io_sp->GetWaitableHandle();
439 const int pipe_fd = m_pipe.GetReadFileDescriptor();
440
441 if (handle != IOObject::kInvalidHandleValue) {
442 SelectHelper select_helper;
443 if (timeout)
444 select_helper.SetTimeout(*timeout);
445
446 // FIXME: Migrate to MainLoop.
447 select_helper.FDSetRead(reinterpret_cast<socket_t>(handle));
448#if defined(_WIN32)
449 // select() won't accept pipes on Windows. The entire Windows codepath
450 // needs to be converted over to using WaitForMultipleObjects and event
451 // HANDLEs, but for now at least this will allow ::select() to not return
452 // an error.
453 const bool have_pipe_fd = false;
454#else
455 const bool have_pipe_fd = pipe_fd >= 0;
456#endif
457 if (have_pipe_fd)
458 select_helper.FDSetRead(pipe_fd);
459
460 while (handle == m_io_sp->GetWaitableHandle()) {
461
462 Status error = select_helper.Select();
463
464 if (error_ptr)
465 *error_ptr = error.Clone();
466
467 if (error.Fail()) {
468 switch (error.GetError()) {
469 case EBADF: // One of the descriptor sets specified an invalid
470 // descriptor.
472
473 case EINVAL: // The specified time limit is invalid. One of its
474 // components is negative or too large.
475 default: // Other unknown error
477
478 case ETIMEDOUT:
480
481 case EAGAIN: // The kernel was (perhaps temporarily) unable to
482 // allocate the requested number of file descriptors, or
483 // we have non-blocking IO
484 case EINTR: // A signal was delivered before the time limit
485 // expired and before any of the selected events occurred.
486 break; // Lets keep reading to until we timeout
487 }
488 } else {
489 if (select_helper.FDIsSetRead((lldb::socket_t)handle))
491
492 if (select_helper.FDIsSetRead(pipe_fd)) {
493 // There is an interrupt or exit command in the command pipe Read the
494 // data from that pipe:
495 char c;
496
497 ssize_t bytes_read =
498 llvm::sys::RetryAfterSignal(-1, ::read, pipe_fd, &c, 1);
499 assert(bytes_read == 1);
500 UNUSED_IF_ASSERT_DISABLED(bytes_read);
501 switch (c) {
502 case 'q':
503 LLDB_LOGF(log,
504 "%p ConnectionFileDescriptor::BytesAvailable() "
505 "got data: %c from the command channel.",
506 static_cast<void *>(this), c);
508 case 'i':
509 // Interrupt the current read
511 }
512 }
513 }
514 }
515 }
516
517 if (error_ptr)
518 *error_ptr = Status::FromErrorString("not connected");
520}
521
523 Socket::SocketProtocol socket_protocol, llvm::StringRef socket_name,
524 llvm::function_ref<void(Socket &)> post_listen_callback,
525 Status *error_ptr) {
527 std::unique_ptr<Socket> listening_socket =
528 Socket::Create(socket_protocol, error);
529 Socket *accepted_socket;
530
531 if (!error.Fail())
532 error = listening_socket->Listen(socket_name, 5);
533
534 if (!error.Fail()) {
535 post_listen_callback(*listening_socket);
536 error = listening_socket->Accept(/*timeout=*/std::nullopt, accepted_socket);
537 }
538
539 if (!error.Fail()) {
540 m_io_sp.reset(accepted_socket);
541 m_uri.assign(socket_name.str());
543 }
544
545 if (error_ptr)
546 *error_ptr = error.Clone();
548}
549
552 llvm::StringRef socket_name,
553 Status *error_ptr) {
555 std::unique_ptr<Socket> socket = Socket::Create(socket_protocol, error);
556
557 if (!error.Fail())
558 error = socket->Connect(socket_name);
559
560 if (!error.Fail()) {
561 m_io_sp = std::move(socket);
562 m_uri.assign(socket_name.str());
564 }
565
566 if (error_ptr)
567 *error_ptr = error.Clone();
569}
570
572 llvm::StringRef socket_name, socket_id_callback_type socket_id_callback,
573 Status *error_ptr) {
574 return AcceptSocket(
575 Socket::ProtocolUnixDomain, socket_name,
576 [socket_id_callback, socket_name](Socket &listening_socket) {
577 socket_id_callback(socket_name);
578 },
579 error_ptr);
580}
581
583 llvm::StringRef socket_name, socket_id_callback_type socket_id_callback,
584 Status *error_ptr) {
585 return ConnectSocket(Socket::ProtocolUnixDomain, socket_name, error_ptr);
586}
587
589 llvm::StringRef socket_name, socket_id_callback_type socket_id_callback,
590 Status *error_ptr) {
591 return AcceptSocket(
592 Socket::ProtocolUnixAbstract, socket_name,
593 [socket_id_callback, socket_name](Socket &listening_socket) {
594 socket_id_callback(socket_name);
595 },
596 error_ptr);
597}
598
600 llvm::StringRef socket_name, socket_id_callback_type socket_id_callback,
601 Status *error_ptr) {
602 return ConnectSocket(Socket::ProtocolUnixAbstract, socket_name, error_ptr);
603}
604
606ConnectionFileDescriptor::AcceptTCP(llvm::StringRef socket_name,
607 socket_id_callback_type socket_id_callback,
608 Status *error_ptr) {
610 Socket::ProtocolTcp, socket_name,
611 [socket_id_callback](Socket &listening_socket) {
612 uint16_t port =
613 static_cast<TCPSocket &>(listening_socket).GetLocalPortNumber();
614 socket_id_callback(std::to_string(port));
615 },
616 error_ptr);
617 if (ret == eConnectionStatusSuccess)
618 m_uri.assign(
619 static_cast<TCPSocket *>(m_io_sp.get())->GetRemoteConnectionURI());
620 return ret;
621}
622
624ConnectionFileDescriptor::ConnectTCP(llvm::StringRef socket_name,
625 socket_id_callback_type socket_id_callback,
626 Status *error_ptr) {
627 return ConnectSocket(Socket::ProtocolTcp, socket_name, error_ptr);
628}
629
632 socket_id_callback_type socket_id_callback,
633 Status *error_ptr) {
634 if (error_ptr)
635 *error_ptr = Status();
636 llvm::Expected<std::unique_ptr<UDPSocket>> socket = Socket::UdpConnect(s);
637 if (!socket) {
638 if (error_ptr)
639 *error_ptr = Status::FromError(socket.takeError());
640 else
641 LLDB_LOG_ERROR(GetLog(LLDBLog::Connection), socket.takeError(),
642 "tcp connect failed: {0}");
644 }
645 m_io_sp = std::move(*socket);
646 m_uri.assign(std::string(s));
648}
649
652 socket_id_callback_type socket_id_callback,
653 Status *error_ptr) {
654#if LLDB_ENABLE_POSIX
655 // Just passing a native file descriptor within this current process that
656 // is already opened (possibly from a service or other source).
657 int fd = -1;
658
659 if (!s.getAsInteger(0, fd)) {
660 // We have what looks to be a valid file descriptor, but we should make
661 // sure it is. We currently are doing this by trying to get the flags
662 // from the file descriptor and making sure it isn't a bad fd.
663 errno = 0;
664 int flags = ::fcntl(fd, F_GETFL, 0);
665 if (flags == -1 || errno == EBADF) {
666 if (error_ptr)
668 "stale file descriptor: %s", s.str().c_str());
669 m_io_sp.reset();
671 } else {
672 // Don't take ownership of a file descriptor that gets passed to us
673 // since someone else opened the file descriptor and handed it to us.
674 // TODO: Since are using a URL to open connection we should
675 // eventually parse options using the web standard where we have
676 // "fd://123?opt1=value;opt2=value" and we can have an option be
677 // "owns=1" or "owns=0" or something like this to allow us to specify
678 // this. For now, we assume we must assume we don't own it.
679
680 std::unique_ptr<TCPSocket> tcp_socket;
681 tcp_socket = std::make_unique<TCPSocket>(fd, /*should_close=*/false);
682 // Try and get a socket option from this file descriptor to see if
683 // this is a socket and set m_is_socket accordingly.
684 int resuse;
685 bool is_socket =
686 !!tcp_socket->GetOption(SOL_SOCKET, SO_REUSEADDR, resuse);
687 if (is_socket)
688 m_io_sp = std::move(tcp_socket);
689 else
690 m_io_sp =
691 std::make_shared<NativeFile>(fd, File::eOpenOptionReadWrite, false);
692 m_uri = s.str();
694 }
695 }
696
697 if (error_ptr)
699 "invalid file descriptor: \"%s\"", s.str().c_str());
700 m_io_sp.reset();
702#endif // LLDB_ENABLE_POSIX
703 llvm_unreachable("this function should be only called w/ LLDB_ENABLE_POSIX");
704}
705
707 llvm::StringRef s, socket_id_callback_type socket_id_callback,
708 Status *error_ptr) {
709#if LLDB_ENABLE_POSIX
710 std::string addr_str = s.str();
711 // file:///PATH
712 int fd = FileSystem::Instance().Open(addr_str.c_str(), O_RDWR);
713 if (fd == -1) {
714 if (error_ptr)
715 *error_ptr = Status::FromErrno();
717 }
718
719 if (::isatty(fd)) {
720 // Set up serial terminal emulation
721 struct termios options;
722 ::tcgetattr(fd, &options);
723
724 // Set port speed to the available maximum
725#ifdef B115200
726 ::cfsetospeed(&options, B115200);
727 ::cfsetispeed(&options, B115200);
728#elif B57600
729 ::cfsetospeed(&options, B57600);
730 ::cfsetispeed(&options, B57600);
731#elif B38400
732 ::cfsetospeed(&options, B38400);
733 ::cfsetispeed(&options, B38400);
734#else
735#error "Maximum Baud rate is Unknown"
736#endif
737
738 // Raw input, disable echo and signals
739 options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
740
741 // Make sure only one character is needed to return from a read
742 options.c_cc[VMIN] = 1;
743 options.c_cc[VTIME] = 0;
744
745 llvm::sys::RetryAfterSignal(-1, ::tcsetattr, fd, TCSANOW, &options);
746 }
747
748 m_io_sp = std::make_shared<NativeFile>(fd, File::eOpenOptionReadWrite, true);
750#endif // LLDB_ENABLE_POSIX
751 llvm_unreachable("this function should be only called w/ LLDB_ENABLE_POSIX");
752}
753
755 llvm::StringRef s, socket_id_callback_type socket_id_callback,
756 Status *error_ptr) {
757#if LLDB_ENABLE_POSIX
758 llvm::StringRef path, qs;
759 // serial:///PATH?k1=v1&k2=v2...
760 std::tie(path, qs) = s.split('?');
761
762 llvm::Expected<SerialPort::Options> serial_options =
764 if (!serial_options) {
765 if (error_ptr)
766 *error_ptr = Status::FromError(serial_options.takeError());
767 else
768 llvm::consumeError(serial_options.takeError());
770 }
771
772 int fd = FileSystem::Instance().Open(path.str().c_str(), O_RDWR);
773 if (fd == -1) {
774 if (error_ptr)
775 *error_ptr = Status::FromErrno();
777 }
778
779 llvm::Expected<std::unique_ptr<SerialPort>> serial_sp = SerialPort::Create(
780 fd, File::eOpenOptionReadWrite, serial_options.get(), true);
781 if (!serial_sp) {
782 if (error_ptr)
783 *error_ptr = Status::FromError(serial_sp.takeError());
784 else
785 llvm::consumeError(serial_sp.takeError());
787 }
788 m_io_sp = std::move(serial_sp.get());
789
791#endif // LLDB_ENABLE_POSIX
792 llvm_unreachable("this function should be only called w/ LLDB_ENABLE_POSIX");
793}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:369
#define LLDB_LOGF(log,...)
Definition Log.h:383
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:399
lldb_private::Status Select()
void FDSetRead(lldb::socket_t fd)
void SetTimeout(const std::chrono::microseconds &timeout)
bool FDIsSetRead(lldb::socket_t fd) const
lldb::ConnectionStatus AcceptTCP(llvm::StringRef host_and_port, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectNamedSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus AcceptAbstractSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectUDP(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectSerialPort(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
bool InterruptRead() override
Interrupts an ongoing Read() operation.
lldb::ConnectionStatus Connect(llvm::StringRef url, Status *error_ptr) override
Connect using the connect string url.
bool IsConnected() const override
Check if the connection is valid.
lldb::ConnectionStatus AcceptNamedSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status, Status *error_ptr) override
The actual write function that attempts to write to the communications protocol.
lldb::ConnectionStatus AcceptSocket(Socket::SocketProtocol socket_protocol, llvm::StringRef socket_name, llvm::function_ref< void(Socket &)> post_listen_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectFD(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectAbstractSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus Disconnect(Status *error_ptr) override
Disconnect the communications connection if one is currently connected.
lldb::ConnectionStatus BytesAvailable(const Timeout< std::micro > &timeout, Status *error_ptr)
lldb::ConnectionStatus ConnectFile(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectSocket(Socket::SocketProtocol socket_protocol, llvm::StringRef socket_name, Status *error_ptr)
std::string GetURI() override
Returns a URI that describes this connection object.
lldb::ConnectionStatus ConnectTCP(llvm::StringRef host_and_port, socket_id_callback_type socket_id_callback, Status *error_ptr)
size_t Read(void *dst, size_t dst_len, const Timeout< std::micro > &timeout, lldb::ConnectionStatus &status, Status *error_ptr) override
The read function that attempts to read from the connection.
llvm::function_ref< void(llvm::StringRef local_socket_id)> socket_id_callback_type
Connection()=default
Default constructor.
int Open(const char *path, int flags, int mode=0600)
Wraps open in a platform-independent way.
static FileSystem & Instance()
@ eOpenOptionReadWrite
Definition File.h:53
static const WaitableHandle kInvalidHandleValue
Definition IOObject.h:31
lldb::file_t WaitableHandle
Definition IOObject.h:29
static llvm::Expected< std::unique_ptr< SerialPort > > Create(int fd, OpenOptions options, Options serial_options, bool transfer_ownership)
Definition File.cpp:931
static llvm::Expected< Options > OptionsFromURL(llvm::StringRef urlqs)
Definition File.cpp:876
static std::unique_ptr< Socket > Create(const SocketProtocol protocol, Status &error)
Definition Socket.cpp:200
static llvm::Expected< std::unique_ptr< UDPSocket > > UdpConnect(llvm::StringRef host_and_port)
Definition Socket.cpp:287
An error handling class.
Definition Status.h:118
static Status FromErrno()
Set the current error to errno.
Definition Status.cpp:299
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:194
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:136
bool Success() const
Test for success condition.
Definition Status.cpp:303
std::string GetRemoteConnectionURI() const override
#define UNUSED_IF_ASSERT_DISABLED(x)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
ConnectionStatus
Connection Status Types.
@ eConnectionStatusError
Check GetError() for details.
@ eConnectionStatusInterrupted
Interrupted read.
@ eConnectionStatusTimedOut
Request timed out.
@ eConnectionStatusEndOfFile
End-of-file encountered.
@ eConnectionStatusSuccess
Success.
@ eConnectionStatusLostConnection
Lost connection while connected to a valid connection.
@ eConnectionStatusNoConnection
No connection.
int socket_t
Definition lldb-types.h:60