From: Andrew Burgess Date: Thu, 21 Aug 2025 12:42:44 +0000 (+0100) Subject: gdb: use existing argument more in rename_vmcore_idle_reg_sections X-Git-Tag: gdb-17-branchpoint~169 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1cb99f1398127070de3ad4b354101f640316075c;p=thirdparty%2Fbinutils-gdb.git gdb: use existing argument more in rename_vmcore_idle_reg_sections In corelow.c, in the function rename_vmcore_idle_reg_sections, the argument ABFD holds the core file bfd pointer. When this function is called current_program_space->core_bfd() is passed as the argument value. Within this function, we sometimes use the function argument, and sometimes access current_program_space->core_bfd() directly. This is confusing, and unnecessary. Lets not do that. I've renamed the argument to cbfd (for Core file BFD), and then updated the function to make use of this argument throughout. This reduces the number of accesses to global state, which is, I think, 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 b3768296962..af534bfb26f 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -790,10 +790,13 @@ core_file_command (const char *filename, int from_tty) .reg/1, .reg2/1, .reg/2, .reg2/2 After calling this function the rest of the core file handling code can - treat this core file just like any other core file. */ + treat this core file just like any other core file. + + CBFD is the core file being loaded, and INF is the inferior through + which the core file will be examined. */ static void -rename_vmcore_idle_reg_sections (bfd *abfd, inferior *inf) +rename_vmcore_idle_reg_sections (bfd *cbfd, inferior *inf) { /* Map from the bfd section to its lwpid (the /NN number). */ std::vector> sections_and_lwpids; @@ -808,7 +811,7 @@ rename_vmcore_idle_reg_sections (bfd *abfd, inferior *inf) /* Look for all the .reg sections. Record the section object and the lwpid which is extracted from the section name. Spot if any have an lwpid of zero. */ - for (asection *sect : gdb_bfd_sections (current_program_space->core_bfd ())) + for (asection *sect : gdb_bfd_sections (cbfd)) { if (startswith (bfd_section_name (sect), ".reg/")) { @@ -841,7 +844,7 @@ rename_vmcore_idle_reg_sections (bfd *abfd, inferior *inf) std::string replacement_lwpid_str; auto iter = sections_and_lwpids.begin (); int replacement_lwpid = 0; - for (asection *sect : gdb_bfd_sections (current_program_space->core_bfd ())) + for (asection *sect : gdb_bfd_sections (cbfd)) { if (iter != sections_and_lwpids.end () && sect == iter->first) { @@ -879,7 +882,7 @@ rename_vmcore_idle_reg_sections (bfd *abfd, inferior *inf) static_cast (len - 2), name, replacement_lwpid); char *name_buf - = static_cast (bfd_alloc (abfd, name_str.size () + 1)); + = static_cast (bfd_alloc (cbfd, name_str.size () + 1)); if (name_buf == nullptr) error (_("failed to allocate space for section name '%s'"), name_str.c_str ());