mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-23 03:29:47 +08:00
gdbsupport: add observer_debug_printf, OBSERVER_SCOPED_DEBUG_ENTER_EXIT
Switch observer to use the "new" debug printf mechanism and sprinkle a few debug prints. Here's a small example of the output with "infrun" and "observer" debug output enabled: [infrun] proceed: enter [observer] notify: start: observable target_resumed notify() called [observer] notify: start: calling observer mi-interp of observable target_resumed [observer] notify: end: calling observer mi-interp of observable target_resumed [observer] notify: start: calling observer py-inferior of observable target_resumed [observer] notify: end: calling observer py-inferior of observable target_resumed [observer] notify: end: observable target_resumed notify() called ... gdbsupport/ChangeLog: * observable.h (observer_debug_printf, OBSERVER_SCOPED_DEBUG_START_END): New. (class observable) <notify, attach>: Use them. Change-Id: If3ae4b6b65450ca3b7cae56698a87fc526688b86
This commit is contained in:
@ -1,3 +1,9 @@
|
|||||||
|
2021-04-24 Simon Marchi <simon.marchi@polymtl.ca>
|
||||||
|
|
||||||
|
* observable.h (observer_debug_printf,
|
||||||
|
OBSERVER_SCOPED_DEBUG_START_END): New.
|
||||||
|
(class observable) <notify, attach>: Use them.
|
||||||
|
|
||||||
2021-04-24 Simon Marchi <simon.marchi@polymtl.ca>
|
2021-04-24 Simon Marchi <simon.marchi@polymtl.ca>
|
||||||
|
|
||||||
* common-debug.h (struct scoped_debug_start_end)
|
* common-debug.h (struct scoped_debug_start_end)
|
||||||
|
@ -24,6 +24,16 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
/* Print an "observer" debug statement. */
|
||||||
|
|
||||||
|
#define observer_debug_printf(fmt, ...) \
|
||||||
|
debug_prefixed_printf_cond (observer_debug, "observer", fmt, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
/* Print "observer" start/end debug statements. */
|
||||||
|
|
||||||
|
#define OBSERVER_SCOPED_DEBUG_START_END(fmt, ...) \
|
||||||
|
scoped_debug_start_end (observer_debug, "observer", fmt, ##__VA_ARGS__)
|
||||||
|
|
||||||
namespace gdb
|
namespace gdb
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -85,6 +95,9 @@ public:
|
|||||||
lifetime must be at least as long as the observer is attached. */
|
lifetime must be at least as long as the observer is attached. */
|
||||||
void attach (const func_type &f, const char *name)
|
void attach (const func_type &f, const char *name)
|
||||||
{
|
{
|
||||||
|
observer_debug_printf ("Attaching observable %s to observer %s",
|
||||||
|
name, m_name);
|
||||||
|
|
||||||
m_observers.emplace_back (nullptr, f, name);
|
m_observers.emplace_back (nullptr, f, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +108,9 @@ public:
|
|||||||
lifetime must be at least as long as the observer is attached. */
|
lifetime must be at least as long as the observer is attached. */
|
||||||
void attach (const func_type &f, const token &t, const char *name)
|
void attach (const func_type &f, const token &t, const char *name)
|
||||||
{
|
{
|
||||||
|
observer_debug_printf ("Attaching observable %s to observer %s",
|
||||||
|
name, m_name);
|
||||||
|
|
||||||
m_observers.emplace_back (&t, f, name);
|
m_observers.emplace_back (&t, f, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,17 +126,23 @@ public:
|
|||||||
return o.token == &t;
|
return o.token == &t;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
observer_debug_printf ("Detaching observable %s from observer %s",
|
||||||
|
iter->name, m_name);
|
||||||
|
|
||||||
m_observers.erase (iter, m_observers.end ());
|
m_observers.erase (iter, m_observers.end ());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Notify all observers that are attached to this observable. */
|
/* Notify all observers that are attached to this observable. */
|
||||||
void notify (T... args) const
|
void notify (T... args) const
|
||||||
{
|
{
|
||||||
if (observer_debug)
|
OBSERVER_SCOPED_DEBUG_START_END ("observable %s notify() called", m_name);
|
||||||
fprintf_unfiltered (gdb_stdlog, "observable %s notify() called\n",
|
|
||||||
m_name);
|
|
||||||
for (auto &&e : m_observers)
|
for (auto &&e : m_observers)
|
||||||
e.func (args...);
|
{
|
||||||
|
OBSERVER_SCOPED_DEBUG_START_END ("calling observer %s of observable %s",
|
||||||
|
e.name, m_name);
|
||||||
|
e.func (args...);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user