[Lldb-commits] [lldb] Add SBDebugger:: AddNotificationCallback API (PR #111206)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 8 15:16:17 PDT 2024
================
@@ -737,19 +752,35 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
lldb::TargetSP m_dummy_target_sp;
Diagnostics::CallbackID m_diagnostics_callback_id;
- std::mutex m_destroy_callback_mutex;
- lldb::callback_token_t m_destroy_callback_next_token = 0;
- struct DestroyCallbackInfo {
- DestroyCallbackInfo() {}
- DestroyCallbackInfo(lldb::callback_token_t token,
- lldb_private::DebuggerDestroyCallback callback,
- void *baton)
+ template <typename T> struct CallbackInfo {
+ CallbackInfo() {}
+ CallbackInfo(lldb::callback_token_t token, T callback, void *baton)
: token(token), callback(callback), baton(baton) {}
lldb::callback_token_t token;
- lldb_private::DebuggerDestroyCallback callback;
+ T callback;
void *baton;
};
- llvm::SmallVector<DestroyCallbackInfo, 2> m_destroy_callbacks;
+ template <typename T>
+ struct NotificationCallbackInfo : public CallbackInfo<T> {
+ NotificationCallbackInfo() {}
+ NotificationCallbackInfo(lldb::callback_token_t token,
+ lldb::NotificationType type, T callback,
+ void *baton, void *original_callback)
+ : CallbackInfo<T>(token, callback, baton), type(type),
+ original_callback(original_callback) {}
+ lldb::NotificationType type;
+ void *original_callback;
+ };
+ static std::mutex s_notification_callback_mutex;
+ static lldb::callback_token_t s_notification_callback_next_token;
+ static llvm::SmallVector<
----------------
jimingham wrote:
Every action we perform with the notifications except for "deleting by token" knows the type of the notification that it's adding/looking up. We could even encode the type in the token and we'd always know. So it seems awkward to store them in a flat list. When we get around to listing these and other management tasks, those will very likely also be requests by type.
Maybe storing them in a map of type -> vector of callbacks for that type would be a better data structure here?
https://github.com/llvm/llvm-project/pull/111206
More information about the lldb-commits
mailing list