aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-06-27[lldb] Extract debug server location code (#145706)Pavel Labath1-76/+1
.. from the guts of GDBRemoteCommunication to ~top level. This is motivated by #131519 and by the fact that's impossible to guess whether the author of a symlink intended it to be a "convenience shortcut" -- meaning it should be resolved before looking for related files; or an "implementation detail" -- meaning the related files should be located near the symlink itself. This debate is particularly ridiculous when it comes to lldb-server running in platform mode, because it also functions as a debug server, so what we really just need to do is to pass /proc/self/exe in a platform-independent manner. Moving the location logic higher up achieves that as lldb-platform (on non-macos) can pass `HostInfo::GetProgramFileSpec`, while liblldb can use the existing complex logic (which only worked on liblldb anyway as lldb-platform doesn't have a lldb_private::Platform instance). Another benefit of this patch is a reduction in dependency from GDBRemoteCommunication to the rest of liblldb (achieved by avoiding the Platform dependency).
2025-06-26[lldb] Remove child_process_inherit argument from Pipe (#145516)Pavel Labath1-4/+4
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-25[lldb] Fix qEcho message handling. (#145675)eleviant1-1/+2
This fixes issues found in e066f35c6981c720e3a7e5883efc40c861b3b7, which was later reverted. The problem was with "k" message which was sent with sync_on_timeout flag set to true, so lldb was waiting for response, which is currently not being sent by lldb-server. Not waiting for response at all seems to be not a solution, because on MAC OS X lldb waits for response from "k" to gracefully kill inferior.
2025-06-25[lldb] Clean up GDBRemoteCommunication::StartDebugserverProcess (#145021)Pavel Labath1-113/+56
The function was extremely messy in that it, depending on the set of arguments, it could either modify the Connection object in `this` or not. It had a lot of arguments, with each call site passing a different combination of null values. This PR: - packs "url" and "comm_fd" arguments into a variant as they are mutually exclusive - removes the (surprising) "null url *and* null comm_fd" code path which is not used as of https://github.com/llvm/llvm-project/pull/145017 - marks the function as `static` to make it clear it (now) does not operate on the `this` object. Depends on #145017
2025-06-24[lldb] Remove GDBRemoteCommunication::ConnectLocally (#145293)Pavel Labath1-16/+2
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-06-23[lldb] Add Socket::CreatePair (#145015)Pavel Labath1-26/+6
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-22Revert "[lldb] Fix qEcho message handling (#145072)" (#145241)eleviant1-2/+1
Temporarily revert commit e066f35c6981c720e3a7e5883efc40c861b3b7ee, because lldb tests randomly hang after it's been pushed.
2025-06-21[lldb] Fix qEcho message handling (#145072)eleviant1-1/+2
Patch fixes the sync-on-timeout logic in lldb and switches to qEcho based ping, instead of qC. This fixes vRun message case, when there is no process yet and qC returns an error.
2025-05-13[lldb] Fix compilation errors from #138896 (#139711)Pavel Labath1-1/+2
- s/size_t/SIZE_T to match the windows API - case HANDLE to int64_t to avoid cast-to-int-of-different-size errors/warnings
2025-05-12Reapply "[lldb] Inherit DuplicateFileAction(HANDLE, HANDLE) handles on ↵Pavel Labath1-2/+0
windows (#137978)" (#138896) This reverts commit https://github.com/llvm/llvm-project/commit/a0260a95ece74733ada00b19d8b1930dde462a66, reapplying https://github.com/llvm/llvm-project/commit/7c5f5f3ef83b1d1d43d63862a8431af3dded15bb, with a fix that makes *both* pipe handles inheritable. The original commit description was: This is a follow-up to https://github.com/llvm/llvm-project/pull/126935, which enables passing handles to a child process on windows systems. Unlike on unix-like systems, the handles need to be created with the "inheritable" flag because there's to way to change the flag value after it has been created. This is why I don't respect the child_process_inherit flag but rather always set the flag to true. (My next step is to delete the flag entirely.) This does mean that pipe may be created as inheritable even if its not necessary, but I think this is offset by the fact that windows (unlike unixes, which pass all ~O_CLOEXEC descriptors through execve and *all* descriptors through fork) has a way to specify the precise set of handles to pass to a specific child process. If this turns out to be insufficient, instead of a constructor flag, I'd rather go with creating a separate api to create an inheritable copy of a handle (as typically, you only want to inherit one end of the pipe).
2025-05-07Revert "[lldb] Inherit DuplicateFileAction(HANDLE, HANDLE) handles on ↵Pavel Labath1-0/+2
windows (#137978)" This reverts commit 7c5f5f3ef83b1d1d43d63862a8431af3dded15bb due to failures on the lldb-remote-linux-win bot.
2025-05-07[lldb] Inherit DuplicateFileAction(HANDLE, HANDLE) handles on windows (#137978)Pavel Labath1-2/+0
This is a follow-up to https://github.com/llvm/llvm-project/pull/126935, which enables passing handles to a child process on windows systems. Unlike on unix-like systems, the handles need to be created with the "inheritable" flag because there's to way to change the flag value after it has been created. This is why I don't respect the child_process_inherit flag but rather always set the flag to true. (My next step is to delete the flag entirely.) This does mean that pipe may be created as inheritable even if its not necessary, but I think this is offset by the fact that windows (unlike unixes, which pass all ~O_CLOEXEC descriptors through execve and *all* descriptors through fork) has a way to specify the precise set of handles to pass to a specific child process. If this turns out to be insufficient, instead of a constructor flag, I'd rather go with creating a separate api to create an inheritable copy of a handle (as typically, you only want to inherit one end of the pipe).
2025-05-04[lldb] Remove unused local variables (NFC) (#138457)Kazu Hirata1-1/+0
2025-04-22[lldb] Clean up StartDebugserverProcess before I start refactoring it (#135342)Pavel Labath1-282/+199
- use early exits where possible - avoid the listen thread by using Socket APIs which allow separate "listen" and "accept" steps - use formatv-like log statements There "should" be no functional changes from this patch.
2025-04-22[lldb/cmake] Normalize use of HAVE_LIBCOMPRESSION (#135528)Pavel Labath1-3/+3
I *think* this was the reason behind the failures in 2fd860c1f559c0b0be66cc000e38270a04d0a1a3: the clang include tool showed the Config.h headers as unused, and because the macro was referenced through an `#ifdef`, its removal didn't cause build failures. Switching to `#cmakedefine01` + `#if` should make sure this does not happen again. According to D48977, the `#ifndef`+`#cmakedefine` patterns is due to some files redefining the macro themselves. I no longer see any such files in the source tree (there also were no files like that in the source tree at the revision mentioned, but the macro *was* defined in the hand-maintained XCode project we had at the time).
2025-04-13Reapply "[lldb] ProcessGdbRemote header gardning"Pavel Labath1-10/+5
This reverts commit 68ab45f0533f3bbfc1c96bddd53de7e769180219, reapplying 2fd860c1f559c0b0be66cc000e38270a04d0a1a3. The only change is keeping "lldb/Host/Config.h", which I believe was the cause of the failures.
2025-04-11Revert "[lldb] ProcessGdbRemote header gardning"Jonas Devlieghere1-5/+11
This reverts commit 2fd860c1f559c0b0be66cc000e38270a04d0a1a3 as this is causing a EXC_BAD_ACCESS on Darwin: https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/23807/ https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake/11255/
2025-04-11[lldb] ProcessGdbRemote header gardningPavel Labath1-11/+5
Remove unused headers, add used headers, remove declared-but-not-defined entities.
2025-03-19[lldb/gdb-remote] Do not crash on an invalid server response (#131979)Igor Kudrin1-5/+17
An invalid RLE sequence in the received packet could result in an out-of-bounds reading that could cause a crash.
2025-02-27[lldb] Assorted improvements to the Pipe class (#128719)Pavel Labath1-7/+17
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.
2024-11-28[lldb] Remove child_process_inherit from the socket classes (#117699)Pavel Labath1-2/+1
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 Labath1-7/+8
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-09[NFC] Add explicit #include llvm-config.h where its macros are used, lldb ↵Daniil Fukalov1-0/+1
part. (#107603) (this is lldb part) Without these explicit includes, removing other headers, who implicitly include llvm-config.h, may have non-trivial side effects. For example, `clangd` may report even `llvm-config.h` as "no used" in case it defines a macro, that is explicitly used with #ifdef. It is actually amplified with different build configs which use different set of macros.
2024-09-06[lldb][NFC] Used shared_fd_t (#107553)Dmitry Vasilyev1-8/+11
Replaced `int connection_fd = -1` with `shared_fd_t connection_fd = SharedSocket::kInvalidFD`. This is prerequisite for #104238.
2024-09-06[lldb] Fixed a typo in #107388Dmitry Vasilyev1-1/+1
2024-09-06[lldb][NFC] Fix -Wparentheses warning.Christian Sigg1-1/+1
Fix `using the result of an assignment as a condition without parentheses` warning.
2024-09-06[lldb][NFC] Separated GDBRemoteCommunication::GetDebugserverPath() (#107388)Dmitry Vasilyev1-12/+17
This is the prerequisite for #104238.
2024-09-05[lldb] Make conversions from llvm::Error explicit with Status::FromEr… ↵Adrian Prantl1-1/+1
(#107163) …ror() [NFC]
2024-08-27[lldb] Turn lldb_private::Status into a value type. (#106163)Adrian Prantl1-4/+4
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-07-26[lldb] Optimized lldb-server memory usage (#100666)Dmitry Vasilyev1-2/+2
MAX_PATH is definitely larger than 6 bytes we are expecting for this message, and could be rather large depending on the target OS (4K for some Linux OSs). Since the buffer gets allocated on the stack we better be conservative and allocate what we actually need.
2024-06-10[lldb] Fix redundant condition in compression type check (NFC) (#94841)Shivam Gupta1-3/+2
The `else if` condition for checking `m_compression_type` is redundant as it matches with a previous `if` condition, making the expression always false. Reported by cppcheck as a possible cut-and-paste error. Caught by cppcheck - lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp:543:35: style: Expression is always false because 'else if' condition matches previous condition at line 535. [multiCondition] Fix #91222
2023-08-09[lldb] Sink StreamFile into lldbHostAlex Langford1-1/+0
StreamFile subclasses Stream (from lldbUtility) and is backed by a File (from lldbHost). It does not depend on anything from lldbCore or any of its sibling libraries, so I think it makes sense for this to live in lldbHost instead. Differential Revision: https://reviews.llvm.org/D157460
2022-12-19Revert "[lldb] Remove redundant .c_str() and .get() calls"Muhammad Omair Javaid1-1/+1
This reverts commit fbaf48be0ff6fb24b9aa8fe9c2284fe88a8798dd. This has broken all LLDB buildbots: https://lab.llvm.org/buildbot/#/builders/68/builds/44990 https://lab.llvm.org/buildbot/#/builders/96/builds/33160
2022-12-18[lldb] Remove redundant .c_str() and .get() callsFangrui Song1-1/+1
Removing .c_str() has a semantics difference, but the use scenarios likely do not matter as we don't have NUL in the strings.
2022-10-03[lldb] [gdb-remote] Move ReadPacketWithOutputSupport() to clientMichał Górny1-17/+0
Move ReadPacketWithOutputSupport() from GDBRemoteCommunication to GDBRemoteClientBase. This function is client-specific and moving it there simplifies followup patches that split communication into separate thread. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D135028
2022-09-20[LLDB]Initialize accept_socket with nullptrGeorge Hu1-1/+1
Fix high impact issue of illegal access of memory. Initialize accept_socket with nullptr. Differential Revision: https://reviews.llvm.org/D134293
2022-09-19[lldb] Remove LLDB reproducersJonas Devlieghere1-6/+0
This patch removes the remaining reproducer code. The SBReproducer class remains for ABI stability but is just an empty shell. This completes the removal process outlined on the mailing list [1]. [1] https://lists.llvm.org/pipermail/lldb-dev/2021-September/017045.html
2022-09-09[gdb-remote] Move broadcasting logic down to GDBRemoteClientBaseMichał Górny1-3/+2
Move the broadcasting support from GDBRemoteCommunication to GDBRemoteClientBase since this is where it is actually used. Remove GDBRemoteCommunication and subclass constructor arguments left over after Communication cleanup. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D133427
2022-09-06[lldb] [Core] Split read thread support into ThreadedCommunicationMichał Górny1-1/+1
Split the read thread support from Communication into a dedicated ThreadedCommunication subclass. The read thread support is used only by a subset of Communication consumers, and it adds a lot of complexity to the base class. Furthermore, having a dedicated subclass makes it clear whether a particular consumer needs to account for the possibility of read thread being running or not. The modules currently calling `StartReadThread()` are updated to use `ThreadedCommunication`. The remaining modules use the simplified `Communication` class. `SBCommunication` is changed to use `ThreadedCommunication` in order to avoid changing the public API. `CommunicationKDP` is updated in order to (hopefully) compile with the new code. However, I do not have a Darwin box to test it, so I've limited the changes to the bare minimum. `GDBRemoteCommunication` is updated to become a `Broadcaster` directly. Since it does not inherit from `ThreadedCommunication`, its event support no longer collides with the one used for read thread and can be implemented cleanly. The support for `eBroadcastBitReadThreadDidExit` is removed from the code -- since the read thread was not used, this event was never reported. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D133251
2022-08-08[lldb] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song1-1/+1
2022-07-20[LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scanSlava Gurevich1-3/+3
Improve LLDB reliability by fixing the following "uninitialized variables" static code inspection warnings from scan.coverity.com: 1094796 1095721 1095728 1095737 1095741 1095756 1095779 1095789 1095805 1214552 1229457 1232475 1274006 1274010 1293427 1364800 1364802 1364804 1364812 1364816 1374902 1374909 1384975 1399312 1420451 1431704 1454230 1454554 1454615 1454579 1454594 1454832 1457759 1458696 1461909 1467658 1487814 1487830 1487845 Differential Revision: https://reviews.llvm.org/D130098
2022-06-21[lldb] [llgs] Implement non-stop style stop notification packetsMichał Górny1-0/+23
Implement the support for %Stop asynchronous notification packet format in LLGS. This does not implement full support for non-stop mode for threaded programs -- process plugins continue stopping all threads on every event. However, it will be used to implement asynchronous events in multiprocess debugging. The non-stop protocol is enabled using QNonStop packet. When it is enabled, the server uses notification protocol instead of regular stop replies. Since all threads are always stopped, notifications are always generated for all active threads and copied into stop notification queue. If the queue was empty, the initial asynchronous %Stop notification is sent to the client immediately. The client needs to (eventually) acknowledge the notification by sending the vStopped packet, in which case it is popped from the queue and the stop reason for the next thread is reported. This continues until notification queue is empty again, in which case an OK reply is sent. Asychronous notifications are also used for vAttach results and program exits. The `?` packet uses a hybrid approach -- it returns the first stop reason synchronously, and exposes the stop reasons for remaining threads via vStopped queue. The change includes a test case for a program generating a segfault on 3 threads. The server is expected to generate a stop notification for the segfaulting thread, along with the notifications for the other running threads (with "no stop reason"). This verifies that the stop reasons are correctly reported for all threads, and that notification queue works. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D125575
2022-02-23[lldb] Modernize ThreadLauncherPavel Labath1-8/+7
Accept a function object instead of a raw pointer. This avoids a bunch of boilerplate typically needed to pass arguments to the thread functions. Differential Revision: https://reviews.llvm.org/D120321
2022-02-01[lldb] Convert ProcessGDBRemoteLog to the new APIPavel Labath1-8/+8
2021-11-25[lldb/gdb-remote] Ignore spurious ACK packetsPavel Labath1-2/+13
Although I cannot find any mention of this in the specification, both gdb and lldb agree on sending an initial + packet after establishing the connection. OTOH, gdbserver and lldb-server behavior is subtly different. While lldb-server *expects* the initial ack, and drops the connection if it is not received, gdbserver will just ignore a spurious ack at _any_ point in the connection. This patch changes lldb's behavior to match that of gdb. An ACK packet is ignored at any point in the connection (except when expecting an ACK packet, of course). This is inline with the "be strict in what you generate, and lenient in what you accept" philosophy, and also enables us to remove some special cases from the server code. I've extended the same handling to NAK (-) packets, mainly because I don't see a reason to treat them differently here. (The background here is that we had a stub which was sending spurious + packets. This bug has since been fixed, but I think this change makes sense nonetheless.) Differential Revision: https://reviews.llvm.org/D114520
2021-11-24[lldb/gdb-remote] Remove more non-stop mode remnantsPavel Labath1-86/+1
The read thread handling is completely dead code now that non-stop mode no longer exists.
2021-10-26[lldb] [Host] Move port predicate-related logic to gdb-remoteMichał Górny1-5/+12
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] [Communication] Add a WriteAll() method that resumes writingMichał Górny1-3/+3
Add a Communication::WriteAll() that resumes Write() if the initial call did not write all data. Use it in GDBRemoteCommunication when sending packets in order to fix handling partial writes (i.e. just resume/retry them rather than erring out). This fixes LLDB failures when writing large packets to a pty. Differential Revision: https://reviews.llvm.org/D112169
2021-09-25[lldb] Convert misc. StringConvert usesMichał Górny1-2/+3
Replace misc. StringConvert uses with llvm::to_integer() and llvm::to_float(), except for cases where further refactoring is planned. The purpose of this change is to eliminate the StringConvert API that is duplicate to LLVM, and less correct in behavior at the same time. Differential Revision: https://reviews.llvm.org/D110447
2021-05-26[lldb][NFC] Use C++ versions of the deprecated C standard library headersRaphael Isemann1-2/+2
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