summaryrefslogtreecommitdiff
path: root/lldb/source/Target/Thread.cpp
AgeCommit message (Collapse)Author
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-05-01[lldb] Add debugger.external-editor settingJonas Devlieghere
Add a new setting (debugger.external-editor) to specify an external editor. The setting takes precedence over the existing LLDB_EXTERNAL_EDITOR environment variable. Differential revision: https://reviews.llvm.org/D149565
2023-04-28[lldb] Refactor host::OpenFileInExternalEditorJonas Devlieghere
This patch refactors the macOS implementation of OpenFileInExternalEditor. It fixes an AppleEvent memory leak, the caching of LLDB_EXTERNAL_EDITOR and speculatively fixes a crash when CFURL is NULL (rdar://108633464). The new code also improves error handling, readability and documents calls to the CoreFoundation Launch Services APIs. A bunch of the Launch Services APIs have been deprecated (LSFindApplicationForInfo, LSOpenURLsWithRole). The preferred API is LSOpenCFURLRef but it doesn't specifying the "location" Apple Event which is used to highlight the current line and switching over would regress the existing behavior. rdar://108633464 Differential revision: https://reviews.llvm.org/D149482
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-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-04-07[lldb] Move "SelectMostRelevantFrame" from Thread::WillStopJim Ingham
SelectMostRelevantFrame triggers the StackFrameRecognizer construction, which can run arbitrary Python code, call expressions etc. WillStop gets called on every private stop while the recognizers are a user-facing feature, so first off doing this work on every stop is inefficient. But more importantly, you can get in to situations where the recognizer causes an expression to get run, then when we fetch the stop event at the end of the expression evaluation, we call WillStop again on the expression handling thread, which will do the same StackFrameRecognizer work again. If anyone is locking along that path, you will end up with a deadlock between the two threads. The example that brought this to my attention was the objc_exception_throw recognizer which can cause the objc runtime introspection functions to get run, and those take a lock in AppleObjCRuntimeV2::DynamicClassInfoExtractor::UpdateISAToDescriptorMap along this path, so the second thread servicing the expression deadlocks against the first thread waiting for the expression to complete. It makes more sense to have the frame recognizers run on demand, either when someone asks for the variables for the frame, or when someone does GetSelectedFrame. The former already worked that way, the only reason this was being done in WillStop was because the StackFrameRecognizers can change the SelectedFrame, so you needed to run them before the anyone requested the SelectedFrame. This patch moves SelectMostRelevantFrame to StackFrameList, and runs it when GetSelectedFrame is called for the first time on a given stop. If you call SetSelectedFrame before GetSelectedFrame, then you should NOT run the recognizer & change the frame out from under you. This patch also makes that work. There were already tests for this behavior, and for the feature that caused the hang, but the hang is racy, and it doesn't trigger all the time, so I don't have a way to test that explicitly. One more detail: it's actually pretty easy to end up calling GetSelectedFrame, for instance if you ask for the best ExecutionContext from an ExecutionContextRef it will fill the StackFrame with the result of GetSelectedFrame and that would still have the same problems if this happens on the Private State Thread. So this patch also short-circuits SelectMostRelevantFrame if run on the that thread. I can't think of any reason the computations that go on on the Private State Thread would actually want the SelectedFrame - that's a user-facing concept, so avoiding that complication is the best way to go. rdar://107643231 Differential revision: https://reviews.llvm.org/D147753
2023-03-20Revert "Fix a problem with "watchpoint triggers before" watchpoint handling."Jim Ingham
This reverts commit 8d024a79ea783ed3fbb5691aeaf186ad3f0a4ae9. I accidentally included some "in progress" work that wasn't supposed to go with this commit.
2023-03-20Fix a problem with "watchpoint triggers before" watchpoint handling.Jim Ingham
We need to step the watchpoint instruction in these cases, but the when we queued the ThreadPlanStepOverWatchpoint to do this, we didn't make it a Controlling plan. So if you are stepping, this plan returns as though it were a utility plan, and the stepping plan keeps going. This only partially fixes the problem on Darwin; there's another bug with reporting a watchpoint when we're instruction single stepping over an instruction that triggers a watchpoint. The kernel reports the "single step completed" but not the watchpoint hit. So this commit also refactors the test into a part that works (at least on Darwin) and a part that still fails. We may have to adjust the test result expectations for other systems after this fix. Differential Revision: https://reviews.llvm.org/D146337
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
2023-01-04[lldb] Remove unneeded .get() NFCFangrui Song
2022-12-19Revert "[lldb] Remove redundant .c_str() and .get() calls"Muhammad Omair Javaid
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 Song
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-17[lldb] llvm::Optional::value() && => operator*/operator->Fangrui Song
std::optional::value() has undesired exception checking semantics and is unavailable in older Xcode (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). The call sites block std::optional migration.
2022-12-13Launch state discoverable in Darwin, use for SafeToCallFunctionsJason Molenda
The dynamic linker on Darwin, dyld, can provide status of the process state for a few significant points early on, most importantly, when libSystem has been initialized and it is safe to call functions behind the scenes. Pipe this information up from debugserver to DynamicLoaderMacOS, for the DynamicLoader::IsFullyInitialized() method, then have Thread::SafeToCallFunctions use this information. Finally, for the two utility functions in the AppleObjCRuntimeV2 LanguageRuntime plugin that I was fixing, call this method before running our utility functions to collect the list of objc classes registered in the runtime. User expressions will still be allowed to run any time - we assume the user knows what they are doing - but these two additional utility functions that they are unaware of will be limited by this state. Differential Revision: https://reviews.llvm.org/D139054 rdar://102436092 can probably make function calls.
2022-08-05Reapply the commits to enable accurate hit-count detection for watchpoints.Jim Ingham
This commit combines the initial commit (7c240de609af), a fix for x86_64 Linux (3a0581501e76) and a fix for thinko in a last minute rewrite that I really should have run the testsuite on. Also, make sure that all the "I need to step over watchpoint" plans execute before we call a public stop. Otherwise, e.g. if you have N watchpoints and a Signal, the signal stop info will get us to stop with the watchpoints in a half-done state. Differential Revision: https://reviews.llvm.org/D130674
2022-07-15Use value instead of getValue (NFC)Kazu Hirata
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata
2022-04-05[lldb][gui] make 'step out' step out of the selected frameLuboš Luňák
Differential Revision: https://reviews.llvm.org/D123001
2022-03-10[lldb] Call ThreadPlan::DiscardPlan from Thread::DiscardPlanDave Lee
Correct `Thread::DiscardPlan` to call `DiscardPlan` instead of `PopPlan`. Differential Revision: https://reviews.llvm.org/D96655
2022-03-10[lldb] Remove extra space in step logging messageDave Lee
When seeing the extra space in the log, it wasn't clear if there was a missing printf argument. Removing the extra space removes the potential confusion.
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-28[lldb] [gdb-remote] Support getting siginfo via APIMichał Górny
Add Thread::GetSiginfo() and SBThread::GetSiginfo() methods to retrieve the siginfo value from server. Differential Revision: https://reviews.llvm.org/D118055
2022-01-02Remove redundant void arguments (NFC)Kazu Hirata
Identified by modernize-redundant-void-arg.
2021-12-13[lldb] Clarify StructuredDataImpl ownershipPavel Labath
StructuredDataImpl ownership semantics is unclear at best. Various structures were holding a non-owning pointer to it, with a comment that the object is owned somewhere else. From what I was able to gather that "somewhere else" was the SBStructuredData object, but I am not sure that all created object eventually made its way there. (It wouldn't matter even if they did, as we are leaking most of our SBStructuredData objects.) Since StructuredDataImpl is just a collection of two (shared) pointers, there's really no point in elaborate lifetime management, so this patch replaces all StructuredDataImpl pointers with actual objects or unique_ptrs to it. This makes it much easier to resolve SBStructuredData leaks in a follow-up patch. Differential Revision: https://reviews.llvm.org/D114791
2021-11-11[lldb][NFC] Inclusive Language: rename master plan to controlling planQuinn Pham
[NFC] As part of using inclusive language within the llvm project, this patch renames master plan to controlling plan in lldb. Reviewed By: jingham Differential Revision: https://reviews.llvm.org/D113019
2021-10-08[lldb] Remove shared_ptr from some global Properties objectsPavel Labath
they're unnecessary, make the code longer, and their removal actually ensures proper initialization in multithreaded scenarios.
2021-04-24[lldb] [gdb-remote server] Introduce new stop reasons for fork and vforkMichał Górny
Introduce three new stop reasons for fork, vfork and vforkdone events. This includes server support for serializing fork/vfork events into gdb-remote protocol. The stop infos for the two base events take a pair of PID and TID for the newly forked process. Differential Revision: https://reviews.llvm.org/D100196
2021-03-30[trace][intel-pt] Implement trace start and trace stopWalter Erquinigo
This implements the interactive trace start and stop methods. This diff ended up being much larger than I anticipated because, by doing it, I found that I had implemented in the beginning many things in a non optimal way. In any case, the code is much better now. There's a lot of boilerplate code due to the gdb-remote protocol, but the main changes are: - New tracing packets: jLLDBTraceStop, jLLDBTraceStart, jLLDBTraceGetBinaryData. The gdb-remote packet definitions are quite comprehensive. - Implementation of the "process trace start|stop" and "thread trace start|stop" commands. - Implementaiton of an API in Trace.h to interact with live traces. - Created an IntelPTDecoder for live threads, that use the debugger's stop id as checkpoint for its internal cache. - Added a functionality to stop the process in case "process tracing" is enabled and a new thread can't traced. - Added tests I have some ideas to unify the code paths for post mortem and live threads, but I'll do that in another diff. Differential Revision: https://reviews.llvm.org/D91679
2021-03-04[lldb] Rename QueueFundamentalPlan to QueueBasePlan (NFC)Dave Lee
Minor change for naming consistency. Differential Revision: https://reviews.llvm.org/D97985
2021-02-28[lldb/Interpreter] Fix deep copying for OptionValue classesTatyana Krasnukha
Some implementations of the DeepCopy function called the copy constructor that copied m_parent member instead of setting a new parent. Others just leaved the base class's members (m_parent, m_callback, m_was_set) empty. One more problem is that not all classes override this function, e.g. OptionValueArgs::DeepCopy produces OptionValueArray instance, and Target[Process/Thread]ValueProperty::DeepCopy produces OptionValueProperty. This makes downcasting via static_cast invalid. The patch implements idiom "virtual constructor" to fix these issues. Add a test that checks DeepCopy for correct copying/setting all data members of the base class. Differential Revision: https://reviews.llvm.org/D96952
2021-02-20[lldb] Refine ThreadPlan::ShouldAutoContinueDave Lee
Adjust `ShouldAutoContinue` to be available to any thread plan previous to the plan that explains a stop, not limited to the parent to the plan that explains the stop. Before this change, `Thread::ShouldStop` did the following: 1. find the plan that explains the stop 2. if it's not a master plan, continue processing previous (aka parent) plans 3. first, call `ShouldAutoContinue` on the immediate parent of the explaining plan 4. then loop over previous plans, calling `ShouldStop` and `MischiefManaged` Of note, the iteration in step 4 does not call `ShouldAutoContinue`, so again only the plan just prior to the explaining plan is given the opportunity to override whether to continue or stop. This commit changes the loop call `ShouldAutoContinue`, giving each plan the opportunity to override `ShouldStop` of previous plans. Why? This allows a plan to do the following: 1. mark itself done and be popped off the stack 2. allow parent plans to finish their work, and to also be popped off the stack 3. and finally, have the thread continue, not stop This is useful for stepping into async functions. A plan will would step far enough enough to set a breakpoint on the async target, and then use `ShouldAutoContinue` to unwind the necessary stepping, and then have the calling thread continue. Differential Revision: https://reviews.llvm.org/D97076
2021-02-19[lldb] Rename {stop,run}_vote to report_{stop,run}_voteDave Lee
Rename `stop_vote` and `run_vote` to `report_stop_vote` and `report_run_vote` respectively. These variables are limited to logic involving (event) reporting only. This naming is intended to make their context more clear. Differential Revision: https://reviews.llvm.org/D96917
2021-02-15[lldb] Remove unused ThreadPlan tracer utilities (NFC)Dave Lee
Delete unused `EnableTracer()` and `SetTracer()` functions on `Thread`. By deleting these, their `ThreadPlan` counterparts also become unused. Then, by deleting `ThreadPlanStack::EnableTracer`, `EnableSingleStep` becomes unused. With no more callers to `EnableSingleStep`, the value `m_single_step` is always true and can be removed as well. Differential Revision: https://reviews.llvm.org/D96666
2021-02-15[lldb] Minor refinements to ThreadPlan::RestoreThreadState (NFC)Dave Lee
Correct `RestoreThreadState` to a `void` return type. Also, update the signature of its callee, `Thread::RestoreThreadStateFromCheckpoint`, by updating it to a `void` return type, and making it non-`virtual`. Differential Revision: https://reviews.llvm.org/D96688
2021-02-11[lldb] Add step target to ThreadPlanStepInRange constructorDave Lee
`QueueThreadPlanForStepInRange` accepts a `step_into_target`, but the constructor for `ThreadPlanStepInRange` does not. Instead, a caller would optionally call `SetStepInTarget()` in a separate statement. This change adds `step_into_target` as a constructor argument. This simplifies construction of `ThreadPlanSP`, by avoiding a subsequent downcast and conditional assignment. This constructor is already used in downstream repos. Differential Revision: https://reviews.llvm.org/D96539
2020-08-11[lldb][NFC] Fix warning in Thread::AutoCompleteThreadPlansRaphael Isemann
2020-08-11[lldb] tab completion for `thread plan discard`Gongyu Deng
Dedicated completion for the command `thread plan discard` with a corresponding test case. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D83234
2020-08-07Add a setting to force stepping to always run all threads.Jim Ingham
Also allow ScriptedThreadPlans to set & get their StopOthers state. <rdar://problem/64229484> Differential Revision: https://reviews.llvm.org/D85265
2020-07-30[lldb] Don't use static locals for return value storage in some *AsCString ↵Raphael Isemann
functions Let's just return a std::string to make this safe. formatv seemed overkill for formatting the return values as they all just append an integer value to a constant string. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D84505
2020-06-24[lldb] Use std::make_unique<> (NFC)Jonas Devlieghere
Update the rest of lldb to use std::make_unique<>. I used clang-tidy to automate this, which probably missed cases that are wrapped in ifdefs.
2020-05-22Print a warning when stopped in a frame LLDB has no plugin for.Adrian Prantl
This patchs adds an optional warning that is printed when stopped at a frame that was compiled in a source language that LLDB has no plugin for. The motivational use-case is debugging Swift code on Linux. When the user accidentally invokes the system LLDB that was built without the Swift plugin, it is very much non-obvious why debugging doesnt work. This warning makes it easy to figure out what went wrong. <rdar://problem/56986569>
2020-05-21Rename FunctionOptimizationWarning to the more generic FrameSelectedCallback ↵Adrian Prantl
(NFC)
2020-05-14 [lldb] Update stop info override callback comment.Ryan Mansfield
In D31172 GetStopInfoOverrideCallback was moved and renamed. Differential revision: https://reviews.llvm.org/D79953
2020-04-03Allow the ThreadPlanStackMap to hold the thread plans for threadsJim Ingham
that were not reported by the OS plugin. To facilitate this, move adding/updating the ThreadPlans for a Thread to the ThreadPlanStackMap. Also move dumping thread plans there as well. Added some tests for "thread plan list" and "thread plan discard" since I didn't seem to have written any originally. Differential Revision: https://reviews.llvm.org/D76814
2020-04-03Move thread plan stacks into the Process, indexed by TID.Jim Ingham
Differential Revision: https://reviews.llvm.org/D75880