aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2023-09-08 16:02:13 +0100
committerAndrew Burgess <aburgess@redhat.com>2023-09-28 15:33:13 +0100
commit063453b199e1291a03ee81c3422c31d7cca60af6 (patch)
tree8748bab017896c702225859e76a68e81d1f16ba4
parentaac60a978e2620037e4b034386cbc6ef65f8e4aa (diff)
downloadbinutils-063453b199e1291a03ee81c3422c31d7cca60af6.zip
binutils-063453b199e1291a03ee81c3422c31d7cca60af6.tar.gz
binutils-063453b199e1291a03ee81c3422c31d7cca60af6.tar.bz2
gdb: pass more arguments to the executable_changed observer
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. Approved-By: Tom Tromey <tom@tromey.com>
-rw-r--r--gdb/exec.c11
-rw-r--r--gdb/observable.h18
2 files changed, 23 insertions, 6 deletions
diff --git a/gdb/exec.c b/gdb/exec.c
index 0775972..a1396c2 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 4ea203c..464d0b7 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