From 5d549384811df0d4db34a7bf56db045eed9b2f5f Mon Sep 17 00:00:00 2001 From: Felipe de Azevedo Piovezan Date: Tue, 29 Jul 2025 11:15:01 -0700 Subject: [PATCH 1/2] [lldb] Clear Frames when changing `disable-language-runtime-unwindplans` This patch uses the "setting changed" callback to clear previously cached stack frames when `target.process.disable-language-runtime-unwindplans` is changed. This is necessary so that changing the setting followed by a `backtrace` command produces an accurate backtrace. With this, a user can create a custom command like below in order to quickly inspect a backtrace created without language plugins. ``` debugger.HandleCommand("settings set target.process.disable-language-runtime-unwindplans true") debugger.HandleCommand("bt " + command) debugger.HandleCommand("settings set target.process.disable-language-runtime-unwindplans false") ``` In the future, we may consider implementing this as an option to `backtrace`. Currently, this process setting is the only way of affecting the unwinder, and changing the process setting as part of the backtrace implementation doesn't feel right. There are no upstream users of this flag, so we cannot write a test for it here. --- lldb/include/lldb/Target/Process.h | 1 + lldb/source/Target/Process.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index 7e66e315a867c..dc75d98acea70 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -100,6 +100,7 @@ class ProcessProperties : public Properties { void SetStopOnSharedLibraryEvents(bool stop); bool GetDisableLangRuntimeUnwindPlans() const; void SetDisableLangRuntimeUnwindPlans(bool disable); + void DisableLanguageRuntimeUnwindPlansCallback(); bool GetDetachKeepsStopped() const; void SetDetachKeepsStopped(bool keep_stopped); bool GetWarningsOptimization() const; diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 2aa02fd58335e..385834795cb05 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -166,6 +166,9 @@ ProcessProperties::ProcessProperties(lldb_private::Process *process) m_collection_sp->SetValueChangedCallback( ePropertyPythonOSPluginPath, [this] { m_process->LoadOperatingSystemPlugin(true); }); + m_collection_sp->SetValueChangedCallback( + ePropertyDisableLangRuntimeUnwindPlans, + [this] { DisableLanguageRuntimeUnwindPlansCallback(); }); } m_experimental_properties_up = @@ -280,6 +283,13 @@ void ProcessProperties::SetDisableLangRuntimeUnwindPlans(bool disable) { m_process->Flush(); } +void ProcessProperties::DisableLanguageRuntimeUnwindPlansCallback() { + if (!m_process) + return; + for (auto thread_sp : m_process->Threads()) + thread_sp->ClearStackFrames(); +} + bool ProcessProperties::GetDetachKeepsStopped() const { const uint32_t idx = ePropertyDetachKeepsStopped; return GetPropertyAtIndexAs( From feb8bffb24cb0aed4958c4617dcb58df47c89bed Mon Sep 17 00:00:00 2001 From: Felipe de Azevedo Piovezan Date: Wed, 30 Jul 2025 18:39:39 -0700 Subject: [PATCH 2/2] fixup! Also discard thread plans --- lldb/source/Target/Process.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 385834795cb05..ff9e5fc12059e 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -286,8 +286,10 @@ void ProcessProperties::SetDisableLangRuntimeUnwindPlans(bool disable) { void ProcessProperties::DisableLanguageRuntimeUnwindPlansCallback() { if (!m_process) return; - for (auto thread_sp : m_process->Threads()) + for (auto thread_sp : m_process->Threads()) { thread_sp->ClearStackFrames(); + thread_sp->DiscardThreadPlans(/*force*/ true); + } } bool ProcessProperties::GetDetachKeepsStopped() const {