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
#include "dwarf2/aranges.h"
#include "dwarf2/read.h"
#include "extract-store-integer.h"
+#include "cli/cli-style.h"
/* See aranges.h. */
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;
/* 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,
#include "dwarf2/aranges.h"
#include "dwarf2/cooked-index.h"
+#include "cli/cli-style.h"
#include "complaints.h"
#include "cp-support.h"
#include "dwz.h"
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<std::size_t> (gdb::thread_pool::g_thread_pool->thread_count (),
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}" \
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}" \
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}" \