From: Tom Tromey Date: Thu, 29 Jan 2026 03:56:47 +0000 (-0700) Subject: Style file names in DWARF warnings X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1554225edc345257a8e08f31b59c5a5aa3c915ef;p=thirdparty%2Fbinutils-gdb.git Style file names in DWARF warnings This patch adds filename styling, where appropriate, to warnings in the DWARF reader. I didn't think this was really worth writing tests for. --- diff --git a/gdb/dwarf2/aranges.c b/gdb/dwarf2/aranges.c index 9b7603263d4..b085497844b 100644 --- a/gdb/dwarf2/aranges.c +++ b/gdb/dwarf2/aranges.c @@ -82,10 +82,11 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, const uint8_t offset_size = dwarf5_is_dwarf64 ? 8 : 4; if (addr + entry_length > section->buffer + section->size) { - warn->warn (_("Section .debug_aranges in %s entry at offset %s " + warn->warn (_("Section .debug_aranges in %ps entry at offset %s " "length %s exceeds section length %s, " "ignoring .debug_aranges."), - objfile_name (objfile), + styled_string (file_name_style.style (), + objfile_name (objfile)), plongest (entry_addr - section->buffer), plongest (bytes_read + entry_length), pulongest (section->size)); @@ -98,9 +99,10 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, if (version != 2) { warn->warn - (_("Section .debug_aranges in %s entry at offset %s " + (_("Section .debug_aranges in %ps entry at offset %s " "has unsupported version %d, ignoring .debug_aranges."), - objfile_name (objfile), + styled_string (file_name_style.style (), + objfile_name (objfile)), plongest (entry_addr - section->buffer), version); return false; } @@ -112,10 +114,11 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, = debug_info_offset_to_per_cu.find (sect_offset (debug_info_offset)); if (per_cu_it == debug_info_offset_to_per_cu.cend ()) { - warn->warn (_("Section .debug_aranges in %s entry at offset %s " + warn->warn (_("Section .debug_aranges in %ps entry at offset %s " "debug_info_offset %s does not exists, " "ignoring .debug_aranges."), - objfile_name (objfile), + styled_string (file_name_style.style (), + objfile_name (objfile)), plongest (entry_addr - section->buffer), pulongest (debug_info_offset)); return false; @@ -124,9 +127,10 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, = debug_info_offset_seen.insert (sect_offset (debug_info_offset)); if (!insertpair.second) { - warn->warn (_("Section .debug_aranges in %s has duplicate " + warn->warn (_("Section .debug_aranges in %ps has duplicate " "debug_info_offset %s, ignoring .debug_aranges."), - objfile_name (objfile), + styled_string (file_name_style.style (), + objfile_name (objfile)), sect_offset_str (sect_offset (debug_info_offset))); return false; } @@ -136,9 +140,10 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, if (address_size < 1 || address_size > 8) { warn->warn - (_("Section .debug_aranges in %s entry at offset %s " + (_("Section .debug_aranges in %ps entry at offset %s " "address_size %u is invalid, ignoring .debug_aranges."), - objfile_name (objfile), + styled_string (file_name_style.style (), + objfile_name (objfile)), plongest (entry_addr - section->buffer), address_size); return false; } @@ -146,10 +151,11 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, const uint8_t segment_selector_size = *addr++; if (segment_selector_size != 0) { - warn->warn (_("Section .debug_aranges in %s entry at offset %s " + warn->warn (_("Section .debug_aranges in %ps entry at offset %s " "segment_selector_size %u is not supported, " "ignoring .debug_aranges."), - objfile_name (objfile), + styled_string (file_name_style.style (), + objfile_name (objfile)), plongest (entry_addr - section->buffer), segment_selector_size); return false; @@ -168,10 +174,11 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, { if (addr + 2 * address_size > entry_end) { - warn->warn (_("Section .debug_aranges in %s entry at offset %s " + warn->warn (_("Section .debug_aranges in %ps entry at offset %s " "address list is not properly terminated, " "ignoring .debug_aranges."), - objfile_name (objfile), + styled_string (file_name_style.style (), + objfile_name (objfile)), plongest (entry_addr - section->buffer)); return false; } diff --git a/gdb/dwarf2/dwz.c b/gdb/dwarf2/dwz.c index 564b2c1a935..b403265a18d 100644 --- a/gdb/dwarf2/dwz.c +++ b/gdb/dwarf2/dwz.c @@ -31,6 +31,7 @@ #include "gdbsupport/pathstuff.h" #include "gdbsupport/scoped_fd.h" #include "run-on-main-thread.h" +#include "cli/cli-style.h" const char * dwz_file::read_string (struct objfile *objfile, LONGEST str_offset) @@ -379,8 +380,9 @@ dwz_file::read_dwz_file (dwarf2_per_objfile *per_objfile) dwz_bfd = gdb_bfd_open (alt_filename.get (), gnutarget); if (dwz_bfd == nullptr) - warning (_("File \"%s\" from debuginfod cannot be opened as bfd"), - alt_filename.get ()); + warning (_("File \"%ps\" from debuginfod cannot be opened as bfd"), + styled_string (file_name_style.style (), + alt_filename.get ())); else if (!verify_id (dwz_bfd.get (), buildid_len, buildid.get (), dwarf5)) dwz_bfd.reset (nullptr); diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c index 94586b06ef3..771a03d9467 100644 --- a/gdb/dwarf2/frame.c +++ b/gdb/dwarf2/frame.c @@ -33,6 +33,7 @@ #include "record.h" #include "extract-store-integer.h" #include "producer.h" +#include "cli/cli-style.h" #include "complaints.h" #include "dwarf2/frame.h" @@ -2157,8 +2158,10 @@ dwarf2_build_frame_info (struct objfile *objfile) catch (const gdb_exception_error &e) { - warning (_("skipping .eh_frame info of %s: %s"), - objfile_name (objfile), e.what ()); + warning (_("skipping .eh_frame info of %ps: %s"), + styled_string (file_name_style.style (), + objfile_name (objfile)), + e.what ()); fde_table.clear (); /* The cie_table is discarded below. */ @@ -2186,8 +2189,10 @@ dwarf2_build_frame_info (struct objfile *objfile) } catch (const gdb_exception_error &e) { - warning (_("skipping .debug_frame info of %s: %s"), - objfile_name (objfile), e.what ()); + warning (_("skipping .debug_frame info of %ps: %s"), + styled_string (file_name_style.style (), + objfile_name (objfile)), + e.what ()); fde_table.resize (num_old_fde_entries); } diff --git a/gdb/dwarf2/read-debug-names.c b/gdb/dwarf2/read-debug-names.c index a5669bde71e..8e488377439 100644 --- a/gdb/dwarf2/read-debug-names.c +++ b/gdb/dwarf2/read-debug-names.c @@ -30,6 +30,7 @@ #include "stringify.h" #include "extract-store-integer.h" #include "gdbsupport/thread-pool.h" +#include "cli/cli-style.h" /* This is just like cooked_index_functions, but overrides a single method so the test suite can distinguish the .debug_names case from @@ -230,10 +231,11 @@ mapped_debug_names_reader::scan_one_entry (const char *name, default: /* A warning instead of a complaint, because this one is more like a bug in gdb. */ - warning (_("Unsupported .debug_names form %s [in module %s].\n" + warning (_("Unsupported .debug_names form %s [in module %ps].\n" "This normally should not happen, please file a bug report."), dwarf_form_name (attr.form), - bfd_get_filename (abfd)); + styled_string (file_name_style.style (), + bfd_get_filename (abfd))); return nullptr; } switch (attr.dw_idx) @@ -535,9 +537,11 @@ read_debug_names_from_section (dwarf2_per_objfile *per_objfile, if (bytes_read + length != section->size) { /* There may be multiple per-CU indices. */ - warning (_("Section .debug_names in %s length %s does not match " + warning (_("Section .debug_names in %ps length %s does not match " "section length %s, ignoring .debug_names."), - filename, plongest (bytes_read + length), + styled_string (file_name_style.style (), + filename), + plongest (bytes_read + length), pulongest (section->size)); return false; } @@ -547,9 +551,11 @@ read_debug_names_from_section (dwarf2_per_objfile *per_objfile, addr += 2; if (version != 5) { - warning (_("Section .debug_names in %s has unsupported version %d, " + warning (_("Section .debug_names in %ps has unsupported version %d, " "ignoring .debug_names."), - filename, version); + styled_string (file_name_style.style (), + filename), + version); return false; } @@ -558,9 +564,11 @@ read_debug_names_from_section (dwarf2_per_objfile *per_objfile, addr += 2; if (padding != 0) { - warning (_("Section .debug_names in %s has unsupported padding %d, " + warning (_("Section .debug_names in %ps has unsupported padding %d, " "ignoring .debug_names."), - filename, padding); + styled_string (file_name_style.style (), + filename), + padding); return false; } @@ -579,9 +587,11 @@ read_debug_names_from_section (dwarf2_per_objfile *per_objfile, addr += 4; if (foreign_tu_count != 0) { - warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, " + warning (_("Section .debug_names in %ps has unsupported %lu foreign TUs, " "ignoring .debug_names."), - filename, static_cast (foreign_tu_count)); + styled_string (file_name_style.style (), + filename), + static_cast (foreign_tu_count)); return false; } @@ -666,9 +676,11 @@ read_debug_names_from_section (dwarf2_per_objfile *per_objfile, = map.abbrev_map.emplace (index_num, mapped_debug_names_reader::index_val ()); if (!insertpair.second) { - warning (_("Section .debug_names in %s has duplicate index %s, " + warning (_("Section .debug_names in %ps has duplicate index %s, " "ignoring .debug_names."), - filename, pulongest (index_num)); + styled_string (file_name_style.style (), + filename), + pulongest (index_num)); return false; } mapped_debug_names_reader::index_val &indexval = insertpair.first->second; @@ -695,9 +707,11 @@ read_debug_names_from_section (dwarf2_per_objfile *per_objfile, } if (addr != abbrev_table_start + abbrev_table_size) { - warning (_("Section .debug_names in %s has abbreviation_table " + warning (_("Section .debug_names in %ps has abbreviation_table " "of size %s vs. written as %u, ignoring .debug_names."), - filename, plongest (addr - abbrev_table_start), + styled_string (file_name_style.style (), + filename), + plongest (addr - abbrev_table_start), abbrev_table_size); return false; } @@ -797,8 +811,9 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile) bfd_get_filename (dwz->dwz_bfd.get ()), &dwz->debug_names, dwz_map)) { - warning (_("could not read '.debug_names' section from %s; skipping"), - bfd_get_filename (dwz->dwz_bfd.get ())); + warning (_("could not read '.debug_names' section from %ps; skipping"), + styled_string (file_name_style.style (), + bfd_get_filename (dwz->dwz_bfd.get ()))); return false; } } diff --git a/gdb/dwarf2/read-gdb-index.c b/gdb/dwarf2/read-gdb-index.c index 0848c8393e6..2d204737bd2 100644 --- a/gdb/dwarf2/read-gdb-index.c +++ b/gdb/dwarf2/read-gdb-index.c @@ -30,6 +30,7 @@ #include "extract-store-integer.h" #include "cp-support.h" #include "symtab.h" +#include "cli/cli-style.h" /* When true, do not reject deprecated .gdb_index sections. */ static bool use_deprecated_index_sections = false; @@ -428,8 +429,9 @@ read_gdb_index_from_buffer (const char *filename, static int warning_printed = 0; if (!warning_printed) { - warning (_("Skipping obsolete .gdb_index section in %s."), - filename); + warning (_("Skipping obsolete .gdb_index section in %ps."), + styled_string (file_name_style.style (), + filename)); warning_printed = 1; } return 0; @@ -757,8 +759,9 @@ dwarf2_read_gdb_index &dwz_types_ignore, &dwz_types_elements_ignore)) { - warning (_("could not read '.gdb_index' section from %s; skipping"), - dwz->filename ()); + warning (_("could not read '.gdb_index' section from %ps; skipping"), + styled_string (file_name_style.style (), + dwz->filename ())); return false; } } diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index f23a9af19f3..efe0b046f15 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -97,6 +97,7 @@ #include "dwarf2/error.h" #include "gdbsupport/unordered_set.h" #include "extract-store-integer.h" +#include "cli/cli-style.h" /* When == 1, print basic high level tracing messages. When > 1, be more verbose. @@ -1267,9 +1268,10 @@ dwarf2_per_bfd::locate_sections (asection *sectp, { bfd_size_type size = sectp->size; warning (_("Discarding section %s which has an invalid size (%s) " - "[in module %s]"), + "[in module %ps]"), bfd_section_name (sectp), phex_nz (size), - this->filename ()); + styled_string (file_name_style.style (), + this->filename ())); } else if (names.info.matches (sectp->name)) { @@ -7094,7 +7096,9 @@ cutu_reader::locate_dwo_sections (objfile *objfile, dwo_file &dwo_file) else { warning (_("Multiple .debug_macro.dwo sections found in " - "%s, ignoring them."), dwo_file.dbfd->filename); + "%ps, ignoring them."), + styled_string (file_name_style.style (), + dwo_file.dbfd->filename)); dwo_sections.macro = dwarf2_section_info {}; complained_about_macro_already = true; @@ -7477,9 +7481,11 @@ cutu_reader::lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name, lbasename (dwp_file->name)); warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s" - " [in module %s]"), + " [in module %ps]"), kind, dwo_name, hex_string (signature), dwp_text.c_str (), kind, - sect_offset_str (cu->per_cu->sect_off ()), objfile_name (objfile)); + sect_offset_str (cu->per_cu->sect_off ()), + styled_string (file_name_style.style (), + objfile_name (objfile))); } return NULL; }