summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp
AgeCommit message (Collapse)Author
2025-05-27[LLDB] Show exit code on Windows if process can't launch (#141290)nerix
When running a process that would exit before LLDB could stop the target, it would try to interpret (and subsequently format) the exit code as a Win32 error. However, processes on Windows won't return Win32 errors in that case. They will often return an [NTSTATUS](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55). One common case for this to occur is when a DLL is missing. In that case, the process will start successfully, but it will exit with `STATUS_DLL_NOT_FOUND`. LLDB would previously return "unknown error", because it tried to [`FormatMessage`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-formatmessage) `0xC0000135` which doesn't work, so it fell back to "unknown error". This PR changes the error to be the string "Process prematurely exited with {0:x}" and doesn't try to format the exit code. One could `FormatMessage` an `NTSTATUS` by passing `FORMAT_MESSAGE_FROM_HMODULE` and a handle to `ntdll.dll`, however, I don't think we can get the required format arguments (e.g. the missing DLL name - `%hs`).
2024-09-05[lldb] Convert ProcessDebugger.cpp to new Status API (NFC)Adrian Prantl
2024-09-03[lldb] Support partial memory reads on windows (#106981)Pavel Labath
ReadProcessMemory will not perform the read if part of the memory is unreadable (and even though the API has a `number_of_bytes_read` argument). To make this work, I explicitly inspect the memory region being read and only read the accessible part.
2024-08-27[lldb] Adapt Plugins/Process/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.
2022-07-28[NFC] Improve FileSpec internal APIs and usage in preparation for adding ↵Greg Clayton
caching of resolved/absolute. Resubmission of https://reviews.llvm.org/D130309 with the 2 patches that fixed the linux buildbot, and new windows fixes. The FileSpec APIs allow users to modify instance variables directly by getting a non const reference to the directory and filename instance variables. This makes it impossible to control all of the times the FileSpec object is modified so we can clear cached member variables like m_resolved and with an upcoming patch caching if the file is relative or absolute. This patch modifies the APIs of FileSpec so no one can modify the directory or filename instance variables directly by adding set accessors and by removing the get accessors that are non const. Many clients were using FileSpec::GetCString(...) which returned a unique C string from a ConstString'ified version of the result of GetPath() which returned a std::string. This caused many locations to use this convenient function incorrectly and could cause many strings to be added to the constant string pool that didn't need to. Most clients were converted to using FileSpec::GetPath().c_str() when possible. Other clients were modified to use the newly renamed version of this function which returns an actualy ConstString: ConstString FileSpec::GetPathAsConstString(bool denormalize = true) const; This avoids the issue where people were getting an already uniqued "const char *" that came from a ConstString only to put the "const char *" back into a "ConstString" object. By returning the ConstString instead of a "const char *" clients can be more efficient with the result. The patch: - Removes the non const GetDirectory() and GetFilename() get accessors - Adds set accessors to replace the above functions: SetDirectory() and SetFilename(). - Adds ClearDirectory() and ClearFilename() to replace usage of the FileSpec::GetDirectory().Clear()/FileSpec::GetFilename().Clear() call sites - Fixed all incorrect usage of FileSpec::GetCString() to use FileSpec::GetPath().c_str() where appropriate, and updated other call sites that wanted a ConstString to use the newly returned ConstString appropriately and efficiently. Differential Revision: https://reviews.llvm.org/D130549
2022-07-07[lldb][Windows] Fix memory region base addresses when a range is splitDavid Spickett
Previously we recorded AllocationBase as the base address of the region we get from VirtualQueryEx. However, this is the base of the allocation, which can later be split into more regions. So you got stuff like: [0x00007fff377c0000-0x00007fff377c1000) r-- PECOFF header [0x00007fff377c0000-0x00007fff37840000) r-x .text [0x00007fff377c0000-0x00007fff37870000) r-- .rdata Where all the base addresses were the same. Instead, use BaseAddress as the base of the region. So we get: [0x00007fff377c0000-0x00007fff377c1000) r-- PECOFF header [0x00007fff377c1000-0x00007fff37840000) r-x .text [0x00007fff37840000-0x00007fff37870000) r-- .rdata https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-memory_basic_information The added test checks for any overlapping regions which means if we get the base or size wrong it'll fail. This logic applies to any OS so the test isn't restricted to Windows. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D129272
2022-06-22[lldb] Remove an outdated comment. NFC.Martin Storsjö
This comment became outdated in 053eb35651906e693906fad6c695fce11415ade7 (but was moved along); that commit moved the code and the comment to a separate function, with a separate local variable `num_of_bytes_read`. On error, the possibly garbage value is never copied back to the caller's reference, thus the comment is no longer relevant (and slightly confusing as is). Differential Revision: https://reviews.llvm.org/D128226
2022-01-27[lldb] Convert ProcessWindowsLog to the new APIPavel Labath
2021-11-03Revert "[lldb] Remove non address bits when looking up memory regions"David Spickett
This reverts commit 6f5ce43b433706c3ae5c37022d6c0964b6bfadf8 due to build failure on Windows.
2021-11-03[lldb] Remove non address bits when looking up memory regionsDavid Spickett
On AArch64 we have various things using the non address bits of pointers. This means when you lookup their containing region you won't find it if you don't remove them. This changes Process GetMemoryRegionInfo to a non virtual method that uses the current ABI plugin to remove those bits. Then it calls DoGetMemoryRegionInfo. That function does the actual work and is virtual to be overriden by Process implementations. A test case is added that runs on AArch64 Linux using the top byte ignore feature. Reviewed By: omjavaid Differential Revision: https://reviews.llvm.org/D102757
2020-10-05Reland "[lldb] Don't send invalid region addresses to lldb server"David Spickett
This reverts commit c65627a1fe3be7521fc232d633bb6df577f55269. The test immediately after the new invalid symbol test was failing on Windows. This was because when we called VirtualQueryEx to get the region info for 0x0, even if it succeeded we would call GetLastError. Which must have picked up the last error that was set while trying to lookup "not_an_address". Which happened to be 2. ("The system cannot find the file specified.") To fix this only call GetLastError when we know VirtualQueryEx has failed. (when it returns 0, which we were also checking for anyway) Also convert memory region to an early return style to make the logic clearer. Reviewed By: labath, stella.stamenova Differential Revision: https://reviews.llvm.org/D88229
2020-08-03[lldb/Process/Windows] Attempting to kill exited/detached process in not an ↵Tatyana Krasnukha
error The lldb test-suite on Windows reports a 'CLEANUP ERROR' when attempting to kill an exited/detached process. This change makes ProcessWindows consistent with the other processes which only log the error. After this change a number of 'CLEANUP ERROR' messages are now removed. Differential Revision: https://reviews.llvm.org/D84957
2020-01-29[lldb] Fix build break in ProcessDebugger due to StringRef usage changesStella Stamenova
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-10-31[LLDB] [Windows] Fix Windows-specific race condition in LLDB for session ↵Martin Storsjö
lifetime This can e.g. happen if the debugged executable exits before the initial stop, e.g. if it fails to load dependent DLLs. Add a virtual destructor to ProcessDebugger and let it clean up the session, and make ProcessWindows::OnExitProcess call ProcessDebugger::OnExitProcess for shared parts. Fix suggestion by Adrian McCarthy. Differential Revision: https://reviews.llvm.org/D69503
2019-07-10Try again to move common functionality from ProcessWindows into ProcessDebuggerAaron Smith
This reverts commit ed499a36b67cf46cbf66052cfe374c80a595f1c1 and addresses a problem causing a Windows build bot to hang. llvm-svn: 365592
2019-07-08Revert "Move common functionality from processwindows into processdebugger"Stella Stamenova
This reverts commit 9c01eaff6aa3f59d91530f47b85bb470377a7780. The changes in this commit are causing several of the LLDB tests to hang and/or timeout. llvm-svn: 365371
2019-06-24Move common functionality from processwindows into processdebuggerAaron Smith
Summary: This change extracts functionalities from processwindows into a introduced processdebugger that can be reused in native process debugging. The main reason is that the native process debugging can't directly be based on processwindows or be implemented as a pass-through to this plugin since the plugin has ties to Target and Process classes that are needed in host debugging but not necessary in native debugging. Reviewers: labath, Hui, jfb, clayborg, amccarth Reviewed By: labath Subscribers: amccarth, dexonsmith, mgorny, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D63166 llvm-svn: 364210