From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 32F3B3865C28; Mon, 14 Mar 2022 13:53:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32F3B3865C28 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Replace deprecated_target_wait_hook by observers X-Act-Checkin: binutils-gdb X-Git-Author: Patrick Monnerat X-Git-Refname: refs/heads/master X-Git-Oldrev: 79a0742380b5304c734ce6f4359d437325cc7121 X-Git-Newrev: fb85cece22a2cb3c0185e61cfc1323e9c5a6466e Message-Id: <20220314135345.32F3B3865C28@sourceware.org> Date: Mon, 14 Mar 2022 13:53:45 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Mar 2022 13:53:45 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dfb85cece22a2= cb3c0185e61cfc1323e9c5a6466e commit fb85cece22a2cb3c0185e61cfc1323e9c5a6466e Author: Patrick Monnerat Date: Sat Mar 12 13:41:47 2022 +0100 Replace deprecated_target_wait_hook by observers =20 Commit b60cea7 (Make target_wait options use enum flags) broke deprecated_target_wait_hook usage: there's a commit comment telling this hook has not been converted. =20 Rather than trying to mend it, this patch replaces the hook by two target_wait observers: =20 target_pre_wait (ptid_t ptid) target_post_wait (ptid_t event_ptid) =20 Upon target_wait entry, target_pre_wait is notified with the ptid passed to target_wait. Upon exit, target_post_wait is notified with the event ptid returned by target_wait. Should an exception occur, event_ptid is null_ptid. =20 This change benefits to Insight (out-of-tree): there's no real use of t= he late hook in gdb itself. Diff: --- gdb/infrun.c | 15 +++------------ gdb/infrun.h | 5 ++--- gdb/interps.c | 1 - gdb/observable.c | 2 ++ gdb/observable.h | 6 ++++++ gdb/target.c | 14 +++++++++++++- gdb/top.c | 7 ------- 7 files changed, 26 insertions(+), 24 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index e3c1db73749..bc6521c8ec6 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -367,7 +367,7 @@ show_stop_on_solib_events (struct ui_file *file, int fr= om_tty, static bool stop_print_frame; =20 /* This is a cached copy of the target/ptid/waitstatus of the last - event returned by target_wait()/deprecated_target_wait_hook(). + event returned by target_wait(). This information is returned by get_last_target_status(). */ static process_stratum_target *target_last_proc_target; static ptid_t target_last_wait_ptid; @@ -3515,7 +3515,6 @@ static ptid_t do_target_wait_1 (inferior *inf, ptid_t ptid, target_waitstatus *status, target_wait_flags options) { - ptid_t event_ptid; struct thread_info *tp; =20 /* We know that we are looking for an event in the target of inferior @@ -3630,12 +3629,7 @@ do_target_wait_1 (inferior *inf, ptid_t ptid, if (!target_can_async_p ()) options &=3D ~TARGET_WNOHANG; =20 - if (deprecated_target_wait_hook) - event_ptid =3D deprecated_target_wait_hook (ptid, status, options); - else - event_ptid =3D target_wait (ptid, status, options); - - return event_ptid; + return target_wait (ptid, status, options); } =20 /* Wrapper for target_wait that first checks whether threads have @@ -4591,10 +4585,7 @@ poll_one_curr_target (struct target_waitstatus *ws) don't get any event. */ target_dcache_invalidate (); =20 - if (deprecated_target_wait_hook) - event_ptid =3D deprecated_target_wait_hook (minus_one_ptid, ws, TARGET= _WNOHANG); - else - event_ptid =3D target_wait (minus_one_ptid, ws, TARGET_WNOHANG); + event_ptid =3D target_wait (minus_one_ptid, ws, TARGET_WNOHANG); =20 if (debug_infrun) print_target_wait_results (minus_one_ptid, event_ptid, *ws); diff --git a/gdb/infrun.h b/gdb/infrun.h index 3e84805accb..1209b4188e9 100644 --- a/gdb/infrun.h +++ b/gdb/infrun.h @@ -124,9 +124,8 @@ extern process_stratum_target *user_visible_resume_targ= et (ptid_t resume_ptid); extern int normal_stop (void); =20 /* Return the cached copy of the last target/ptid/waitstatus returned - by target_wait()/deprecated_target_wait_hook(). The data is - actually cached by handle_inferior_event(), which gets called - immediately after target_wait()/deprecated_target_wait_hook(). */ + by target_wait(). The data is actually cached by handle_inferior_event= (), + which gets called immediately after target_wait(). */ extern void get_last_target_status (process_stratum_target **target, ptid_t *ptid, struct target_waitstatus *status); diff --git a/gdb/interps.c b/gdb/interps.c index a475d8790c9..b8df3d781e7 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -357,7 +357,6 @@ clear_interpreter_hooks (void) deprecated_readline_hook =3D 0; deprecated_readline_end_hook =3D 0; deprecated_context_hook =3D 0; - deprecated_target_wait_hook =3D 0; deprecated_call_command_hook =3D 0; deprecated_error_begin_hook =3D 0; } diff --git a/gdb/observable.c b/gdb/observable.c index 78f315793b6..afe81394594 100644 --- a/gdb/observable.c +++ b/gdb/observable.c @@ -79,6 +79,8 @@ DEFINE_OBSERVABLE (styling_changed); DEFINE_OBSERVABLE (current_source_symtab_and_line_changed); DEFINE_OBSERVABLE (gdb_exiting); DEFINE_OBSERVABLE (connection_removed); +DEFINE_OBSERVABLE (target_pre_wait); +DEFINE_OBSERVABLE (target_post_wait); =20 } /* namespace observers */ } /* namespace gdb */ diff --git a/gdb/observable.h b/gdb/observable.h index 0cdf4767f04..f426c1a761f 100644 --- a/gdb/observable.h +++ b/gdb/observable.h @@ -256,6 +256,12 @@ extern observable gdb_exiting; /* When a connection is removed. */ extern observable connection_removed; =20 +/* About to enter target_wait (). */ +extern observable target_pre_wait; + +/* About to leave target_wait (). */ +extern observable target_post_wait; + } /* namespace observers */ =20 } /* namespace gdb */ diff --git a/gdb/target.c b/gdb/target.c index 658698b4e2b..e3df9275c9a 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -26,6 +26,7 @@ #include "symtab.h" #include "inferior.h" #include "infrun.h" +#include "observable.h" #include "bfd.h" #include "symfile.h" #include "objfiles.h" @@ -2609,7 +2610,18 @@ target_wait (ptid_t ptid, struct target_waitstatus *= status, if (!target_can_async_p (target)) gdb_assert ((options & TARGET_WNOHANG) =3D=3D 0); =20 - return target->wait (ptid, status, options); + try + { + gdb::observers::target_pre_wait.notify (ptid); + ptid_t event_ptid =3D target->wait (ptid, status, options); + gdb::observers::target_post_wait.notify (event_ptid); + return event_ptid; + } + catch (...) + { + gdb::observers::target_post_wait.notify (null_ptid); + throw; + } } =20 /* See target.h. */ diff --git a/gdb/top.c b/gdb/top.c index a94ed5cebdb..7831b4f96ca 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -247,13 +247,6 @@ void (*deprecated_readline_end_hook) (void); void (*deprecated_attach_hook) (void); void (*deprecated_detach_hook) (void); =20 -/* Called when going to wait for the target. Usually allows the GUI - to run while waiting for target events. */ - -ptid_t (*deprecated_target_wait_hook) (ptid_t ptid, - struct target_waitstatus *status, - int options); - /* Used by UI as a wrapper around command execution. May do various things like enabling/disabling buttons, etc... */