From 294cb98c95a0466eca90d5b1a512db44fae45c3d Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Mon, 1 Dec 2025 12:41:00 +0100 Subject: [PATCH] [gdb/corefiles] Sort info proc mappings table 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 | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 6e9135f576e..10843613c5d 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -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 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); } } -- 2.47.3