public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Jan Vrany <jan.vrany@fit.cvut.cz>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@fit.cvut.cz>
Subject: [RFC 1/2] gdb: add new observables target_connected and target_disconnected
Date: Sun, 14 Oct 2018 12:56:00 -0000	[thread overview]
Message-ID: <20181014125534.11724-2-jan.vrany@fit.cvut.cz> (raw)
In-Reply-To: <20181014125534.11724-1-jan.vrany@fit.cvut.cz>

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(+)

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;
 }
 
-- 
2.19.1

  reply	other threads:[~2018-10-14 12:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-14 12:55 [RFC 0/2] add new async events =target-connected and =target-disconnected Jan Vrany
2018-10-14 12:56 ` Jan Vrany [this message]
2018-10-14 12:56 ` [RFC 2/2] gdb/mi: " Jan Vrany
2018-10-14 15:02   ` Eli Zaretskii
2018-10-18  1:31   ` Simon Marchi
2018-11-22 14:20     ` Jan Vrany

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181014125534.11724-2-jan.vrany@fit.cvut.cz \
    --to=jan.vrany@fit.cvut.cz \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).