public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 7/9] gdb: pass more arguments to the executable_changed observer
Date: Sat, 16 Sep 2023 11:18:08 +0100	[thread overview]
Message-ID: <ec22b26ea4c99b068f574724063366f418334b8d.1694858967.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1694858967.git.aburgess@redhat.com>

This commit continues the work of the previous few commits.

My goal is to expose the executable_changed observer through the
Python API as an event.

At this point adding executable_changed as an event to the Python API
is trivial, but before I do that I would like to add some additional
arguments to the observable, which currently has no arguments at all.

The new arguments I wish to add are:

 1. The program_space in which the executable was changed, and

 2. A boolean flag that will indicate if the executable changed to a
 whole new path, or if GDB just spotted that the executable changed on
 disk (e.g. the user recompiled the executable).

In this commit I change the signature of the observable and then pass
the arguments through at the one place where this observable is
notified.

As there are (currently) no users of this observable nothing else
needs updating.  In the next commit I'll add a listener for this
observable in the Python code, and expose this as an event in the
Python API.

Additionally, with this change, it should be possible to update the
insight debugger to make use of this observable rather than using the
deprecated_exec_file_display_hook (as it currently does), which will
then allow this hook to be removed from GDB.

There should be no user visible changes after this commit.
---
 gdb/exec.c       | 11 ++++++++++-
 gdb/observable.h | 18 +++++++++++++-----
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/gdb/exec.c b/gdb/exec.c
index 07759725711..a1396c2aa3d 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -501,7 +501,16 @@ exec_file_attach (const char *filename, int from_tty)
     }
 
   bfd_cache_close_all ();
-  gdb::observers::executable_changed.notify ();
+
+  /* Are are loading the same executable?  */
+  bfd *prev_bfd = exec_bfd_holder.get ();
+  bfd *curr_bfd = current_program_space->exec_bfd ();
+  bool reload_p = (((prev_bfd != nullptr) == (curr_bfd != nullptr))
+		   && (prev_bfd == nullptr
+		       || (strcmp (bfd_get_filename (prev_bfd),
+				   bfd_get_filename (curr_bfd)) == 0)));
+
+  gdb::observers::executable_changed.notify (current_program_space, reload_p);
 }
 
 /*  Process the first arg in ARGS as the new exec file.
diff --git a/gdb/observable.h b/gdb/observable.h
index c0bafc51f14..e5305fa081e 100644
--- a/gdb/observable.h
+++ b/gdb/observable.h
@@ -31,6 +31,7 @@ struct inferior;
 struct process_stratum_target;
 struct target_ops;
 struct trace_state_variable;
+struct program_space;
 
 namespace gdb
 {
@@ -60,11 +61,18 @@ extern observable<enum gdb_signal /* siggnal */> signal_received;
 /* The target's register contents have changed.  */
 extern observable<struct target_ops */* target */> target_changed;
 
-/* The executable being debugged by GDB has changed: The user
-   decided to debug a different program, or the program he was
-   debugging has been modified since being loaded by the debugger
-   (by being recompiled, for instance).  */
-extern observable<> executable_changed;
+/* The executable being debugged by GDB in PSPACE has changed: The user
+   decided to debug a different program, or the program he was debugging
+   has been modified since being loaded by the debugger (by being
+   recompiled, for instance).  The path to the new executable can be found
+   by examining PSPACE->exec_filename.
+
+   When RELOAD is true the path to the executable hasn't changed, but the
+   file does appear to have changed, so GDB reloaded it, e.g. if the user
+   recompiled the executable.  when RELOAD is false then the path to the
+   executable has not changed.  */
+extern observable<struct program_space */* pspace */,
+		  bool /*reload */> executable_changed;
 
 /* gdb has just connected to an inferior.  For 'run', gdb calls this
    observer while the inferior is still stopped at the entry-point
-- 
2.25.4


  parent reply	other threads:[~2023-09-16 10:18 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-16 10:18 [PATCH 0/9] Add executable_changed event to Python API Andrew Burgess
2023-09-16 10:18 ` [PATCH 1/9] gdb/doc: extend the description for Progspace.filename Andrew Burgess
2023-09-16 10:53   ` Eli Zaretskii
2023-09-16 10:18 ` [PATCH 2/9] gdb/python: new Progspace.symbol_file attribute Andrew Burgess
2023-09-16 10:56   ` Eli Zaretskii
2023-09-16 10:18 ` [PATCH 3/9] gdb/python: new Progspace.executable_filename attribute Andrew Burgess
2023-09-16 10:55   ` Eli Zaretskii
2023-09-16 10:18 ` [PATCH 4/9] gdb: remove one user of the executable changed observer Andrew Burgess
2023-09-16 10:18 ` [PATCH 5/9] gdb: remove final user of the executable_changed observer Andrew Burgess
2023-09-16 10:18 ` [PATCH 6/9] gdb: remove unnecessary notification of " Andrew Burgess
2023-09-16 10:18 ` Andrew Burgess [this message]
2023-09-16 10:18 ` [PATCH 8/9] gdb/python: make the executable_changed event available from Python Andrew Burgess
2023-09-16 11:03   ` Eli Zaretskii
2023-09-28 14:35     ` Andrew Burgess
2023-09-16 10:18 ` [PATCH 9/9] gdb: use reopen_exec_file from reread_symbols Andrew Burgess
2023-09-19 14:08   ` Tom Tromey
2023-09-28 15:23     ` Andrew Burgess
2023-09-28 18:15       ` Tom Tromey
2023-09-29 10:17         ` Andrew Burgess
2023-09-29 15:18           ` Eli Zaretskii
2023-10-02 14:16           ` Tom Tromey
2023-09-29 14:42         ` Eli Zaretskii
2023-10-02 14:02           ` Tom Tromey
2023-10-02 16:19             ` Eli Zaretskii
2023-09-19 14:09 ` [PATCH 0/9] Add executable_changed event to Python API Tom Tromey

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=ec22b26ea4c99b068f574724063366f418334b8d.1694858967.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --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).