@@ -569,6 +569,16 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
569
569
SetDestroyCallback (lldb_private::DebuggerDestroyCallback destroy_callback,
570
570
void *baton);
571
571
572
+ // / Add a callback for when the debugger is created. Return a token, which
573
+ // / can be used to remove said callback. Multiple callbacks can be added by
574
+ // / calling this function multiple times, and will be invoked in FIFO order.
575
+ static lldb::callback_token_t
576
+ AddCreateCallback (lldb_private::DebuggerCreateCallback create_callback,
577
+ void *baton, void *original_callback);
578
+
579
+ // / Remove the specified callback. Return true if successful.
580
+ static bool RemoveCreateCallback (lldb::callback_token_t token);
581
+
572
582
// / Add a callback for when the debugger is destroyed. Return a token, which
573
583
// / can be used to remove said callback. Multiple callbacks can be added by
574
584
// / calling this function multiple times, and will be invoked in FIFO order.
@@ -737,19 +747,32 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
737
747
lldb::TargetSP m_dummy_target_sp;
738
748
Diagnostics::CallbackID m_diagnostics_callback_id;
739
749
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)
750
+ template <typename T> struct CallbackInfo {
751
+ CallbackInfo () {}
752
+ CallbackInfo (lldb::callback_token_t token, T callback, void *baton)
747
753
: token(token), callback(callback), baton(baton) {}
748
754
lldb::callback_token_t token;
749
- lldb_private::DebuggerDestroyCallback callback;
755
+ T callback;
750
756
void *baton;
751
757
};
752
- llvm::SmallVector<DestroyCallbackInfo, 2 > m_destroy_callbacks;
758
+ template <typename T, typename ExtraT>
759
+ struct CallbackInfoExtraData : public CallbackInfo <T> {
760
+ CallbackInfoExtraData () {}
761
+ CallbackInfoExtraData (lldb::callback_token_t token, T callback, void *baton,
762
+ ExtraT extra_data)
763
+ : CallbackInfo<T>(token, callback, baton), extra_data(extra_data) {}
764
+ ExtraT extra_data;
765
+ };
766
+ static std::mutex s_create_callback_mutex;
767
+ static lldb::callback_token_t s_create_callback_next_token;
768
+ static llvm::SmallVector<
769
+ CallbackInfoExtraData<lldb_private::DebuggerCreateCallback, void *>, 2 >
770
+ s_create_callbacks;
771
+
772
+ std::mutex m_destroy_callback_mutex;
773
+ lldb::callback_token_t m_destroy_callback_next_token = 0 ;
774
+ llvm::SmallVector<CallbackInfo<lldb_private::DebuggerDestroyCallback>, 2 >
775
+ m_destroy_callbacks;
753
776
754
777
uint32_t m_interrupt_requested = 0 ; // /< Tracks interrupt requests
755
778
std::mutex m_interrupt_mutex;
0 commit comments