From: Tom Tromey Date: Tue, 27 Jan 2026 03:49:26 +0000 (-0700) Subject: Don't use .debug_names if .debug_aranges is missing X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=169c87848f5b565475fea22b44bdf078a3d9ea6e;p=thirdparty%2Fbinutils-gdb.git Don't use .debug_names if .debug_aranges is missing gdb's .debug_names reader depends on .debug_aranges as well, because if the ranges are missing, it won't be able to create a map from PC to CU. However, this requirement isn't enforced by gdb. I no longer recall know why, but I can see in commit b371f07c ("Rewrite .debug_names reader") that I made this choice on purpose: In v1 of this patch, I made the new reader more strict about requiring .debug_aranges. In v2, I've backed this out and kept the previous logic. This solved a few test failures, though it's arguably not the right approach. However, the current setup now seems clearly incorrect to me. And, it was causing problems for another patch I'm working on. Fixing this required patching a few tests to add a .debug_aranges section. I've also updated the intro comment to read_addrmap_from_aranges to reflect how it ought to be used. Regression tested on x86-64 Fedora 41 with both the default and the cc-with-debug-names target boards. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33847 --- diff --git a/gdb/dwarf2/aranges.c b/gdb/dwarf2/aranges.c index 4f25763ebc8..9b7603263d4 100644 --- a/gdb/dwarf2/aranges.c +++ b/gdb/dwarf2/aranges.c @@ -20,6 +20,7 @@ #include "dwarf2/aranges.h" #include "dwarf2/read.h" #include "extract-store-integer.h" +#include "cli/cli-style.h" /* See aranges.h. */ @@ -29,12 +30,18 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, addrmap_mutable *mutable_map, deferred_warnings *warn) { + struct objfile *objfile = per_objfile->objfile; + /* Caller must ensure that the section has already been read. */ gdb_assert (section->read_in); if (section->empty ()) - return false; + { + warn->warn (_(".debug_aranges section is empty or missing from %ps"), + styled_string (file_name_style.style (), + objfile_name (objfile))); + return false; + } - struct objfile *objfile = per_objfile->objfile; bfd *abfd = objfile->obfd.get (); struct gdbarch *gdbarch = objfile->arch (); dwarf2_per_bfd *per_bfd = per_objfile->per_bfd; diff --git a/gdb/dwarf2/aranges.h b/gdb/dwarf2/aranges.h index a8e534580a0..26709062d17 100644 --- a/gdb/dwarf2/aranges.h +++ b/gdb/dwarf2/aranges.h @@ -26,7 +26,12 @@ class addrmap_mutable; /* Read the address map data from DWARF-5 .debug_aranges, and use it to populate given addrmap. Returns true on success, false on - failure. */ + failure. On failure, it is guaranteed that a warning will be + emitted to WARN. + + Note that this will emit a warning and fail if the section is + empty. If a caller can tolerate a missing .debug_aranges section, + it should check this explicitly before the call. */ extern bool read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, dwarf2_section_info *section, diff --git a/gdb/dwarf2/read-debug-names.c b/gdb/dwarf2/read-debug-names.c index 6258fcb86a7..a5669bde71e 100644 --- a/gdb/dwarf2/read-debug-names.c +++ b/gdb/dwarf2/read-debug-names.c @@ -21,6 +21,7 @@ #include "dwarf2/aranges.h" #include "dwarf2/cooked-index.h" +#include "cli/cli-style.h" #include "complaints.h" #include "cp-support.h" #include "dwz.h" @@ -833,9 +834,18 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile) into place later. */ cooked_index_worker_result first; deferred_warnings warnings; - read_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges, - first.get_addrmap (), &warnings); + bool ok = read_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges, + first.get_addrmap (), &warnings); warnings.emit (); + if (!ok) + { + /* read_addrmap_from_aranges must have emitted a warning in this + case. */ + warning (_("... not using '.debug_names' for %ps"), + styled_string (file_name_style.style (), + objfile_name (objfile))); + return false; + } const auto n_workers = std::max (gdb::thread_pool::g_thread_pool->thread_count (), diff --git a/gdb/testsuite/gdb.dwarf2/debug-names-bad-cu-index.exp b/gdb/testsuite/gdb.dwarf2/debug-names-bad-cu-index.exp index b88430eaa59..e91ff225e94 100644 --- a/gdb/testsuite/gdb.dwarf2/debug-names-bad-cu-index.exp +++ b/gdb/testsuite/gdb.dwarf2/debug-names-bad-cu-index.exp @@ -73,6 +73,10 @@ Dwarf::assemble { name _start subprogram CU-1 0xEDDB6232 name struct_with_int_member structure_type tu_label 0x53A2AE86 } + + aranges {} cu_label { + arange {} $_start_start $_start_len + } } if {[build_executable ${testfile}.exp $testfile "${asm_file} ${srcfile}" \ diff --git a/gdb/testsuite/gdb.dwarf2/debug-names-tu.exp.tcl b/gdb/testsuite/gdb.dwarf2/debug-names-tu.exp.tcl index be1a9f490f0..f5803a32b3c 100644 --- a/gdb/testsuite/gdb.dwarf2/debug-names-tu.exp.tcl +++ b/gdb/testsuite/gdb.dwarf2/debug-names-tu.exp.tcl @@ -81,6 +81,10 @@ Dwarf::assemble { name struct_with_int_member structure_type tu_label 0x53A2AE86 \ {DW_LANG_C} } + + aranges {} cu_label { + arange {} $_start_start $_start_len + } } if {[prepare_for_testing "failed to prepare" $testfile "${asm_file} ${srcfile}" \ diff --git a/gdb/testsuite/gdb.dwarf2/debug-names.exp b/gdb/testsuite/gdb.dwarf2/debug-names.exp index cb55c447dc4..66458df3974 100644 --- a/gdb/testsuite/gdb.dwarf2/debug-names.exp +++ b/gdb/testsuite/gdb.dwarf2/debug-names.exp @@ -56,6 +56,10 @@ Dwarf::assemble { name _start subprogram cu_label 0xEDDB6232 name int base_type cu_label 0xB888030 } + + aranges {} cu_label { + arange {} $_start_end $_start_len + } } if {[prepare_for_testing "failed to prepare" $testfile "${asm_file} ${srcfile}" \