[RFC,1/2] gdb: add new observables target_connected and target_disconnected

Message ID 20181014125534.11724-2-jan.vrany@fit.cvut.cz
State New
Headers show
Series
  • add new async events =target-connected and =target-disconnected
Related show

Commit Message

Jan Vrany Oct. 14, 2018, 12:55 p.m.
Observers of these are notified whenver a target is connected or
disconnected.

gdb/ChangeLog:

	* observable.h: Define new observables target_connected and
	target_disconnected.
	* observable.c: Likewise.
	* target.c (target_stack::push, target_stack::unpush): Notify
	observers of target_connected and target_disconnected
---
 gdb/ChangeLog    | 8 ++++++++
 gdb/observable.c | 2 ++
 gdb/observable.h | 6 ++++++
 gdb/target.c     | 7 +++++++
 4 files changed, 23 insertions(+)

-- 
2.19.1

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b3cc64659f..d13ce2097d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@ 
+2018-07-03  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* observable.h: Define new observables target_connected and
+	target_disconnected.
+	* observable.c: Likewise.
+	* target.c (target_stack::push, target_stack::unpush): Notify
+	observers of target_connected and target_disconnected
+
 2018-10-11  Gary Benson <gbenson@redhat.com>
 
 	* interps.h (interp::m_name): Make private and mutable.
diff --git a/gdb/observable.c b/gdb/observable.c
index 5539b9837b..4b98612433 100644
--- a/gdb/observable.c
+++ b/gdb/observable.c
@@ -74,6 +74,8 @@  DEFINE_OBSERVABLE (inferior_call_pre);
 DEFINE_OBSERVABLE (inferior_call_post);
 DEFINE_OBSERVABLE (register_changed);
 DEFINE_OBSERVABLE (user_selected_context_changed);
+DEFINE_OBSERVABLE (target_connected);
+DEFINE_OBSERVABLE (target_disconnected);
 
 } /* namespace observers */
 } /* namespace gdb */
diff --git a/gdb/observable.h b/gdb/observable.h
index 34447b90bb..f1829db99f 100644
--- a/gdb/observable.h
+++ b/gdb/observable.h
@@ -228,6 +228,12 @@  extern observable<struct frame_info *, int> register_changed;
    frame has changed.  */
 extern observable<user_selected_what> user_selected_context_changed;
 
+/* A new target has been connected.  */
+extern observable<struct target_ops *> target_connected;
+
+/* A target has been disonnected.  */
+extern observable<struct target_ops *> target_disconnected;
+
 } /* namespace observers */
 
 } /* namespace gdb */
diff --git a/gdb/target.c b/gdb/target.c
index 2d98954b54..5c19afead9 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -50,6 +50,7 @@ 
 #include "terminal.h"
 #include <algorithm>
 #include <unordered_map>
+#include "observable.h"
 
 static void generic_tls_error (void) ATTRIBUTE_NORETURN;
 
@@ -644,6 +645,8 @@  target_stack::push (target_ops *t)
       target_ops *prev = m_stack[t->to_stratum];
       m_stack[t->to_stratum] = NULL;
       target_close (prev);
+
+      gdb::observers::target_disconnected.notify (t);
     }
 
   /* Now add the new one.  */
@@ -651,6 +654,8 @@  target_stack::push (target_ops *t)
 
   if (m_top < t->to_stratum)
     m_top = t->to_stratum;
+
+  gdb::observers::target_connected.notify (t);
 }
 
 /* See target.h.  */
@@ -701,6 +706,8 @@  target_stack::unpush (target_ops *t)
      implementation don't end up in T anymore.  */
   target_close (t);
 
+  gdb::observers::target_disconnected.notify (t);
+
   return true;
 }