@@ -569,6 +569,18 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
569569 SetDestroyCallback (lldb_private::DebuggerDestroyCallback destroy_callback,
570570 void *baton);
571571
572+ // / Add a notification callback when notification type event happens. Return a
573+ // / token, which can be used to remove said callback. Multiple callbacks can
574+ // / be added by calling this function multiple times, and will be invoked in
575+ // / FIFO order.
576+ static lldb::callback_token_t AddNotificationCallback (
577+ lldb::NotificationType type,
578+ lldb_private::NotificationCallback notification_callback, void *baton,
579+ void *original_callback);
580+
581+ // / Remove the specified callback. Return true if successful.
582+ static bool RemoveNotificationCallback (lldb::callback_token_t token);
583+
572584 // / Add a callback for when the debugger is destroyed. Return a token, which
573585 // / can be used to remove said callback. Multiple callbacks can be added by
574586 // / calling this function multiple times, and will be invoked in FIFO order.
@@ -683,6 +695,9 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
683695
684696 void InstanceInitialize ();
685697
698+ static void InvokeNotificationCallbacks (lldb::DebuggerSP debugger_sp,
699+ lldb::NotificationType notify_type);
700+
686701 // these should never be NULL
687702 lldb::FileSP m_input_file_sp;
688703 lldb::StreamFileSP m_output_stream_sp;
@@ -737,19 +752,35 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
737752 lldb::TargetSP m_dummy_target_sp;
738753 Diagnostics::CallbackID m_diagnostics_callback_id;
739754
740- std::mutex m_destroy_callback_mutex;
741- lldb::callback_token_t m_destroy_callback_next_token = 0 ;
742- struct DestroyCallbackInfo {
743- DestroyCallbackInfo () {}
744- DestroyCallbackInfo (lldb::callback_token_t token,
745- lldb_private::DebuggerDestroyCallback callback,
746- void *baton)
755+ template <typename T> struct CallbackInfo {
756+ CallbackInfo () {}
757+ CallbackInfo (lldb::callback_token_t token, T callback, void *baton)
747758 : token(token), callback(callback), baton(baton) {}
748759 lldb::callback_token_t token;
749- lldb_private::DebuggerDestroyCallback callback;
760+ T callback;
750761 void *baton;
751762 };
752- llvm::SmallVector<DestroyCallbackInfo, 2 > m_destroy_callbacks;
763+ template <typename T>
764+ struct NotificationCallbackInfo : public CallbackInfo <T> {
765+ NotificationCallbackInfo () {}
766+ NotificationCallbackInfo (lldb::callback_token_t token,
767+ lldb::NotificationType type, T callback,
768+ void *baton, void *original_callback)
769+ : CallbackInfo<T>(token, callback, baton), type(type),
770+ original_callback (original_callback) {}
771+ lldb::NotificationType type;
772+ void *original_callback;
773+ };
774+ static std::mutex s_notification_callback_mutex;
775+ static lldb::callback_token_t s_notification_callback_next_token;
776+ static llvm::SmallVector<
777+ NotificationCallbackInfo<lldb_private::NotificationCallback>, 2 >
778+ s_notification_callbacks;
779+
780+ std::mutex m_destroy_callback_mutex;
781+ lldb::callback_token_t m_destroy_callback_next_token = 0 ;
782+ llvm::SmallVector<CallbackInfo<lldb_private::DebuggerDestroyCallback>, 2 >
783+ m_destroy_callbacks;
753784
754785 uint32_t m_interrupt_requested = 0 ; // /< Tracks interrupt requests
755786 std::mutex m_interrupt_mutex;
0 commit comments