]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/corefiles] Sort info proc mappings table
authorTom de Vries <tdevries@suse.de>
Mon, 1 Dec 2025 11:41:00 +0000 (12:41 +0100)
committerTom de Vries <tdevries@suse.de>
Mon, 1 Dec 2025 11:41:00 +0000 (12:41 +0100)
On x86_64-linux, with test-case gdb.python/py-corefile.exp I run into:
...
FAIL: $exp: test mapped files data: diff input and output one
...

The failing test compares the output of:
- info proc mappings, and
- info proc py-mappings, a python implementation of "info proc mappings".

The difference in output is order: while the latter prints the entries sorted
on start address, the former doesn't.

Fix this by sorting the entries in linux_read_core_file_mappings.

Tested on x86_64-linux.

PR corefiles/33543
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33543

gdb/linux-tdep.c

index 6e9135f576efde0244438fb21a4855be6d960892..10843613c5dbb8ec546ff138662db832a93549ae 100644 (file)
@@ -1217,23 +1217,51 @@ linux_read_core_file_mappings
   cbfd->build_id = orig_build_id;
   pre_loop_cb (count);
 
+  /* Vector to collect proc mappings.  */
+  struct proc_mapping
+  {
+    int num;
+    ULONGEST start;
+    ULONGEST end;
+    ULONGEST file_ofs;
+    const char *filename;
+    const bfd_build_id *build_id;
+  };
+  std::vector<struct proc_mapping> proc_mappings;
+
+  /* Collect proc mappings.  */
   for (int i = 0; i < count; i++)
     {
-      ULONGEST start = bfd_get (addr_size_bits, cbfd, descdata);
+      struct proc_mapping m = { .num = i };
+      m.start = bfd_get (addr_size_bits, cbfd, descdata);
       descdata += addr_size;
-      ULONGEST end = bfd_get (addr_size_bits, cbfd, descdata);
+      m.end = bfd_get (addr_size_bits, cbfd, descdata);
       descdata += addr_size;
-      ULONGEST file_ofs = bfd_get (addr_size_bits, cbfd, descdata) * page_size;
+      m.file_ofs = bfd_get (addr_size_bits, cbfd, descdata) * page_size;
       descdata += addr_size;
-      char * filename = filenames;
+      m.filename = filenames;
       filenames += strlen ((char *) filenames) + 1;
-      const bfd_build_id *build_id = nullptr;
-      auto vma_map_it = vma_map.find (start);
 
+      m.build_id = nullptr;
+      auto vma_map_it = vma_map.find (m.start);
       if (vma_map_it != vma_map.end ())
-       build_id = vma_map_it->second;
+       m.build_id = vma_map_it->second;
+
+      proc_mappings.push_back (m);
+    }
+
+  /* Sort proc mappings.  */
+  std::sort (proc_mappings.begin (), proc_mappings.end (),
+            [] (const proc_mapping &a, const proc_mapping &b)
+              {
+                return a.start < b.start;
+              });
 
-      loop_cb (i, start, end, file_ofs, filename, build_id);
+  /* Call loop_cb with sorted proc mappings.  */
+  for (int i = 0; i < count; i++)
+    {
+      const auto &m = proc_mappings[i];
+      loop_cb (m.num, m.start, m.end, m.file_ofs, m.filename, m.build_id);
     }
 }