[Lldb-commits] [lldb] [lldb] Broadcast `eBroadcastBitStackChanged` when frame providers change (PR #171482)
Adrian Vogelsgesang via lldb-commits
lldb-commits at lists.llvm.org
Tue Dec 9 09:52:58 PST 2025
https://github.com/vogelsgesang created https://github.com/llvm/llvm-project/pull/171482
We want to reload the call stack whenever the frame providers are updated. To do so, we now emit a `eBroadcastBitStackChanged` on all threads whenever any changes to the frame providers take place.
I found this very useful while iterating on a frame provider in lldb-dap. So far, the new frame provider only took effect after continuing execution. Now the back trace in VS-Code gets refreshed immediately upon running `target frame-provider add`.
>From b42d2772a0646b0618e4709b4e2106bfadeb237f Mon Sep 17 00:00:00 2001
From: Adrian Vogelsgesang <avogelsgesang at salesforce.com>
Date: Tue, 9 Dec 2025 17:46:05 +0000
Subject: [PATCH] [lldb] Broadcast `eBroadcastBitStackChanged` when frame
providers change
We want to reload the call stack whenever the frame providers were
updated. To do so, we now emit a `eBroadcastBitStackChanged` on all
threads whenever any changes to the frame providers take place.
I found this very useful while iterating on a frame provider using
lldb-dap. So far, the new frame provider only took effect after
continuing execution. Now the back trace in VS-Code gets refreshed
immediately upon running `target frame-provider add`
---
lldb/include/lldb/Target/Target.h | 5 +++
lldb/source/Target/Target.cpp | 59 ++++++++++++++++++-------------
2 files changed, 40 insertions(+), 24 deletions(-)
diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h
index 812a638910b3b..6d1f5f83d153b 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -776,6 +776,11 @@ class Target : public std::enable_shared_from_this<Target>,
const llvm::DenseMap<uint32_t, ScriptedFrameProviderDescriptor> &
GetScriptedFrameProviderDescriptors() const;
+protected:
+ /// Notify all threads that the stack traces might have changed.
+ void NotifyThreadsOfChangedFrameProviders();
+
+public:
// This part handles the breakpoints.
BreakpointList &GetBreakpointList(bool internal = false);
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 2305f1019ea4f..fe8e41ec4d825 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -3725,47 +3725,43 @@ llvm::Expected<uint32_t> Target::AddScriptedFrameProviderDescriptor(
if (!descriptor.IsValid())
return llvm::createStringError("invalid frame provider descriptor");
+ uint32_t descriptor_id = descriptor.GetID();
+
llvm::StringRef name = descriptor.GetName();
if (name.empty())
return llvm::createStringError(
"frame provider descriptor has no class name");
- std::lock_guard<std::recursive_mutex> guard(
- m_frame_provider_descriptors_mutex);
-
- uint32_t descriptor_id = descriptor.GetID();
- m_frame_provider_descriptors[descriptor_id] = descriptor;
+ {
+ std::unique_lock<std::recursive_mutex> guard(m_frame_provider_descriptors_mutex);
+ m_frame_provider_descriptors[descriptor_id] = descriptor;
+ }
- // Clear frame providers on existing threads so they reload with new config.
- if (ProcessSP process_sp = GetProcessSP())
- for (ThreadSP thread_sp : process_sp->Threads())
- thread_sp->ClearScriptedFrameProvider();
+ NotifyThreadsOfChangedFrameProviders();
return descriptor_id;
}
bool Target::RemoveScriptedFrameProviderDescriptor(uint32_t id) {
- std::lock_guard<std::recursive_mutex> guard(
- m_frame_provider_descriptors_mutex);
- bool removed = m_frame_provider_descriptors.erase(id);
-
- if (removed)
- if (ProcessSP process_sp = GetProcessSP())
- for (ThreadSP thread_sp : process_sp->Threads())
- thread_sp->ClearScriptedFrameProvider();
+ bool removed;
+ {
+ std::lock_guard<std::recursive_mutex> guard(
+ m_frame_provider_descriptors_mutex);
+ removed = m_frame_provider_descriptors.erase(id);
+ }
+ if (removed) NotifyThreadsOfChangedFrameProviders();
return removed;
}
void Target::ClearScriptedFrameProviderDescriptors() {
- std::lock_guard<std::recursive_mutex> guard(
- m_frame_provider_descriptors_mutex);
-
- m_frame_provider_descriptors.clear();
+ {
+ std::lock_guard<std::recursive_mutex> guard(
+ m_frame_provider_descriptors_mutex);
+ m_frame_provider_descriptors.clear();
+ }
- if (ProcessSP process_sp = GetProcessSP())
- for (ThreadSP thread_sp : process_sp->Threads())
- thread_sp->ClearScriptedFrameProvider();
+ NotifyThreadsOfChangedFrameProviders();
}
const llvm::DenseMap<uint32_t, ScriptedFrameProviderDescriptor> &
@@ -3775,6 +3771,21 @@ Target::GetScriptedFrameProviderDescriptors() const {
return m_frame_provider_descriptors;
}
+void Target::NotifyThreadsOfChangedFrameProviders() {
+ ProcessSP process_sp = GetProcessSP();
+ if (!process_sp)
+ return;
+ for (ThreadSP thread_sp : process_sp->Threads()) {
+ // Clear frame providers on existing threads so they reload with new config.
+ thread_sp->ClearScriptedFrameProvider();
+ // Notify threads that the stack traces might have changed.
+ if (EventTypeHasListeners(Thread::eBroadcastBitStackChanged)) {
+ auto data_sp = std::make_shared<Thread::ThreadEventData>(thread_sp);
+ thread_sp->BroadcastEvent(Thread::eBroadcastBitStackChanged, data_sp);
+ }
+ }
+}
+
void Target::FinalizeFileActions(ProcessLaunchInfo &info) {
Log *log = GetLog(LLDBLog::Process);
More information about the lldb-commits
mailing list