aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-08[lldb-dap] persistent assembly breakpoints (#148061)Ely Ronnen1-1/+2
Resolves #141955 - Adds data to breakpoints `Source` object, in order for assembly breakpoints, which rely on a temporary `sourceReference` value, to be able to resolve in future sessions like normal path+line breakpoints - Adds optional `instructions_offset` parameter to `BreakpointResolver`
2025-03-13[lldb][NFC] Correct whitespace in SearchForKernelWithDebugHintsJason Molenda1-20/+22
2025-02-20[lldb] Store StreamAsynchronousIO in a unique_ptr (NFC) (#127961)Jonas Devlieghere1-3/+3
Make StreamAsynchronousIO an unique_ptr instead of a shared_ptr. I tried passing the class by value, but the llvm::raw_ostream forwarder stored in the Stream parent class isn't movable and I don't think it's worth changing that. Additionally, there's a few places that expect a StreamSP, which are easily created from a StreamUP.
2025-02-19[lldb] Make GetOutputStreamSP and GetErrorStreamSP protected (#127682)Jonas Devlieghere1-4/+5
This makes GetOutputStreamSP and GetErrorStreamSP protected members of Debugger. Users who want to print to the debugger's stream should use GetAsyncOutputStreamSP and GetAsyncErrorStreamSP instead and the few remaining stragglers have been migrated.
2025-02-12[lldb] Remove Debugger::Get{Output,Error}Stream (NFC) (#126821)Jonas Devlieghere1-41/+40
Remove Debugger::GetOutputStream and Debugger::GetErrorStream in preparation for replacing both with a new variant that needs to be locked and hence can't be handed out like we do right now. The patch replaces most uses with GetAsyncOutputStream and GetAsyncErrorStream respectively. There methods return new StreamSP objects that automatically get flushed on destruction. See #126630 for more details.
2025-02-10[lldb] [darwin] Upstream a few DriverKit cases (#126604)Jason Molenda1-2/+4
A DriverKit process is a kernel extension that runs in userland, instead of running in the kernel address space/priv levels, they've been around a couple of years. From lldb's perspective a DriverKit process is no different from any other userland level process, but it has a different Triple so we need to handle those cases in the lldb codebase. Some of the DriverKit triple handling had been upstreamed to llvm-project, but I noticed a few cases that had not yet. Cleaning that up.
2024-08-27[lldb] Turn lldb_private::Status into a value type. (#106163)Adrian Prantl1-1/+1
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-20[lldb][AIX] 1. Avoid namespace collision on other platforms (#104679)Dhruv Srivastava1-2/+2
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. #101657 The complete changes for porting are present in this draft PR: https://github.com/llvm/llvm-project/pull/102601 The changes on this PR are intended to avoid namespace collision for certain typedefs between lldb and other platforms: 1. tid_t --> lldb::tid_t 2. offset_t --> lldb::offset_t
2024-07-17[lldb] progressive progress reporting for darwin kernel/firmware (#98845)Jason Molenda1-28/+36
When doing firmware/kernel debugging, it is frequent that binaries and debug info need to be retrieved / downloaded, and the lack of progress reports made for a poor experience, with lldb seemingly hung while downloading things over the network. This PR adds progress reports to the critical sites for these use cases.
2024-03-06[lldb] Address mask sbprocess apis and new mask invalid const (#83663)Jason Molenda1-1/+2
[lldb] Add SBProcess methods for get/set/use address masks (#83095) I'm reviving a patch from phabracator, https://reviews.llvm.org/D155905 which was approved but I wasn't thrilled with all the API I was adding to SBProcess for all of the address mask types / memory regions. In this update, I added enums to control type address mask type (code, data, any) and address space specifiers (low, high, all) with defaulted arguments for the most common case. I originally landed this via https://github.com/llvm/llvm-project/pull/83095 but it failed on CIs outside of arm64 Darwin so I had to debug it on more environments and update the patch. This patch is also fixing a bug in the "addressable bits to address mask" calculation I added in AddressableBits::SetProcessMasks. If lldb were told that 64 bits are valid for addressing, this method would overflow the calculation and set an invalid mask. Added tests to check this specific bug while I was adding these APIs. This patch changes the value of "no mask set" from 0 to LLDB_INVALID_ADDRESS_MASK, which is UINT64_MAX. A mask of all 1's means "no bits are used for addressing" which is an impossible mask, whereas a mask of 0 means "all bits are used for addressing" which is possible. I added a base class implementation of ABI::FixCodeAddress and ABI::FixDataAddress that will apply the Process mask values if they are set to a value other than LLDB_INVALID_ADDRESS_MASK. I updated all the callers/users of the Mask methods which were handling a value of 0 to mean invalid mask to use LLDB_INVALID_ADDRESS_MASK. I added code to the all AArch64 ABI Fix* methods to apply the Highmem masks if they have been set. These will not be set on a Linux environment, but in TestAddressMasks.py I test the highmem masks feature for any AArch64 target, so all AArch64 ABI plugins must handle it. rdar://123530562
2024-02-19[llvm] Upstream the BridgeOS triple enum value (NFC)Jonas Devlieghere1-1/+1
This upstreams the BridgeOS target triple enum value.
2024-01-17[lldb] Upstream xros support in lldb (#78389)Jonas Devlieghere1-0/+1
Upstream support for debugging xros applications through LLDB.
2023-11-05[lldb] Remove LocateSymbolFile (#71301)Jonas Devlieghere1-1/+0
This completes the conversion of LocateSymbolFile into a SymbolLocator plugin. The only remaining function is DownloadSymbolFileAsync which doesn't really fit into the plugin model, and therefore moves into the SymbolLocator class, while still relying on the plugins to do the underlying work.
2023-11-04[lldb] Move DownloadObjectAndSymbolFile to SymbolLocator plugin (#71267)Jonas Devlieghere1-2/+2
This builds on top of the work started in c3a302d to convert LocateSymbolFile to a SymbolLocator plugin. This commit moves DownloadObjectAndSymbolFile.
2023-10-04[lldb] Mark operator== const to avoid ambiguity in C++20. (#68224)Samira Bazuzi1-2/+2
C++20 will automatically generate an operator== with reversed operand order, which is ambiguous with the written operator== when one argument is marked const and the other isn't. These operators currently trigger -Wambiguous-reversed-operator at usage sites lldb/source/Symbol/SymbolFileOnDemand.cpp:68 and lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp:1286.
2023-08-31[lldb][NFCI] Remove unneeded ConstString conversionsAlex Langford1-2/+2
ConstString can be implicitly converted into a llvm::StringRef. This is very useful in many places, but it also hides places where we are creating a ConstString only to use it as a StringRef for the entire lifespan of the ConstString object. I locally removed the implicit conversion and found some of the places we were doing this. Differential Revision: https://reviews.llvm.org/D159237
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
2023-08-08When loading kernel binary, use DownloadObjectAndSymbolFile lastJason Molenda1-16/+17
When lldb starts a kernel debug session, it has the UUID of the kernel binary. lldb will try three different methods to find a binary and symbol file for this UUID. Currently it calls out to Symbols::DownloadObjectAndSymbolFile() first, which may be the slowest method when a DBGShellCommand can find the UUID on a network filesystem or downloaded from a server. This patch tries the local searches first, then falls back to that method. Differential Revision: https://reviews.llvm.org/D157165
2023-08-08Show error messages from DebugSymbols DBGShellCommand agentJason Molenda1-3/+8
The DebugSymbols DBGShellsCommand, which can find the symbols for binaries, has a mechanism to return error messages when it cannot find a symbol file. Those errors were not printed to the user for several corefile use case scenarios; this patch fixes that. Also add dyld/process logging for the LC_NOTE metadata parsers in ObjectFileMachO, to help in seeing what lldb is basing its searches on. Differential Revision: https://reviews.llvm.org/D157160
2023-07-30[lldb] Remove the last radar link in LLDB source code (NFC)Jonas Devlieghere1-4/+2
This was probably the only really useful radar in our source code. It's a request to be able to tell if __LINKEDIT has been mapped or not. I've left a comment in the radar that we should update the corresponding code if and when such an ability becomes available.
2023-05-31Setting to control addressable bits in high memoryJason Molenda1-8/+14
On AArch64, it is possible to have a program that accesses both low (0x000...) and high (0xfff...) memory, and with pointer authentication, you can have different numbers of bits used for pointer authentication depending on whether the address is in high or low memory. This adds a new target.process.highmem-virtual-addressable-bits setting which the AArch64 Mac ABI plugin will use, when set, to always set those unaddressable high bits for high memory addresses, and will use the existing target.process.virtual-addressable-bits setting for low memory addresses. This patch does not change the existing behavior when only target.process.virtual-addressable-bits is set. In that case, the value will apply to all addresses. Not yet done is recognizing metadata in a live process connection (gdb-remote qHostInfo) or a Mach-O corefile LC_NOTE to set the correct number of addressing bits for both memory ranges. That will be a future change. Differential Revision: https://reviews.llvm.org/D151292 rdar://109746900
2023-05-04[lldb] Use templates to simplify {Get,Set}PropertyAtIndex (NFC)Jonas Devlieghere1-4/+6
Use templates to simplify {Get,Set}PropertyAtIndex. It has always bothered me how cumbersome those calls are when adding new properties. After this patch, SetPropertyAtIndex infers the type from its arguments and GetPropertyAtIndex required a single template argument for the return value. As an added benefit, this enables us to remove a bunch of wrappers from UserSettingsController and OptionValueProperties. Differential revision: https://reviews.llvm.org/D149774
2023-05-02[lldb] Make exe_ctx an optional argument in OptionValueProperties (NFC)Jonas Devlieghere1-6/+3
The majority of call sites are nullptr as the execution context. Refactor OptionValueProperties to make the argument optional and simplify all the callers.
2023-05-01[lldb] Refactor OptionValueProperties to return a std::optional (NFC)Jonas Devlieghere1-6/+8
Similar to fdbe7c7faa54, refactor OptionValueProperties to return a std::optional instead of taking a fail value. This allows the caller to handle situations where there's no value, instead of being unable to distinguish between the absence of a value and the value happening the match the fail value. When a fail value is required, std::optional::value_or() provides the same functionality.
2023-04-19[lldb] Change setting descriptions to use StringRef instead of ConstStringAlex Langford1-1/+1
These probably do not need to be in the ConstString StringPool as they don't really need any of the advantages that ConstStrings offer. Lifetime for these things is always static and we never need to perform comparisons for setting descriptions. Differential Revision: https://reviews.llvm.org/D148679
2023-04-03Using global variable in xnu kernel, set # of addressable bitsJason Molenda1-0/+31
The kernel has a global variable with the TCR_EL1.T1SZ value, from which was can calculate the number of addressable bits. Find that symbol in DynamicLoaderDarwinKernel and set the bits to that value for this Process. Differential Revision: https://reviews.llvm.org/D147462 rdar://107445318
2023-03-08Clean up conditional, don't set load binaries twiceJason Molenda1-5/+4
Follow Alex Langford's feedback to my patch from https://reviews.llvm.org/D145547 , and fix a side issue I noticed while testing this, where binaries loaded via LC_NOTE metadata were loaded in the Target twice unnecessarily.
2023-03-08Don't load non-kexts in darwin kernel debug; handle unslid segsJason Molenda1-8/+66
We have some non-kexts in the binary list in the Darwin kernel in some situations. The binary has likely already been loaded; check if it has been, and don't re-load it. Also, if we do need to load it at this point, if in-memory segment vmaddrs have not been updated to the actual load addresses, calculate a fixed slide for the in-memory image and apply that slide to the ondisk binary. Differential Revision: https://reviews.llvm.org/D145547 rdar://106343477
2023-01-28Use llvm::byteswap instead of ByteSwap_{16,32,64} (NFC)Kazu Hirata1-7/+7
2023-01-13Revert "[lldb] Add Debugger & ScriptedMetadata reference to ↵Med Ismail Bennani1-1/+1
Platform::CreateInstance" This reverts commit 2d53527e9c64c70c24e1abba74fa0a8c8b3392b1.
2023-01-12[lldb] Add Debugger & ScriptedMetadata reference to Platform::CreateInstanceMed Ismail Bennani1-1/+1
This patch is preparatory work for Scripted Platform support and does multiple things: First, it introduces new options for the `platform select` command and `SBPlatform::Create` API, to hold a reference to the debugger object, the name of the python script managing the Scripted Platform and a structured data dictionary that the user can use to pass arbitrary data. Then, it updates the various `Create` and `GetOrCreate` methods for the `Platform` and `PlatformList` classes to pass down the new parameter to the `Platform::CreateInstance` callbacks. Finally, it updates every callback to reflect these changes. Differential Revision: https://reviews.llvm.org/D139249 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-12-19Revert "[lldb] Remove redundant .c_str() and .get() calls"Muhammad Omair Javaid1-2/+2
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-2/+2
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-12-05Increase search for kernel image from 32MB to 128MBJason Molenda1-2/+2
DynamicLoaderDarwinKernel::SearchForKernelNearPC() searches for a Darwin kernel mach-o header starting at $pc and working backwards, stopping on the first memory read error encountered. The kernel, and the kexts linked in to the kernel, have grown over the years and the original 32MB scan limit is giving a high chance of failing to find the kernel if we're in a random kext. In non-kernel environments, firmware and bare board typically, we will hit a memory read error on an unmapped page quickly so this doesn't add a lot of random memory read requests in those environments. We only check at one megabyte boundaries, so worst case this is 128 reads at the start of a gdb-remote connection. The check for a memory read error & stopping was a more recent addition (a few years ago), so I kept the scan region a bit small.
2022-10-13PlatformDarwinKernel calls the ctor directly, not setting no-jitJason Molenda1-1/+1
Fix a small thinko in https://reviews.llvm.org/D133534 . Normally DynamicLoaderDarwinKernels are created via the CreateInstance plugin method, and that plugin method sets the Process CanJIT to false. In the above patch, I added a new code path that can call the DynamicLoaderDarwinKernel ctor directly, without going through CreateInstance, and CanJIT was not being correctly set for the process. rdar://101148552
2022-10-10Allow DynamicLoaderDarwinKernel to activate without binaryJason Molenda1-1/+2
In https://reviews.llvm.org/D133534 I made a little cleanup to DynamicLoaderDarwinKernel::CreateInstance and unintentionally changed the logic. Previously it would not create an instance if there was a binary given to lldb and it was not a kernel. With my change, the absence of any binary would also cause it to not create. So connecting to a kernel without any binaries would fail. rdar://100985097
2022-09-09Recognize a platform binary in ProcessGDBRemote which determines pluginsJason Molenda1-78/+51
Complete support of the binary-addresses key in the qProcessInfo packet in ProcessGDBRemote, for detecting if one of the binaries needs to be handled by a Platform plugin, and can be used to set the Process' DynamicLoader plugin and the Target's Platform plugin. Implement this method in PlatformDarwinKernel to recognize a kernel fileset at that address, find the actual kernel address in the fileset, set DynamicLoaderDarwinKernel and PlatformDarwinKernel in the Process/Target; register the kernel address with the dynamic loader so it will be loaded later during attach. This patch only addresses the live debug scenario with a gdb remote serial protocol connection. I'll handle corefiles in a subsequent patch that builds on this. Differential Revision: https://reviews.llvm.org/D133534 rdar://98754861
2022-09-08[lldb] Use std::size instead of llvm::array_lengthofJoe Loser1-1/+1
LLVM contains a helpful function for getting the size of a C-style array: `llvm::array_lengthof`. This is useful prior to C++17, but not as helpful for C++17 or later: `std::size` already has support for C-style arrays. Change call sites to use `std::size` instead. Differential Revision: https://reviews.llvm.org/D133501
2022-08-30Change the meaning of a UUID with all zeros for data.Jim Ingham1-1/+1
Previously, depending on how you constructed a UUID from data or a StringRef, an input value of all zeros was valid (e.g. setFromData) or not (e.g. setFromOptionalData). Since there was no way to tell which interpretation to use, it was done somewhat inconsistently. This standardizes the meaning of a UUID of all zeros to Not Valid, and removes all the Optional methods and their uses, as well as the static factories that supported them. Differential Revision: https://reviews.llvm.org/D132191
2022-04-14[lldb] Show the DBGError if dsymForUUID can't find a dSYMJonas Devlieghere1-1/+2
Show the user the DBGError (if available) when dsymForUUID fails. rdar://90949180 Differential revision: https://reviews.llvm.org/D123743
2022-04-13[lldb] Remove the global platform listPavel Labath1-2/+3
This patch moves the platform creation and selection logic into the per-debugger platform lists. I've tried to keep functional changes to a minimum -- the main (only) observable difference in this change is that APIs, which select a platform by name (e.g., Debugger::SetCurrentPlatform) will not automatically pick up a platform associated with another debugger (or no debugger at all). I've also added several tests for this functionality -- one of the pleasant consequences of the debugger isolation is that it is now possible to test the platform selection and creation logic. This is a product of the discussion at <https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594>. Differential Revision: https://reviews.llvm.org/D120810
2022-03-09Revert "[lldb] Remove the global platform list"Pavel Labath1-3/+2
It makes module dependencies loopier. This reverts commits 49cffe3c7fab74252d4b6a073303c803dc1659f0 and ffb9429b6f3c29ab4687b96fd85374924c98ad16.
2022-03-09[lldb] Remove the global platform listPavel Labath1-2/+3
This patch moves the platform creation and selection logic into the per-debugger platform lists. I've tried to keep functional changes to a minimum -- the main (only) observable difference in this change is that APIs, which select a platform by name (e.g., Debugger::SetCurrentPlatform) will not automatically pick up a platform associated with another debugger (or no debugger at all). I've also added several tests for this functionality -- one of the pleasant consequences of the debugger isolation is that it is now possible to test the platform selection and creation logic. This is a product of the discussion at <https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594>. Differential Revision: https://reviews.llvm.org/D120810
2022-02-03[lldb] Rename Logging.h to LLDBLog.h and clean up includesPavel Labath1-0/+1
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 Labath1-6/+6
2022-01-26Revert "Rename llvm::array_lengthof into llvm::size to match std::size from ↵Benjamin Kramer1-1/+1
C++17" This reverts commit ef8206320769ad31422a803a0d6de6077fd231d2. - It conflicts with the existing llvm::size in STLExtras, which will now never be called. - Calling it without llvm:: breaks C++17 compat
2022-01-26Rename llvm::array_lengthof into llvm::size to match std::size from C++17serge-sans-paille1-1/+1
As a conquence move llvm::array_lengthof from STLExtras.h to STLForwardCompat.h (which is included by STLExtras.h so no build breakage expected).
2021-10-26[lldb] Remove ConstString from Platform plugin namesPavel Labath1-2/+2
2021-10-25Remove ConstString from DynamicLoader, JITLoader and Instruction plugin namesPavel Labath1-6/+1
2021-10-18[lldb] Return StringRef from PluginInterface::GetPluginNamePavel Labath1-7/+1
There is no reason why this function should be returning a ConstString. While modifying these files, I also fixed several instances where GetPluginName and GetPluginNameStatic were returning different strings. I am not changing the return type of GetPluginNameStatic in this patch, as that would necessitate additional changes, and this patch is big enough as it is. Differential Revision: https://reviews.llvm.org/D111877