summaryrefslogtreecommitdiff
path: root/lldb/source/Target/Process.cpp
AgeCommit message (Collapse)Author
2023-08-22Revert "[lldb] Fix data race in ThreadList"Augusto Noronha
This reverts commit bb90063249707e3ae081bfbd8e3512566abb7df6.
2023-08-21[lldb] Change UnixSignals::GetSignalAsCString to GetSignalAsStringRefAlex Langford
This is in preparation to remove the uses of ConstString from UnixSignals. Differential Revision: https://reviews.llvm.org/D158209
2023-08-18[lldb] Fix data race in ProcessAugusto Noronha
Thread sanitizer reports a data race in Process.cpp in the usage of m_process_input_reader. Fix this data race by introducing a mutex guarding the access to this variable. Differential Revision: https://reviews.llvm.org/D157648
2023-08-18[lldb] Fix data race in ThreadListAugusto Noronha
ThreadSanitizer reports the following issue: ``` Write of size 8 at 0x00010a70abb0 by thread T3 (mutexes: write M0): #0 lldb_private::ThreadList::Update(lldb_private::ThreadList&) ThreadList.cpp:741 (liblldb.18.0.0git.dylib:arm64+0x5dedf4) (BuildId: 9bced2aafa373580ae9d750d9cf79a8f32000000200000000100000000000e00) #1 lldb_private::Process::UpdateThreadListIfNeeded() Process.cpp:1212 (liblldb.18.0.0git.dylib:arm64+0x53bbec) (BuildId: 9bced2aafa373580ae9d750d9cf79a8f32000000200000000100000000000e00) Previous read of size 8 at 0x00010a70abb0 by main thread (mutexes: write M1): #0 lldb_private::ThreadList::GetMutex() const ThreadList.cpp:785 (liblldb.18.0.0git.dylib:arm64+0x5df138) (BuildId: 9bced2aafa373580ae9d750d9cf79a8f32000000200000000100000000000e00) #1 lldb_private::ThreadList::DidResume() ThreadList.cpp:656 (liblldb.18.0.0git.dylib:arm64+0x5de5c0) (BuildId: 9bced2aafa373580ae9d750d9cf79a8f32000000200000000100000000000e00) #2 lldb_private::Process::PrivateResume() Process.cpp:3130 (liblldb.18.0.0git.dylib:arm64+0x53cd7c) (BuildId: 9bced2aafa373580ae9d750d9cf79a8f32000000200000000100000000000e00) ``` Fix this by only using the mutex in ThreadList and removing the one in process entirely. Differential Revision: https://reviews.llvm.org/D158034
2023-08-16Replace the singleton "ShadowListener" with a primary and N secondary ListenersJim Ingham
Before the addition of the process "Shadow Listener" you could only have one Listener observing the Process Broadcaster. That was necessary because fetching the Process event is what switches the public process state, and for the execution control logic to be manageable you needed to keep other listeners from causing this to happen before the main process control engine was ready. Ismail added the notion of a "ShadowListener" - which allowed you ONE extra process listener. This patch inverts that setup by designating the first listener as primary - and giving it priority in fetching events. Differential Revision: https://reviews.llvm.org/D157556
2023-08-14[lldb][NFCI] Change parameter type in Process::SetExitStatusAlex Langford
My primary motivation here is actually to change something in UnixSignals, but this change is a necesary precondition. I've also updated the documentation and rewritten the log statements to use `formatv` instead of `printf` (printf-style formatting and llvm::StringRef don't mix well). Differential Revision: https://reviews.llvm.org/D157662
2023-08-09[lldb] Sink StreamFile into lldbHostAlex Langford
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-07-05[lldb] Fix incorrect uses of formatv specifiers in LLDB_LOGJonas Devlieghere
Fix incorrect uses of formatv specifiers in LLDB_LOG. Unlike Python, arguments must be numbered. All the affected log statements take llvm:Errors so use the LLDB_LOG_ERROR macro instead. Differential revision: https://reviews.llvm.org/D154532
2023-07-03[lldb] Fix data race when interacting with python scriptsMed Ismail Bennani
This patch should fix some data races when a python script (i.e. a Scripted Process) has a nested call to another python script (i.e. a OperatingSystem Plugin), which can cause concurrent writes to the python lock count. This patch also fixes a data race happening when resetting the operating system unique pointer. To address these issues, both accesses is guarded by a mutex. rdar://109413039 Differential Revision: https://reviews.llvm.org/D154271 Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-06-26[lldb][NFCI] Remove ConstString from Process::ConfigureStructuredDataAlex Langford
This is a follow-up to b4827a3c0a7ef121ca376713e115b04eff0f5194. Differential Revision: https://reviews.llvm.org/D153675
2023-06-26[lldb][NFCI] Remove unneeded ConstString constructions for ↵Alex Langford
OptionValueProperties::AppendProperty I removed ConstString from OptionValueProperties in 643ba926c1f6, but there are a few call sites that still create a ConstString as an argument. I did not catch these initially because ConstString has an implicit conversion method to StringRef. Differential Revision: https://reviews.llvm.org/D153673
2023-06-23[lldb][NFCI] Remove use of ConstString from StructuredDataPluginAlex Langford
The use of ConstString in StructuredDataPlugin is unneccessary as fast comparisons are not neeeded for StructuredDataPlugins. Differential Revision: https://reviews.llvm.org/D153482
2023-06-16[lldb] Simplify logging in Process settings (NFC)Jonas Devlieghere
2023-06-15lldb [NFC] Add logging to Process when address masks are updatedJason Molenda
To aid in integration testing/debugging. Verifying that the address mask/addressable bits values from different sources are correctly registered by lldb.
2023-06-14Add Fix*Address methods to Process, call into ABIJason Molenda
We need to clear non-addressable bits from addresses across the lldb sources. Currently these need to use an ABI method to clear those bits from addresses, which you do by taking a Process, getting the current ABI, then calling the method. Simplify this by providing methods in Process which call into the ABI methods themselves. Differential Revision: https://reviews.llvm.org/D152863
2023-06-05[lldb][NFCI] Change the way Process stores StructuredData pluginsAlex Langford
Instead of having a map from ConstString to StructuredDataPluginSP, we can use an llvm::StringMap. The keys themselves don't need to be ConstStrings, so an llvm::StringMap feels most natural. Differential Revision: https://reviews.llvm.org/D151960
2023-06-05[lldb][NFCI] Use size_t in OptionValuePropertiesAlex Langford
In many places we're using uint32_t where we should be using size_t. We should be consistent. Differential Revision: https://reviews.llvm.org/D151949
2023-06-01[lldb/crashlog] Create interactive crashlog with no binaryMed Ismail Bennani
This patch changes the way we load a crash report into a scripted process by creating a empty target. To do so, it parses the architecture information from the report (for both the legacy and json format) and uses that to create a target that doesn't have any executable, like what we do when attaching to a process. For the legacy format, we mostly rely on the `Code Type` line, since the architure is an optional field on the `Binary Images` sections. However for the json format, we first try to get the architecture while parsing the image dictionary if we couldn't find it, we try to infer it using the "flavor" key when parsing the frame's registers. If the architecture is still not set after parsing the report, we raise an exception. rdar://107850263 Differential Revision: https://reviews.llvm.org/D151849 Differential Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-05-31Setting to control addressable bits in high memoryJason Molenda
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-22[lldb] Fix process LLDB_LOG typo (nfci)Med Ismail Bennani
This patch fixes the log commands by replacing the LLDB_LOG macro by the LLDB_LOGF macro. This is necessary in order to format argument with printf. Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-05-14[lldb] Complete OptionValue cleanup (NFC)Jonas Devlieghere
Make the `Get.*Value` and `Set.*Value` function private and migrate the last remaining call sites to the new overloaded/templated functions.
2023-05-04[lldb] Eliminate {Get,Set}PropertyAtIndexAsFileSpec (NFC)Jonas Devlieghere
This patch is a continuation of 6f8b33f6dfd0 and eliminates the {Get,Set}PropertyAtIndexAsFileSpec functions.
2023-05-04[lldb] Use templates to simplify {Get,Set}PropertyAtIndex (NFC)Jonas Devlieghere
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 Devlieghere
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-02[lldb] Remove unused will_modify argument (NFC)Jonas Devlieghere
Various OptionValue related classes are passing around will_modify but the value is never used. This patch simplifies the interfaces by removing the redundant argument.
2023-05-01[lldb] Refactor OptionValueProperties to return a std::optional (NFC)Jonas Devlieghere
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-25[lldb] Improve logging for process state change (NFC)Med Ismail Bennani
This patch improves process state change logging messages to include to process plugin name. It also replaces the `LLDB_LOGF` macro by `LLDB_LOG` macro that adds the class and method name in the log message using the compiler instead of having to change the string litteral for every method. This is very useful when investigating interactions between different types of process plugins. That comes very handy when investigating bugs related to interactive scripted process debugging. Differential Revision: https://reviews.llvm.org/D148399 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-04-21Make sure SelectMostRelevantFrame happens only when returning to the user.Jim Ingham
This is a user facing action, it is meant to focus the user's attention on something other than the 0th frame when you stop somewhere where that's helpful. For instance, stopping in pthread_kill after an assert will select the assert frame. This is not something you want to have happen internally in lldb, both because internally you really don't want the selected frame changing out from under you, and because the recognizers can do arbitrary work, and that can cause deadlocks or other unexpected behavior. However, it's not something that the current code does explicitly after a stop has been delivered, it's expected to happen implicitly as part of stopping. I changing this to call SMRF explicitly after a user stop, but that got pretty ugly quickly. So I added a bool to control whether to run this and audited all the current uses to determine whether we're returning to the user or not. Differential Revision: https://reviews.llvm.org/D148863
2023-04-19[lldb] Fix bug to update process public run lock with process stateMed Ismail Bennani
This patch should address an issue that caused the process public run lock to not be updated during a process launch/attach when the process stops. That caused the public run lock to report its state as running while the process state is stopped. This prevents the users to interact with the process (through the command line or via the SBAPI) since it's considered still running. To address that, this patch refactors the name of the internal hijack listeners to a specific pattern `lldb.internal.<action>.hijack` that are used to ensure that we've attached to or launched a process successfully. Then, when updating the process public state, after updating the state value, if the process is not hijacked externally, meaning if the process doens't have a hijack listener that matches the internal hijack listeners pattern, we can update the public run lock accordingly. rdar://108283017 Differential Revision: https://reviews.llvm.org/D148400 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-04-19[lldb] Change setting descriptions to use StringRef instead of ConstStringAlex Langford
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-19Revert "[lldb] Fix bug to update process public run lock with process state"Med Ismail Bennani
This reverts commit 14f00213b202a82b895a6ab749262d4382435012.
2023-04-19[lldb] Fix bug to update process public run lock with process stateMed Ismail Bennani
This patch should address an issue that caused the process public run lock to not be updated during a process launch/attach when the process stops. That caused the public run lock to report its state as running while the process state is stopped. This prevents the users to interact with the process (through the command line or via the SBAPI) since it's considered still running. To address that, this patch refactors the name of the internal hijack listeners to a specific pattern `lldb.internal.<action>.hijack` that are used to ensure that we've attached to or launched a process successfully. Then, when updating the process public state, after updating the state value, if the process is not hijacked externally, meaning if the process doens't have a hijack listener that matches the internal hijack listeners pattern, we can update the public run lock accordingly. Differential Revision: https://reviews.llvm.org/D148400 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-04-11[lldb] Change return type of EventData::GetFlavorAlex Langford
There's no reason these strings need to be in the ConstString StringPool, they're already string literals with static lifetime. I plan on addressing other similar functions in follow up commits. Differential Revision: https://reviews.llvm.org/D147833
2023-03-10[lldb][NFC] Use UnixSignal::CreateForHost in ProcessAlex Langford
These do the same thing but we have a specific function for it.
2023-02-14[LLDB] add arch-specific watchpoint behavior defaults to lldbJason Molenda
lldb was originally designed to get the watchpoint exception behavior from the gdb remote serial protocol stub -- exceptions are either received before the instruction executes, or after the instruction has executed. This behavior was reported via two lldb extensions to gdb RSP, so generic remote stubs like gdbserver or a JTAG stub, would not tell lldb which behavior was correct, and it would default to "exceptions are received after the instruction has executed". Two architectures hard coded their correct "exceptions before instruction" behavior, to work around this issue. Most architectures have a fixed behavior of watchpoint exceptions, and we can center that information in lldb. We can allow a remote stub to override the default behavior via our packet extensions if it's needed on a specific target. This patch also separates the fetching of the number of watchpoints from whether exceptions are before/after the insn. Currently if lldb couldn't fetch the number of watchpoints (not really needed), it also wouldn't get when exceptions are received, and watchpoint handling would fail. lldb doesn't actually use the number of watchpoints for anything beyond printing it to the user. Differential Revision: https://reviews.llvm.org/D143215 rdar://101426626
2023-02-01[lldb][NFC] Use move instead of copyChris Cotter
Summary: For functions that accept an rvalue reference type parameter, use move to avoid copying the parameter. These were found when implementing CppCoreGuideline F.18 in clang-tidy. Committed on behalf of ccotter (Chris Cotter) Reviewers: Michael137 Differential Revision: https://reviews.llvm.org/D142824
2023-01-13Revert "[lldb] Add Debugger & ScriptedMetadata reference to ↵Med Ismail Bennani
Platform::CreateInstance" This reverts commit 2d53527e9c64c70c24e1abba74fa0a8c8b3392b1.
2023-01-12[lldb] Add Debugger & ScriptedMetadata reference to Platform::CreateInstanceMed Ismail Bennani
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>
2023-01-11[lldb] Do not deallocate memory after execAlex Langford
After an exec has occured, resources used to manage the state of a Process are cleaned up. One such resource is the AllocatedMemoryCache which keeps track of memory allocations made in the process for things like expression evaluation. After an exec is performed, the allocated memory regions in the process are gone, so it does not make sense to try to deallocate those regions. rdar://103188106 Differential Revision: https://reviews.llvm.org/D140249
2023-01-07[lldb] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to clean up the "using" declarations, #include "llvm/ADT/Optional.h", etc. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07[lldb] Add #include <optional> (NFC)Kazu Hirata
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-04[lldb] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-16Make CompilerType safeAdrian Prantl
When a process gets restarted TypeSystem objects associated with it may get deleted, and any CompilerType objects holding on to a reference to that type system are a use-after-free in waiting. Because of the SBAPI, we don't have tight control over where CompilerTypes go and when they are used. This is particularly a problem in the Swift plugin, where the scratch TypeSystem can be restarted while the process is still running. The Swift plugin has a lock to prevent abuse, but where there's a lock there can be bugs. This patch changes CompilerType to store a std::weak_ptr<TypeSystem>. Most of the std::weak_ptr<TypeSystem>* uglyness is hidden by introducing a wrapper class CompilerType::WrappedTypeSystem that has a dyn_cast_or_null() method. The only sites that need to know about the weak pointer implementation detail are the ones that deal with creating TypeSystems. rdar://101505232 Differential Revision: https://reviews.llvm.org/D136650
2022-11-09Don't try to create Expressions when the process is running.Jim Ingham
We generally prohibit this at a higher level - for instance requiring the process to be stopped for "expr". But when we trigger an expression for internal purposes (e.g. to fetch types from the ObjC runtime) we weren't checking the process state. Now we explicitly check this at the very start of the job so we don't get into bad states. Differential Revision: https://reviews.llvm.org/D137684
2022-10-06[lldb] Move breakpoint hit reset code to Target::CleanupProcessPavel Labath
This ensures it is run regardless of the method we use to initiate the session (previous version did not handle connects), and it is the same place that is used for resetting watchpoints. Differential Revision: https://reviews.llvm.org/D134882
2022-09-19[lldb] Reset breakpoint hit count before new runsFelipe de Azevedo Piovezan
A common debugging pattern is to set a breakpoint that only stops after a number of hits is recorded. The current implementation never resets the hit count of breakpoints; as such, if a user re-`run`s their program, the debugger will never stop on such a breakpoint again. This behavior is arguably undesirable, as it renders such breakpoints ineffective on all but the first run. This commit changes the implementation of the `Will{Launch, Attach}` methods so that they reset the _target's_ breakpoint hitcounts. Differential Revision: https://reviews.llvm.org/D133858
2022-09-09Recognize a platform binary in ProcessGDBRemote which determines pluginsJason Molenda
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-08-08[lldb] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song
2022-08-02[lldb] Create an enum to specify the kind of ArchSpec matchingPavel Labath
s/true/ArchSpec::ExactMatch s/false/ArchSpec::CompatibleMatch Differential Revision: https://reviews.llvm.org/D121290
2022-07-25[LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan. Part 2Slava Gurevich
Improve LLDB reliability by fixing the following "uninitialized variables" static code inspection warnings from scan.coverity.com: 1476275, 1274012, 1455035, 1364789, 1454282 1467483, 1406152, 1406255, 1454837, 1454416 1467446, 1462022, 1461909, 1420566, 1327228 1367767, 1431254, 1467299, 1312678, 1431780 1454731, 1490403 Differential Revision: https://reviews.llvm.org/D130528