From: Andrew Burgess Date: Thu, 21 Aug 2025 12:13:59 +0000 (+0100) Subject: gdb: more current_program_space->core_bfd() removal X-Git-Tag: gdb-17-branchpoint~170 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=43ed67a290e7679af86395d7b430a71f9e4449ee;p=thirdparty%2Fbinutils-gdb.git 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 --- diff --git a/gdb/corelow.c b/gdb/corelow.c index a74cb056476..b3768296962 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 39e1e86dcee..171dbce86a0 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 f4766e18d9a..3019cc581a7 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 cd998984ab7..f1044ae2f2a 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 938fa5ab69c..bd255187004 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 f57ee855f1d..f97a890ff22 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 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"));