From c90e7d6352b2e16ac007d08b2e03ae10081147b5 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sat, 24 Apr 2021 19:26:04 -0400 Subject: gdbsupport, gdb: give names to observers Give a name to each observer, this will help produce more meaningful debug message. gdbsupport/ChangeLog: * observable.h (class observable) : Add name parameter. : New field. : Add name parameter, update all callers. Change-Id: Ie0cc4664925215b8d2b09e026011b7803549fba0 --- gdbsupport/ChangeLog | 7 +++++++ gdbsupport/observable.h | 23 +++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'gdbsupport') diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog index bfbd152..0f3de6d 100644 --- a/gdbsupport/ChangeLog +++ b/gdbsupport/ChangeLog @@ -1,5 +1,12 @@ 2021-04-24 Simon Marchi + * observable.h (class observable) : + Add name parameter. + : New field. + : Add name parameter, update all callers. + +2021-04-24 Simon Marchi + * observable.h (class observable) : New. : Update. : Change type to vector of observers. diff --git a/gdbsupport/observable.h b/gdbsupport/observable.h index 1d19429..5e7846f 100644 --- a/gdbsupport/observable.h +++ b/gdbsupport/observable.h @@ -61,12 +61,13 @@ public: private: struct observer { - observer (const struct token *token, func_type func) - : token (token), func (func) + observer (const struct token *token, func_type func, const char *name) + : token (token), func (func), name (name) {} const struct token *token; func_type func; + const char *name; }; public: @@ -78,17 +79,23 @@ public: DISABLE_COPY_AND_ASSIGN (observable); /* Attach F as an observer to this observable. F cannot be - detached. */ - void attach (const func_type &f) + detached. + + NAME is the name of the observer, used for debug output purposes. Its + lifetime must be at least as long as the observer is attached. */ + void attach (const func_type &f, const char *name) { - m_observers.emplace_back (nullptr, f); + m_observers.emplace_back (nullptr, f, name); } /* Attach F as an observer to this observable. T is a reference to - a token that can be used to later remove F. */ - void attach (const func_type &f, const token &t) + a token that can be used to later remove F. + + NAME is the name of the observer, used for debug output purposes. Its + lifetime must be at least as long as the observer is attached. */ + void attach (const func_type &f, const token &t, const char *name) { - m_observers.emplace_back (&t, f); + m_observers.emplace_back (&t, f, name); } /* Remove observers associated with T from this observable. T is -- cgit v1.1