]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: more current_program_space->core_bfd() removal
authorAndrew Burgess <aburgess@redhat.com>
Thu, 21 Aug 2025 12:13:59 +0000 (13:13 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Tue, 26 Aug 2025 20:48:34 +0000 (21:48 +0100)
This commit changes the signature of the gdbarch_core_info_proc method
so that it takes a 'struct bfd *' as an extra argument.  This argument
is used to pass through the core file bfd pointer.

Now, in corelow.c, when calling gdbarch_core_info_proc, we can pass
through current_program_space->core_bfd() as the argument.  Within the
implementations, (Linux and FreeBSD) we can use this argument rather
than having to access the core file through current_program_space.

This reduces the use of global state, which I think is a good thing.

There should be no user visible changes after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/corelow.c
gdb/fbsd-tdep.c
gdb/gdbarch-gen.c
gdb/gdbarch-gen.h
gdb/gdbarch_components.py
gdb/linux-tdep.c

index a74cb0564768e45a65ff067a30c2155b2f8a86d7..b37682969624b6e1bcc8f9268483d8614b0fa3ed 100644 (file)
@@ -1826,7 +1826,8 @@ core_target::info_proc (const char *args, enum info_proc_what request)
   /* Since this is the core file target, call the 'core_info_proc'
      method on gdbarch, not 'info_proc'.  */
   if (gdbarch_core_info_proc_p (gdbarch))
-    gdbarch_core_info_proc (gdbarch, args, request);
+    gdbarch_core_info_proc (gdbarch, current_program_space->core_bfd (),
+                           args, request);
 
   return true;
 }
index 39e1e86dcee10496370637abc6dc1770bf551d94..171dbce86a0ed8aa7290dd971ff0d3d3e8eff0d7 100644 (file)
@@ -1433,8 +1433,8 @@ fbsd_core_info_proc_status (struct gdbarch *gdbarch)
 /* Implement the "core_info_proc" gdbarch method.  */
 
 static void
-fbsd_core_info_proc (struct gdbarch *gdbarch, const char *args,
-                    enum info_proc_what what)
+fbsd_core_info_proc (struct gdbarch *gdbarch, struct bfd *cbfd,
+                    const char *args, enum info_proc_what what)
 {
   bool do_cmdline = false;
   bool do_cwd = false;
@@ -1482,7 +1482,6 @@ fbsd_core_info_proc (struct gdbarch *gdbarch, const char *args,
       return;
     }
 
-  bfd *cbfd = current_program_space->core_bfd ();
   pid = bfd_core_file_pid (cbfd);
   if (pid != 0)
     gdb_printf (_("process %d\n"), pid);
index f4766e18d9a44c6e4294b9e38d725d38db4525da..3019cc581a76dc7d4e998a34e910c721a694c9d2 100644 (file)
@@ -5150,13 +5150,13 @@ gdbarch_core_info_proc_p (struct gdbarch *gdbarch)
 }
 
 void
-gdbarch_core_info_proc (struct gdbarch *gdbarch, const char *args, enum info_proc_what what)
+gdbarch_core_info_proc (struct gdbarch *gdbarch, struct bfd *cbfd, const char *args, enum info_proc_what what)
 {
   gdb_assert (gdbarch != NULL);
   gdb_assert (gdbarch->core_info_proc != NULL);
   if (gdbarch_debug >= 2)
     gdb_printf (gdb_stdlog, "gdbarch_core_info_proc called\n");
-  gdbarch->core_info_proc (gdbarch, args, what);
+  gdbarch->core_info_proc (gdbarch, cbfd, args, what);
 }
 
 void
