aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2025-08-21 13:13:59 +0100
committerAndrew Burgess <aburgess@redhat.com>2025-08-26 21:48:34 +0100
commit43ed67a290e7679af86395d7b430a71f9e4449ee (patch)
treef44df8204da8cda967a4715cc27155c90291445b
parent2bd87cef85034dbf39a2817fba4f03828c0ca782 (diff)
downloadbinutils-43ed67a290e7679af86395d7b430a71f9e4449ee.zip
binutils-43ed67a290e7679af86395d7b430a71f9e4449ee.tar.gz
binutils-43ed67a290e7679af86395d7b430a71f9e4449ee.tar.bz2
gdb: more current_program_space->core_bfd() removal
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>
-rw-r--r--gdb/corelow.c3
-rw-r--r--gdb/fbsd-tdep.c5
-rw-r--r--gdb/gdbarch-gen.c4
-rw-r--r--gdb/gdbarch-gen.h6
-rw-r--r--gdb/gdbarch_components.py8
-rw-r--r--gdb/linux-tdep.c18
6 files changed, 24 insertions, 20 deletions
diff --git a/gdb/corelow.c b/gdb/corelow.c
index a74cb05..b376829 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -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;
}
diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
index 39e1e86..171dbce 100644
--- a/gdb/fbsd-tdep.c
+++ b/gdb/fbsd-tdep.c
@@ -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);
diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c
index f4766e1..3019cc5 100644
--- a/gdb/gdbarch-gen.c
+++ b/gdb/gdbarch-gen.c
@@ -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
diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h
index cd99898..f1044ae 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -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. */
diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py
index 938fa5a..bd25518 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -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,
)
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index f57ee85..f97a890 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -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"));