[Lldb-commits] [lldb] Add SBDebugger:: AddNotificationCallback API (PR #111206)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 10 04:05:52 PDT 2024


================
@@ -739,16 +745,29 @@ DebuggerSP Debugger::CreateInstance(lldb::LogOutputCallback log_callback,
     g_debugger_list_ptr->push_back(debugger_sp);
   }
   debugger_sp->InstanceInitialize();
+
+  InvokeNotificationCallbacks(debugger_sp, lldb::eDebuggerWillBeCreated);
   return debugger_sp;
 }
 
+void Debugger::InvokeNotificationCallbacks(DebuggerSP debugger_sp,
+                                           lldb::NotificationType notify_type) {
+  std::lock_guard<std::mutex> guard(s_notification_callback_mutex);
+  for (const auto &callback_info : s_notification_callbacks) {
+    if ((callback_info.type & notify_type) == notify_type)
+      callback_info.callback(notify_type, debugger_sp, nullptr,
+                             callback_info.baton,
+                             callback_info.original_callback);
+  }
+}
+
 void Debugger::HandleDestroyCallback() {
   const lldb::user_id_t user_id = GetID();
   // Invoke and remove all the callbacks in an FIFO order. Callbacks which are
   // added during this loop will be appended, invoked and then removed last.
   // Callbacks which are removed during this loop will not be invoked.
   while (true) {
-    DestroyCallbackInfo callback_info;
+    CallbackInfo<DebuggerDestroyCallback> callback_info;
----------------
labath wrote:

How about treating the destroy callbacks as (legacy) synonyms for NotificationCallbacks of the "destroy" kind?

Basically, have `SBDebugger::AddDestroyCallback` do a `AddNotificationCallback(eDebuggerWillBeDestroyed, callback, baton)`

Then we could delete all of this code...

https://github.com/llvm/llvm-project/pull/111206


More information about the lldb-commits mailing list