summaryrefslogtreecommitdiff
path: root/lldb/source/Host/common/Socket.cpp
AgeCommit message (Collapse)Author
2025-10-25[ADT] Deprecate StringSwitch Cases with 3+ args. NFC. (#165119)Jakub Kuderski
Suggest the `initializer_list` overload instead. 3+ args is an arbitrary number that allows for incremental depreciation without having to update too many call sites. For more context, see https://github.com/llvm/llvm-project/pull/163117.
2025-09-16[lldb-mcp] Launch lldb on demand, if needed. (#158701)John Harrison
Adding support for launching lldb with `-O protocol start MCP` if a valid ~/.lldb/lldb-mcp-*.json` file is not found. --------- Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
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-23[lldb] Add Socket::CreatePair (#145015)Pavel Labath
It creates a pair of connected sockets using the simplest mechanism for the given platform (TCP on windows, socketpair(2) elsewhere). Main motivation is to remove the ugly platform-specific code in ProcessGDBRemote::LaunchAndConnectToDebugserver, but it can also be used in other places where we need to create a pair of connected sockets.
2025-06-19[lldb-dap] Make connection URLs match lldb (#144770)Jonas Devlieghere
Use the same scheme as ConnectionFileDescriptor::Connect and use "listen" and "accept". Addresses feedback from a Pavel in a different PR [1]. [1] https://github.com/llvm/llvm-project/pull/143628#discussion_r2152225200
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-27[lldb] Clean up Socket headers for Android (#124453)Brad Smith
2025-01-23[lldb] Remove support and workarounds for Android 4 and older (#124047)Brad Smith
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-09-13[lldb] Add a MainLoop version of DomainSocket::Accept (#108188)Pavel Labath
To go along with the existing TCPSocket implementation.
2024-09-04[lldb][NFC] Move few static helpers to the class Socket (#106640)Dmitry Vasilyev
Fixed a typo in Socket::SetOption().
2024-08-27[lldb] Update Host/windows to new Status APIAdrian Prantl
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.
2024-08-26[lldb][NFC] Moved the SharedSocket class to Socket.* (#104787)Dmitry Vasilyev
This is the prerequisite for #104238.
2024-08-16[lldb][NFC] Moved FindSchemeByProtocol() from Acceptor to Socket (#104439)Dmitry Vasilyev
This is the prerequisite for #104238.
2024-05-23Add a createError variant without error code (NFC) (#93209)Adrian Prantl
For the significant amount of call sites that want to create an incontrovertible error, such a wrapper function creates a significant readability improvement and lowers the cost of entry to add error handling in more places.
2023-08-07[lldb] Remove unused Socket::PreDisconnect (NFC)Jonas Devlieghere
2023-07-08Add missing StringExtras.h includesElliot Goodrich
In preparation for removing the `#include "llvm/ADT/StringExtras.h"` from the header to source file of `llvm/Support/Error.h`, first add in all the missing includes that were previously included transitively through this header. This is fixing all files missed in b0abd4893fa1 and 39d8e6e22cd1. Differential Revision: https://reviews.llvm.org/D154763
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
2022-01-21[llvm] Cleanup header dependencies in ADT and Supportserge-sans-paille
The cleanup was manual, but assisted by "include-what-you-use". It consists in 1. Removing unused forward declaration. No impact expected. 2. Removing unused headers in .cpp files. No impact expected. 3. Removing unused headers in .h files. This removes implicit dependencies and is generally considered a good thing, but this may break downstream builds. I've updated llvm, clang, lld, lldb and mlir deps, and included a list of the modification in the second part of the commit. 4. Replacing header inclusion by forward declaration. This has the same impact as 3. Notable changes: - llvm/Support/TargetParser.h no longer includes llvm/Support/AArch64TargetParser.h nor llvm/Support/ARMTargetParser.h - llvm/Support/TypeSize.h no longer includes llvm/Support/WithColor.h - llvm/Support/YAMLTraits.h no longer includes llvm/Support/Regex.h - llvm/ADT/SmallVector.h no longer includes llvm/Support/MemAlloc.h nor llvm/Support/ErrorHandling.h You may need to add some of these headers in your compilation units, if needs be. As an hint to the impact of the cleanup, running clang++ -E -Iinclude -I../llvm/include ../llvm/lib/Support/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l before: 8000919 lines after: 7917500 lines Reduced dependencies also helps incremental rebuilds and is more ccache friendly, something not shown by the above metric :-) Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2022-01-07[LLDB] Fix setting of success in Socket::Close()Shafik Yaghmour
Both close and closesocket should return 0 on success so using !! looks incorrect. I replaced this will a more readable == 0 check. Differential Revision: https://reviews.llvm.org/D116768
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-28[lldb] [Host/Socket] Make DecodeHostAndPort() return a dedicated structMichał Górny
Differential Revision: https://reviews.llvm.org/D112629
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-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-09-24[lldb] [Host] Refactor Socket::DecodeHostAndPort() to use LLVM APIMichał Górny
Refactor Socket::DecodeHostAndPort() to use LLVM API over redundant LLDB API. In particular, this means llvm::Regex, llvm::Error return type and llvm::to_integer(). While at it, change the port type from int32_t to uint16_t. The method never returns any value outside this range, and using the correct type allows us to rely on getAsInteger()'s implicit overflow check. Differential Revision: https://reviews.llvm.org/D110391
2021-09-24Revert "[lldb] [Host] Refactor Socket::DecodeHostAndPort() to use LLVM API"Michał Górny
This reverts commit a6daf99228bc16fb7f2596d67a0d00fef327ace5. It causes buildbot regressions, I'll investigate.
2021-09-24[lldb] [Host] Refactor Socket::DecodeHostAndPort() to use LLVM APIMichał Górny
Refactor Socket::DecodeHostAndPort() to use LLVM API over redundant LLDB API. In particular, this means llvm::Regex, llvm::Error return type and llvm::to_integer(). While at it, change the port type from int32_t to uint16_t. The method never returns any value outside this range, and using the correct type allows us to rely on getAsInteger()'s implicit overflow check. Differential Revision: https://reviews.llvm.org/D110391
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-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-09-27refactor: move IOObject::m_should_close_fd into subclassesLawrence D'Anna
Summary: m_should_close_fd doesn't need to be in IOObject. It will be useful for my next change to move it down into File and Socket. Reviewers: labath, JDevlieghere, jasonmolenda Reviewed By: JDevlieghere Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68152 llvm-svn: 373126
2019-09-21[LLDB] Cast -1 (as invalid socket) to the socket type before comparingMartin Storsjo
This silences warnings about comparison of integers between unsigned long long (which is what the Windows SOCKET type is) and signed int when building in MinGW mode. Differential Revision: https://reviews.llvm.org/D67863 llvm-svn: 372486
2019-09-04[lldb] Fix log statement in Socket::WriteRaphael Isemann
We change num_bytes in this method, so this doesn't actually log the parameter that we called the function with. No test as we don't test logging code. llvm-svn: 370887
2019-08-16[Utility] Reimplement RegularExpression on top of llvm::RegexJonas Devlieghere
Originally I wanted to remove the RegularExpression class in Utility and replace it with llvm::Regex. However, during that transition I noticed that there are several places where need the regular expression string. So instead I propose to keep the RegularExpression class and make it a thin wrapper around llvm::Regex. This patch also removes the workaround for empty regular expressions. The result is that we are now (more or less) POSIX conformant. Differential revision: https://reviews.llvm.org/D66174 llvm-svn: 369153
2019-08-14[LLDB] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368933
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-21Fix LLDB warnings when compiling with Clang 8.0Alexandre Ganea
Differential Revision: https://reviews.llvm.org/D62021 llvm-svn: 361295
2019-04-10[lldb-server] Introduce Socket::Initialize and Terminate to simply WSASocket ↵Aaron Smith
setup Reviewers: zturner, labath Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D60440 llvm-svn: 358044
2019-04-08Fix a stack buffer overflow found by ASAN.Adrian Prantl
llvm::StringRef host_and_port is not guaranteed to be null-terminated. Generally, it is not safe at all to convert a StringRef into a char * by calling data() on it. <rdar://problem/49698580> llvm-svn: 357948
2019-03-21[lldb] Add missing EINTR handlingMichal Gorny
Differential Revision: https://reviews.llvm.org/D59606 llvm-svn: 356703
2019-03-11Fix invalid use of StringRef::data in Socket::DecodeHostAndPortPavel Labath
the input StringRef is not guaranteed to be null-terminated, so using data to get the c string is wrong. Luckily, in two of the usages the target function already accepts a StringRef so we can just drop the data() call, and the third one is easily replaced by a stringref-aware function. Issue found by msan. llvm-svn: 355817
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636