]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: remove pre-loop callback from gdbarch_read_core_file_mappings
authorAndrew Burgess <aburgess@redhat.com>
Tue, 10 Mar 2026 16:38:31 +0000 (16:38 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Fri, 1 May 2026 18:56:56 +0000 (19:56 +0100)
Currently only one target, Linux, implements
gdbarch_read_core_file_mappings, with
linux_read_core_file_mappings. There is one use of
gdbarch_read_core_file_mappings in corelow.c, and one direct use of
linux_read_core_file_mappings in linux-tdep.c.

The gdbarch_read_core_file_mappings takes two callbacks, a pre-loop
callback, which is called once, then a loop callback which is called
multiple times for each mapping that is discovered.

The only user of the pre-loop callback is in linux-tdep.c.  Within
corelow.c, the pre-loop callback is not used.

In the next commit I plan to change linux_read_core_file_mappings, and
as a result of this change the use of linux_read_core_file_mappings in
linux-tdep.c will no longer be able to make use of the pre-loop
callback.  This means that, after the next commit, there will be no
users of the pre-loop callback.

Additionally, the pre-loop callback takes an argument, the number of
mappings found.

After the next commit it is no longer clear what number we should pass
here as the next commit will introduce the idea of there being two
types of mapping, anonymous and non-anonymous.  Should the number
passed to the pre-loop callback be the combined total?  Or should we
count each separately?

I could try to answer this question.

Or I could just delete the pre-loop callback from
gdbarch_read_core_file_mappings.

This commit takes the second approach and deletes the callback.

As part of this work I've updated linux_core_info_proc_mappings, which
is the function that calls linux_read_core_file_mappings, so that the
pre-loop callback is no longer used.  The lambda capture on the loop
callback needed to change from [=] to [&] with this commit so
`emitter` from the enclosing scope can be modified.

There is one subtle change of behaviour in
linux_core_info_proc_mappings after this commit.  Previously,
linux_core_info_proc_mappings would print the table header so long as
the core file had a valid NT_FILE note, even if that note contained no
actual file mappings.

With the removal of the pre-loop callback I had a choice, either
always print the table header, or only print the table header if I saw
some entries being printed.  I selected the second choice as that
seemed like the smallest change, but there is a change here.  If a
user has a core file with an NT_FILE note containing no mapped files,
then the table header will no longer be printed.  Hopefully this isn't
too disruptive.

This is a refactoring commit in preparation for the next one.

Reviewed-By: Keith Seitz <keiths@redhat.com>
gdb/arch-utils.c
gdb/arch-utils.h
gdb/corelow.c
gdb/gdbarch-gen.c
gdb/gdbarch-gen.h
gdb/gdbarch.h
gdb/gdbarch_components.py
gdb/linux-tdep.c

index ea0b3c111f99b51afed6f78372f6c9cf055758e2..5e15fa5b4344356380362e4d5cfa0e891787dc8e 100644 (file)
@@ -1080,7 +1080,6 @@ void
 default_read_core_file_mappings
   (struct gdbarch *gdbarch,
    struct bfd *cbfd,
-   read_core_file_mappings_pre_loop_ftype pre_loop_cb,
    read_core_file_mappings_loop_ftype loop_cb)
 {
 }
index d5772575c7a9b3c410187979592731ced81b23d4..069020500437eae867a21d975eb4967cab0e4814 100644 (file)
@@ -378,7 +378,6 @@ extern std::string default_get_pc_address_flags (const frame_info_ptr &frame,
 extern void default_read_core_file_mappings
   (struct gdbarch *gdbarch,
    struct bfd *cbfd,
-   read_core_file_mappings_pre_loop_ftype pre_loop_cb,
    read_core_file_mappings_loop_ftype loop_cb);
 
 /* Default implementation of gdbarch_core_parse_exec_context.  Returns
index e8e3e85e0c91ac4381dbc61104fe45af0fdac436..407515ee45ad9d80462abc91d5fdb3234f73c2db 100644 (file)
@@ -2168,14 +2168,8 @@ gdb_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd)
   /* See linux_read_core_file_mappings() in linux-tdep.c for an example
      read_core_file_mappings method.  */
   gdbarch_read_core_file_mappings (gdbarch, cbfd,
-    /* After determining the number of mappings, read_core_file_mappings
-       will invoke this lambda.  */
-    [&] (ULONGEST)
-      {
-      },
-
-    /* read_core_file_mappings will invoke this lambda for each mapping
-       that it finds.  */
+    /* gdbarch_read_core_file_mappings will invoke this lambda for each
+       mapping that it finds.  */
     [&] (ULONGEST start, ULONGEST end, ULONGEST file_ofs,
         const char *filename, const bfd_build_id *build_id)
       {
index 1a8f21091b2fceb31adbcb90b09fbc04411371db..f424fa2a86eb859c0a066541cbd4fe6fb9b6ab37 100644 (file)
@@ -5196,13 +5196,13 @@ set_gdbarch_get_pc_address_flags (struct gdbarch *gdbarch,
 }
 
 void
-gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd, read_core_file_mappings_pre_loop_ftype pre_loop_cb, read_core_file_mappings_loop_ftype loop_cb)
+gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd, read_core_file_mappings_loop_ftype loop_cb)
 {
   gdb_assert (gdbarch != nullptr);
   gdb_assert (gdbarch->read_core_file_mappings != nullptr);
   if (gdbarch_debug >= 2)
     gdb_printf (gdb_stdlog, "gdbarch_read_core_file_mappings called\n");
-  gdbarch->read_core_file_mappings (gdbarch, cbfd, pre_loop_cb, loop_cb);
+  gdbarch->read_core_file_mappings (gdbarch, cbfd, loop_cb);
 }
 
 void
index c139497856884cf80eb64e3c2b7f907d5e670fd5..678b308fba5abdfe1e27710069b497f77de9e727 100644 (file)
@@ -1696,8 +1696,8 @@ void set_gdbarch_get_pc_address_flags (struct gdbarch *gdbarch, gdbarch_get_pc_a
 
 /* Read core file mappings */
 
-using gdbarch_read_core_file_mappings_ftype = void (struct gdbarch *gdbarch, struct bfd *cbfd, read_core_file_mappings_pre_loop_ftype pre_loop_cb, read_core_file_mappings_loop_ftype loop_cb);
-void gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd, read_core_file_mappings_pre_loop_ftype pre_loop_cb, read_core_file_mappings_loop_ftype loop_cb);
+using gdbarch_read_core_file_mappings_ftype = void (struct gdbarch *gdbarch, struct bfd *cbfd, read_core_file_mappings_loop_ftype loop_cb);
+void gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd, read_core_file_mappings_loop_ftype loop_cb);
 void set_gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, gdbarch_read_core_file_mappings_ftype *read_core_file_mappings);
 
 /* Return true if the target description for all threads should be read from the
index f5ee3074c38266c456b18c1d9d8c38c669e6abe9..7077f9262e9d8a989363b3e5b1855f9aa5b41dbe 100644 (file)
@@ -122,10 +122,7 @@ enum class memtag_type
   allocation,
 };
 
-/* Callback types for 'read_core_file_mappings' gdbarch method.  */
-
-using read_core_file_mappings_pre_loop_ftype =
-  gdb::function_view<void (ULONGEST count)>;
+/* Callback type for 'read_core_file_mappings' gdbarch method.  */
 
 using read_core_file_mappings_loop_ftype =
   gdb::function_view<void (ULONGEST start,
index 7a329d92166583a8fe2fe205274975a18372558a..b9304d3036dac6d56590bea3cc4fbaf09f6fd2a8 100644 (file)
@@ -2706,7 +2706,6 @@ Read core file mappings
     name="read_core_file_mappings",
     params=[
         ("struct bfd *", "cbfd"),
-        ("read_core_file_mappings_pre_loop_ftype", "pre_loop_cb"),
         ("read_core_file_mappings_loop_ftype", "loop_cb"),
     ],
     predefault="default_read_core_file_mappings",
index 508f9f88457150f88fc7f056831b58bc36ef778a..43df05d1529a24ee5435f1a6a99f161ee3a760b1 100644 (file)
@@ -1109,11 +1109,6 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
 
    CBFD is the BFD of the core file.
 
-   PRE_LOOP_CB is the callback function to invoke prior to starting
-   the loop which processes individual entries.  This callback will
-   only be executed after the note has been examined in enough
-   detail to verify that it's not malformed in some way.
-
    LOOP_CB is the callback function that will be executed once
    for each mapping.  */
 
@@ -1121,7 +1116,6 @@ static void
 linux_read_core_file_mappings
   (struct gdbarch *gdbarch,
    struct bfd *cbfd,
-   read_core_file_mappings_pre_loop_ftype pre_loop_cb,
    read_core_file_mappings_loop_ftype  loop_cb)
 {
   /* Ensure that ULONGEST is big enough for reading 64-bit core files.  */
@@ -1207,7 +1201,6 @@ linux_read_core_file_mappings
     }
 
   cbfd->build_id = orig_build_id;
-  pre_loop_cb (count);
 
   /* Vector to collect proc mappings.  */
   struct proc_mapping
@@ -1249,11 +1242,8 @@ linux_read_core_file_mappings
               });
 
   /* Call loop_cb with sorted proc mappings.  */
