]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: use existing argument more in rename_vmcore_idle_reg_sections
authorAndrew Burgess <aburgess@redhat.com>
Thu, 21 Aug 2025 12:42:44 +0000 (13:42 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Tue, 26 Aug 2025 20:48:35 +0000 (21:48 +0100)
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 <simon.marchi@efficios.com>
gdb/corelow.c

index b37682969624b6e1bcc8f9268483d8614b0fa3ed..af534bfb26f5be612922717b8a083b0f5546b29c 100644 (file)
@@ -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<std::pair<asection *, int>> 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<int> (len - 2),
                                 name, replacement_lwpid);
              char *name_buf
-               = static_cast<char *> (bfd_alloc (abfd, name_str.size () + 1));
+               = static_cast<char *> (bfd_alloc (cbfd, name_str.size () + 1));
              if (name_buf == nullptr)
                error (_("failed to allocate space for section name '%s'"),
                       name_str.c_str ());