index cd998984ab70fe2c258de4dc7dbcbfc2053efdbe..f1044ae2f2adab784147cc8321b09b1b7c452803 100644 (file)
@@ -1626,12 +1626,12 @@ extern void set_gdbarch_info_proc (struct gdbarch *gdbarch, gdbarch_info_proc_ft
 
 /* Implement the "info proc" command for core files.  Note that there
    are two "info_proc"-like methods on gdbarch -- one for core files,
-   one for live targets. */
+   one for live targets.  CBFD is the core file being read from. */
 
 extern bool gdbarch_core_info_proc_p (struct gdbarch *gdbarch);
 
-typedef void (gdbarch_core_info_proc_ftype) (struct gdbarch *gdbarch, const char *args, enum info_proc_what what);
-extern void gdbarch_core_info_proc (struct gdbarch *gdbarch, const char *args, enum info_proc_what what);
+typedef void (gdbarch_core_info_proc_ftype) (struct gdbarch *gdbarch, struct bfd *cbfd, const char *args, enum info_proc_what what);
+extern void gdbarch_core_info_proc (struct gdbarch *gdbarch, struct bfd *cbfd, const char *args, enum info_proc_what what);
 extern void set_gdbarch_core_info_proc (struct gdbarch *gdbarch, gdbarch_core_info_proc_ftype *core_info_proc);
 
 /* Ravenscar arch-dependent ops. */
index 938fa5ab69c3ab0d33edbd0ab59ab3277d610f2e..bd255187004ff3614d92f19710fd6b613ca7f4a0 100644 (file)
@@ -2554,11 +2554,15 @@ Method(
     comment="""
 Implement the "info proc" command for core files.  Note that there
 are two "info_proc"-like methods on gdbarch -- one for core files,
-one for live targets.
+one for live targets.  CBFD is the core file being read from.
 """,
     type="void",
     name="core_info_proc",
-    params=[("const char *", "args"), ("enum info_proc_what", "what")],
+    params=[
+        ("struct bfd *", "cbfd"),
+        ("const char *", "args"),
+        ("enum info_proc_what", "what")
+    ],
     predicate=True,
 )
 
index f57ee855f1d845c3a88812e21313d28b88966ff9..f97a890ff2239f16a3077eb3f55ee464fd3be451 100644 (file)
@@ -1231,14 +1231,15 @@ linux_read_core_file_mappings
     }
 }
 
-/* Implement "info proc mappings" for a corefile.  */
+/* Implement "info proc mappings" for corefile CBFD.  */
 
 static void
-linux_core_info_proc_mappings (struct gdbarch *gdbarch, const char *args)
+linux_core_info_proc_mappings (struct gdbarch *gdbarch, struct bfd *cbfd,
+                              const char *args)
 {
   std::optional<ui_out_emit_table> emitter;
 
-  linux_read_core_file_mappings (gdbarch, current_program_space->core_bfd (),
+  linux_read_core_file_mappings (gdbarch, cbfd,
     [&] (ULONGEST count)
       {
        gdb_printf (_("Mapped address spaces:\n\n"));
@@ -1267,19 +1268,18 @@ linux_core_info_proc_mappings (struct gdbarch *gdbarch, const char *args)
       });
 }
 
-/* Implement "info proc" for a corefile.  */
+/* Implement "info proc" for corefile CBFD.  */
 
 static void
-linux_core_info_proc (struct gdbarch *gdbarch, const char *args,
-                     enum info_proc_what what)
+linux_core_info_proc (struct gdbarch *gdbarch, struct bfd *cbfd,
+                     const char *args, enum info_proc_what what)
 {
   int exe_f = (what == IP_MINIMAL || what == IP_EXE || what == IP_ALL);
   int mappings_f = (what == IP_MAPPINGS || what == IP_ALL);
 
   if (exe_f)
     {
-      const char *exe
-       = bfd_core_file_failing_command (current_program_space->core_bfd ());
+      const char *exe = bfd_core_file_failing_command (cbfd);
 
       if (exe != NULL)
        gdb_printf ("exe = '%s'\n", exe);
@@ -1288,7 +1288,7 @@ linux_core_info_proc (struct gdbarch *gdbarch, const char *args,
     }
 
   if (mappings_f)
-    linux_core_info_proc_mappings (gdbarch, args);
+    linux_core_info_proc_mappings (gdbarch, cbfd, args);
 
   if (!exe_f && !mappings_f)
     error (_("unable to handle request"));