summaryrefslogtreecommitdiff
path: root/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
AgeCommit message (Collapse)Author
2025-11-02[ADT] Prepare to deprecate variadic `StringSwitch::Cases`. NFC. (#166020)Jakub Kuderski
Update all uses of variadic `.Cases` to use the initializer list overload instead. I plan to mark variadic `.Cases` as deprecated in a followup PR. For more context, see https://github.com/llvm/llvm-project/pull/163117.
2025-07-03[lldb] Remove PRIuFT macro and use LLDB_LOG instead (#146867)David Spickett
We don't want this as part of the public API, and using LLDB_LOG avoids some warnings when compiling on Windows.
2025-07-02[lldb] Fixing warnings / win32 builds in MainLoop. (#146632)John Harrison
Commit 1a7b7e24bcc1041ae0fb90abcfb73d36d76f4a07 introduced a few casting warnings and a build issue in Win32 platforms. Trying to correct the casts to c++ style casts instead of C style casts.
2025-07-01[lldb] Fix warningsKazu Hirata
This patch fixes: lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp:279:15: error: format specifies type 'unsigned long' but the argument has type 'file_t' (aka 'int') [-Werror,-Wformat] lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp:383:15: error: format specifies type 'unsigned long' but the argument has type 'file_t' (aka 'int') [-Werror,-Wformat]
2025-07-01[lldb] Adding pipe support to lldb_private::MainLoopWindows. (#145621)John Harrison
This updates MainLoopWindows to support events for reading from a pipe (both anonymous and named pipes) as well as sockets. This unifies both handle types using `WSAWaitForMultipleEvents` which can listen to both sockets and handles for change events. This should allow us to unify how we handle watching pipes/sockets on Windows and Posix systems. We can extend this in the future if we want to support watching other types, like files or even other events like a process life time. --------- Co-authored-by: Pavel Labath <pavel@labath.sk>
2025-06-26[lldb] Remove child_process_inherit argument from Pipe (#145516)Pavel Labath
It's not necessary on posix platforms as of #126935 and it's ignored on windows as of #138896. For both platforms, we have a better way of inheriting FDs/HANDLEs.
2025-06-24[lldb] Remove GDBRemoteCommunication::ConnectLocally (#145293)Pavel Labath
Originally added for reproducers, it is now only used for test code. While we could make it a test helper, I think that after #145015 it is simple enough to not be needed. Also squeeze in a change to make ConnectionFileDescriptor accept a unique_ptr<Socket>.
2025-02-27[lldb] Assorted improvements to the Pipe class (#128719)Pavel Labath
The main motivation for this was the inconsistency in handling of partial reads/writes between the windows and posix implementations (windows was returning partial reads, posix was trying to fill the buffer completely). I settle on the windows implementation, as that's the more common behavior, and the "eager" version can be implemented on top of that (in most cases, it isn't necessary, since we're writing just a single byte). Since this also required auditing the callers to make sure they're handling partial reads/writes correctly, I used the opportunity to modernize the function signatures as a forcing function. They now use the `Timeout` class (basically an `optional<duration>`) to support both polls (timeout=0) and blocking (timeout=nullopt) operations in a single function, and use an `Expected` instead of a by-ref result to return the number of bytes read/written. As a drive-by, I also fix a problem with the windows implementation where we were rounding the timeout value down, which meant that calls could time out slightly sooner than expected.
2025-01-09[lldb][AIX] Some base #if _AIX changes of a minimal lldb build (#120979)Dhruv Srivastava
This PR is in reference to porting LLDB on AIX. Link to discussions on llvm discourse and github: 1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640 2. https://github.com/llvm/llvm-project/issues/101657 The complete changes for porting are present in this draft PR: https://github.com/llvm/llvm-project/pull/102601 Added some base #if _AIX changes for minimal lldb build. Added a PR for clang-format changes separately, to rebase this on later: - https://github.com/llvm/llvm-project/pull/120978 Review Request: @labath @DavidSpickett
2024-12-27[lldb] clang-format changes for some basic #if _AIX changes (#120978)Dhruv Srivastava
This PR is in reference to porting LLDB on AIX. Link to discussions on llvm discourse and github: 1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640 2. https://github.com/llvm/llvm-project/issues/101657 The complete changes for porting are present in this draft PR: https://github.com/llvm/llvm-project/pull/102601 Added clang-format changes for changes related to some base #if _AIX changes: - https://github.com/llvm/llvm-project/pull/120979
2024-11-28[lldb] Remove child_process_inherit from the socket classes (#117699)Pavel Labath
It's never set to true. Also, using inheritable FDs in a multithreaded process pretty much guarantees descriptor leaks. It's better to explicitly pass a specific FD to a specific subprocess, which we already mostly can do using the ProcessLaunchInfo FileActions.
2024-11-27[lldb] Add timeout argument to Socket::Accept (#117691)Pavel Labath
Allows us to stop waiting for a connection if it doesn't come in a certain amount of time. Right now, I'm keeping the status quo (infitnite wait) in the "production" code, but using smaller (finite) values in tests. (A lot of these tests create "loopback" connections, where a really short wait is sufficient: on linux at least even a poll (0s wait) is sufficient if the other end has connect()ed already, but this doesn't seem to be the case on Windows, so I'm using a 1s wait in these cases).
2024-11-13[lldb] Remove ConnectionFileDescriptor::child_process_inherit (#115861)Pavel Labath
It's never set to true. Inheritable FDs are also dangerous as they can end up processes which know nothing about them. It's better to explicitly pass a specific FD to a specific subprocess, which we already mostly can do using the ProcessLaunchInfo FileActions.
2024-09-05[lldb] Make deep copies of Status explicit (NFC) (#107170)Adrian Prantl
2024-09-05[lldb] Make conversions from llvm::Error explicit with Status::FromEr… ↵Adrian Prantl
(#107163) …ror() [NFC]
2024-08-27[lldb] Turn lldb_private::Status into a value type. (#106163)Adrian Prantl
This patch removes all of the Set.* methods from Status. This cleanup is part of a series of patches that make it harder use the anti-pattern of keeping a long-lives Status object around and updating it while dropping any errors it contains on the floor. This patch is largely NFC, the more interesting next steps this enables is to: 1. remove Status.Clear() 2. assert that Status::operator=() never overwrites an error 3. remove Status::operator=() Note that step (2) will bring 90% of the benefits for users, and step (3) will dramatically clean up the error handling code in various places. In the end my goal is to convert all APIs that are of the form ` ResultTy DoFoo(Status& error) ` to ` llvm::Expected<ResultTy> DoFoo() ` How to read this patch? The interesting changes are in Status.h and Status.cpp, all other changes are mostly ` perl -pi -e 's/\.SetErrorString/ = Status::FromErrorString/g' $(git grep -l SetErrorString lldb/source) ` plus the occasional manual cleanup.
2023-11-03[lldb][NFC] Use UNUSED_IF_ASSERT_DISABLED instead of (void) castDavid Spickett
Uses of (void) remain where they are for purposes other than an assert variable.
2023-08-07Revert "[lldb] Fix data race in ConnectionFileDescriptor"Jonas Devlieghere
This reverts commit 0bdbe7bd7f1589817495a60cc8422df49575b17b because it broke the bots.
2023-08-07[lldb] Fix data race in ConnectionFileDescriptorJonas Devlieghere
TSan reports the following data race: Write of size 4 at 0x000109e0b160 by thread T2 (mutexes: write M0, write M1): #0 NativeFile::Close() File.cpp:329 #1 ConnectionFileDescriptor::Disconnect(lldb_private::Status*) ConnectionFileDescriptorPosix.cpp:232 #2 Communication::Disconnect(lldb_private::Status*) Communication.cpp:61 #3 process_gdb_remote::ProcessGDBRemote::DidExit() ProcessGDBRemote.cpp:1164 #4 Process::SetExitStatus(int, char const*) Process.cpp:1097 #5 process_gdb_remote::ProcessGDBRemote::MonitorDebugserverProcess(...) ProcessGDBRemote.cpp:3387 Previous read of size 4 at 0x000109e0b160 by main thread (mutexes: write M2): #0 NativeFile::IsValid() const File.h:393 #1 ConnectionFileDescriptor::IsConnected() const ConnectionFileDescriptorPosix.cpp:121 #2 Communication::IsConnected() const Communication.cpp:79 #3 process_gdb_remote::GDBRemoteCommunication::WaitForPacketNoLock(...) GDBRemoteCommunication.cpp:256 #4 process_gdb_remote::GDBRemoteCommunication::WaitForPacketNoLock(...l) GDBRemoteCommunication.cpp:244 #5 process_gdb_remote::GDBRemoteClientBase::SendPacketAndWaitForResponseNoLock(llvm::StringRef, StringExtractorGDBRemote&) GDBRemoteClientBase.cpp:246 The problem is that in WaitForPacketNoLock's run loop, it checks that the connection is still connected. This races with the ConnectionFileDescriptor disconnecting. Most (but not all) access to the IOObject in ConnectionFileDescriptorPosix is already gated by the mutex. This patch just protects IsConnected in the same way. Differential revision: https://reviews.llvm.org/D157347
2023-08-07[lldb] Remove unused Socket::PreDisconnect (NFC)Jonas Devlieghere
2023-06-15[lldb][Android] Use a lambda for calls to ::open in RetryAfterSignalKazuki Sakamoto
lldb-server for Android does not build with NDK r21 and above due to RetryAfterSignal and Bionic ::open mismatch. https://github.com/llvm/llvm-project/issues/54727 Apply the LLVM patch to LLDB. https://github.com/llvm/llvm-project/commit/0a0e411204a2baa520fd73a8d69b664f98b428ba > In Bionic, open can be overloaded for _FORTIFY_SOURCE support, causing > compile errors of RetryAfterSignal due to overload resolution. Wrapping > the call in a lambda avoids this. Differential Revision: https://reviews.llvm.org/D152712
2022-04-28[lldb] Fix crash when launching in terminalJonas Devlieghere
This patch fixes a crash when using process launch -t to launch the inferior from a TTY. The issue is that on Darwin, Host.mm is calling ConnectionFileDescriptor::Connect without a socket_id_callback_type. The overload passes nullptr as the function ref, which gets called unconditionally as the socket_id_callback. One potential way to fix this is to change all the lambdas to include a null check, but instead I went with an empty lambda. Differential revision: https://reviews.llvm.org/D124535
2022-02-03[lldb] Rename Logging.h to LLDBLog.h and clean up includesPavel Labath
Most of our code was including Log.h even though that is not where the "lldb" log channel is defined (Log.h defines the generic logging infrastructure). This worked because Log.h included Logging.h, even though it should. After the recent refactor, it became impossible the two files include each other in this direction (the opposite inclusion is needed), so this patch removes the workaround that was put in place and cleans up all files to include the right thing. It also renames the file to LLDBLog to better reflect its purpose.
2022-02-02[lldb] Convert "LLDB" log channel to the new APIPavel Labath
2021-10-28[lldb] [Host/ConnectionFileDescriptor] Refactor to improve code reuseMichał Górny
Refactor ConnectionFileDescriptor to improve code reuse for different types of sockets. Unify method naming. While at it, remove some (now-)dead code from Socket. Differential Revision: https://reviews.llvm.org/D112495
2021-10-27Revert "[lldb] [Host/ConnectionFileDescriptor] Refactor to improve code reuse"Med Ismail Bennani
This reverts commit e1acadb61dfc0810656219c6314019d5132f2c61.
2021-10-27[lldb] [Host/ConnectionFileDescriptor] Refactor to improve code reuseMichał Górny
Refactor ConnectionFileDescriptor to improve code reuse for different types of sockets. Unify method naming. While at it, remove some (now-)dead code from Socket. Differential Revision: https://reviews.llvm.org/D112495
2021-10-26[lldb] [Host] Move port predicate-related logic to gdb-remoteMichał Górny
Remove the port predicate from Socket and ConnectionFileDescriptor, and move it to gdb-remote. It is specifically relevant to the threading used inside gdb-remote and with the new port callback API, we can reliably move it there. While at it, switch from the custom Predicate to std::promise/std::future. Differential Revision: https://reviews.llvm.org/D112357
2021-10-26[lldb] [lldb-gdbserver] Unify listen/connect code to use ↵Michał Górny
ConnectionFileDescriptor Unify the listen and connect code inside lldb-server to use ConnectionFileDescriptor uniformly rather than a mix of it and Acceptor. This involves: - adding a function to map legacy values of host:port parameter (including legacy server URLs) into CFD-style URLs - adding a callback to return "local socket id" (i.e. UNIX socket path or TCP port number) between listen() and accept() calls in CFD - adding a "unix-abstract-accept" scheme to CFD As an additional advantage, this permits lldb-server to accept any URL known to CFD including the new serial:// scheme. Effectively, lldb-server can now listen on the serial port. Tests for connecting over a pty are added to test that. Differential Revision: https://reviews.llvm.org/D111964
2021-10-25[lldb] [Host/ConnectionFileDescriptor] Do not use non-blocking modeMichał Górny
Disable non-blocking mode that's enabled only for file:// and serial:// protocols. All read operations should be going through the select(2) in ConnectionFileDescriptor::BytesAvaliable, which effectively erases (non-)blocking mode differences in reading. We do want to perform writes in the blocking mode. Differential Revision: https://reviews.llvm.org/D112442
2021-10-21[lldb] Add serial:// protocol for connecting to serial portMichał Górny
Add a new serial:// protocol along with SerialPort that provides a new API to open serial ports. The URL consists of serial device path followed by URL-style options, e.g.: serial:///dev/ttyS0?baud=115200&parity=even If no options are provided, the serial port is only set to raw mode and the other attributes remain unchanged. Attributes provided via options are modified to the specified values. Upon closing the serial port, its original attributes are restored. Differential Revision: https://reviews.llvm.org/D111355
2021-10-11[lldb] [ConnectionFileDescriptorPosix] Combine m_read_sp & m_write_spMichał Górny
Combine m_read_sp and m_write_sp into a single m_io_sp. In all currently existing code paths, they are pointing to the same object anyway. Differential Revision: https://reviews.llvm.org/D111396
2021-10-08[lldb] [ConnectionFileDescriptorPosix] Refactor scheme matchingMichał Górny
Move the POSIX-specific fd:// and file:// scheme handling into separate methods. Replace the custom GetURLAddress() matching with splitting into scheme and path, and matching scheme via llvm::StringSwitch. Use early returns. Differential Revision: https://reviews.llvm.org/D111321
2021-10-08[lldb] [ConnectionFileDescriptorPosix] Use a single NativeFileMichał Górny
Replace separate read and write NativeFile instances with a single instance shared for reading and writing. There is no clear indication why two instances were used in the first place, and replacing them with just one does not seem to cause any regressions in tests or manual 'process connect file://...'. Differential Revision: https://reviews.llvm.org/D111314
2021-10-05[lldb] Remove some anonymous namespacesPavel Labath
.. and reduce the scope of others. They don't follow llvm coding standards (which say they should be used only when the same effect cannot be achieved with the static keyword), and they set a bad example.
2021-08-09[lldb] [gdb-remote] Add eOpenOptionReadWrite for future gdb compatMichał Górny
Modify OpenOptions enum to open the future path into synchronizing vFile:open bits with GDB. Currently, LLDB and GDB use different flag models effectively making it impossible to match bits. Notably, LLDB uses two bits to indicate read and write status, and uses union of both for read/write. GDB uses a value of 0 for read-only, 1 for write-only and 2 for read/write. In order to future-proof the code for the GDB variant: 1. Add a distinct eOpenOptionReadWrite constant to be used instead of (eOpenOptionRead | eOpenOptionWrite) when R/W access is required. 2. Rename eOpenOptionRead and eOpenOptionWrite to eOpenOptionReadOnly and eOpenOptionWriteOnly respectively, to make it clear that they do not mean to be combined and require update to all call sites. 3. Use the intersection of all three flags when matching against the three possible values. This commit does not change the actual bits used by LLDB. Differential Revision: https://reviews.llvm.org/D106984
2021-06-09[lldb] Use C++11 default member initializersJonas Devlieghere
This converts a default constructor's member initializers into C++11 default member initializers. This patch was automatically generated with clang-tidy and the modernize-use-default-member-init check. $ run-clang-tidy.py -header-filter='lldb' -checks='-*,modernize-use-default-member-init' -fix This is a mass-refactoring patch and this commit will be added to .git-blame-ignore-revs. Differential revision: https://reviews.llvm.org/D103483
2021-05-26[lldb][NFC] Use C++ versions of the deprecated C standard library headersRaphael Isemann
The C headers are deprecated so as requested in D102845, this is replacing them all with their (not deprecated) C++ equivalent. Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D103084
2020-06-24[lldb] Use std::make_unique<> (NFC)Jonas Devlieghere
Update the rest of lldb to use std::make_unique<>. I used clang-tidy to automate this, which probably missed cases that are wrapped in ifdefs.
2020-04-23[lldb/Host] Modernize some socket functionsPavel Labath
return Expected<Socket> instead of a Status object plus a Socket*& argument.
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-24[lldb][NFC] Fix all formatting errors in .cpp file headersRaphael Isemann
Summary: A *.cpp file header in LLDB (and in LLDB) should like this: ``` //===-- TestUtilities.cpp -------------------------------------------------===// ``` However in LLDB most of our source files have arbitrary changes to this format and these changes are spreading through LLDB as folks usually just use the existing source files as templates for their new files (most notably the unnecessary editor language indicator `-*- C++ -*-` is spreading and in every review someone is pointing out that this is wrong, resulting in people pointing out that this is done in the same way in other files). This patch removes most of these inconsistencies including the editor language indicators, all the different missing/additional '-' characters, files that center the file name, missing trailing `===//` (mostly caused by clang-format breaking the line). Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere Reviewed By: JDevlieghere Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D73258
2019-12-13[lldb/Host] Use cmakedefine01 for LLDB_ENABLE_POSIXJonas Devlieghere
Rename LLDB_DISABLE_POSIX to LLDB_ENABLE_POSIX and use cmakedefine01 for consistency.
2019-10-03factor out an abstract base class for FileLawrence D'Anna
Summary: This patch factors out File as an abstract base class and moves most of its actual functionality into a subclass called NativeFile. In the next patch, I'm going to be adding subclasses of File that don't necessarily have any connection to actual OS files, so they will not inherit from NativeFile. This patch was split out as a prerequisite for https://reviews.llvm.org/D68188 Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68317 llvm-svn: 373564
2019-09-23File::SetDescriptor() should require optionsJonas Devlieghere
lvm_private::File::GetStream() can fail if m_options == 0 It's not clear from the header a File created with a descriptor will be not be usable by many parts of LLDB unless SetOptions is also called, but it is. This is because those parts of LLDB rely on GetStream() to use the file, and that in turn relies on calling fdopen on the descriptor. When calling fdopen, GetStream relies on m_options to determine the access mode. If m_options has never been set, GetStream() will fail. This patch adds options as a required argument to File::SetDescriptor and the corresponding constructor. Patch by: Lawrence D'Anna Differential revision: https://reviews.llvm.org/D67792 llvm-svn: 372652
2019-09-23[LLDB] Check for _WIN32 instead of _MSC_VER for code specific to windows in ↵Martin Storsjo
general These ifdefs contain code that isn't specific to MSVC but useful for any windows target, like MinGW. Differential Revision: https://reviews.llvm.org/D67893 llvm-svn: 372592
2019-08-27[ConnectionFileDescriptor] Add shutdown check in ::Write.Jonas Devlieghere
The disconnect method sets the shutdown flag to true. This currently only prevents any reads from happening, but not writes, which is incorrect. Presumably this was just an oversight when adding synchronization to the class. This adds the same shutdown check to the Write method. Over-the-shoulder reviewed by Jim! llvm-svn: 370002
2019-07-24[Logging] Replace Log::Printf with LLDB_LOG macro (NFC)Jonas Devlieghere
This patch replaces explicit calls to log::Printf with the new LLDB_LOGF macro. The macro is similar to LLDB_LOG but supports printf-style format strings, instead of formatv-style format strings. So instead of writing: if (log) log->Printf("%s\n", str); You'd write: LLDB_LOG(log, "%s\n", str); This change was done mechanically with the command below. I replaced the spurious if-checks with vim, since I know how to do multi-line replacements with it. find . -type f -name '*.cpp' -exec \ sed -i '' -E 's/log->Printf\(/LLDB_LOGF\(log, /g' "{}" + Differential revision: https://reviews.llvm.org/D65128 llvm-svn: 366936
2019-05-30Make ConnectionFileDescription work with all socketsAntonio Afonso
Summary: My main goal here is to make lldb-server work with Android Studio. This is currently not the case because lldb-server is started in platform mode listening on a domain socket. When Android Studio connects to it lldb-server crashes because even though it's listening on a domain socket as soon as it gets a connection it asserts that it's a TCP connection, which will obviously fails for any non-tcp connection. To do this I came up with a new method called GetConnectURI() in Socket that returns the URI needed to connect to the connected portion of the socket. Reviewers: labath, clayborg, xiaobai Reviewed By: labath Subscribers: mgorny, jfb, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D62089 llvm-svn: 362173
2019-05-28Fix IPv6 support on lldb-server platformAntonio Afonso
Summary: This is a general fix for the ConnectionFileDescriptor class but my main motivation was to make lldb-server working with IPv6. The connect URI can use square brackets ([]) to wrap the interface part of the URI (e.g.: <scheme>://[<interface>]:<port>). For IPv6 addresses this is a must since its ip can include colons and it will overlap with the port colon otherwise. The URIParser class parses the square brackets correctly but the ConnectionFileDescriptor doesn't generate them for IPv6 addresses making it impossible to connect to the gdb server when using this protocol. How to reproduce the issue: ``` $ lldb-server p --server --listen [::1]:8080 ... $ lldb (lldb) platform select remote-macosx (lldb) platform connect connect://[::1]:8080 (lldb) platform process -p <pid> error: unable to launch a GDB server on 'computer' ``` The server was actually launched we were just not able to connect to it. With this fix lldb will correctly connect. I fixed this by wrapping the ip portion with []. Reviewers: labath Reviewed By: labath Subscribers: xiaobai, mgorny, jfb, lldb-commits, labath Tags: #lldb Differential Revision: https://reviews.llvm.org/D61833 llvm-svn: 361898