-  for (int i = 0; i < count; i++)
-    {
-      const auto &m = proc_mappings[i];
-      loop_cb (m.start, m.end, m.file_ofs, m.filename, m.build_id);
-    }
+  for (const auto &m : proc_mappings)
+    loop_cb (m.start, m.end, m.file_ofs, m.filename, m.build_id);
 }
 
 /* Implement "info proc mappings" for corefile CBFD.  */
@@ -1265,21 +1255,22 @@ linux_core_info_proc_mappings (struct gdbarch *gdbarch, struct bfd *cbfd,
   std::optional<ui_out_emit_table> emitter;
 
   linux_read_core_file_mappings (gdbarch, cbfd,
-    [&] (ULONGEST count)
-      {
-       gdb_printf (_("Mapped address spaces:\n\n"));
-       emitter.emplace (current_uiout, 5, -1, "ProcMappings");
-       int width = gdbarch_addr_bit (gdbarch) == 32 ? 10 : 18;
-       current_uiout->table_header (width, ui_left, "start", "Start Addr");
-       current_uiout->table_header (width, ui_left, "end", "End Addr");
-       current_uiout->table_header (width, ui_left, "size", "Size");
-       current_uiout->table_header (width, ui_left, "offset", "Offset");
-       current_uiout->table_header (0, ui_left, "objfile", "File");
-       current_uiout->table_body ();
-      },
-    [=] (ULONGEST start, ULONGEST end, ULONGEST file_ofs,
+    [&] (ULONGEST start, ULONGEST end, ULONGEST file_ofs,
         const char *filename, const bfd_build_id *build_id)
       {
+       if (!emitter.has_value ())
+         {
+           gdb_printf (_("Mapped address spaces:\n\n"));
+           emitter.emplace (current_uiout, 5, -1, "ProcMappings");
+           int width = gdbarch_addr_bit (gdbarch) == 32 ? 10 : 18;
+           current_uiout->table_header (width, ui_left, "start", "Start Addr");
+           current_uiout->table_header (width, ui_left, "end", "End Addr");
+           current_uiout->table_header (width, ui_left, "size", "Size");
+           current_uiout->table_header (width, ui_left, "offset", "Offset");
+           current_uiout->table_header (0, ui_left, "objfile", "File");
+           current_uiout->table_body ();
+         }
+
        ui_out_emit_tuple tuple_emitter (current_uiout, nullptr);
        current_uiout->field_core_addr ("start", gdbarch, start);
        current_uiout->field_core_addr ("end", gdbarch, end);