]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Style file names in DWARF warnings
authorTom Tromey <tom@tromey.com>
Thu, 29 Jan 2026 03:56:47 +0000 (20:56 -0700)
committerTom Tromey <tom@tromey.com>
Sat, 14 Feb 2026 18:46:45 +0000 (11:46 -0700)
This patch adds filename styling, where appropriate, to warnings in
the DWARF reader.

I didn't think this was really worth writing tests for.

gdb/dwarf2/aranges.c
gdb/dwarf2/dwz.c
gdb/dwarf2/frame.c
gdb/dwarf2/read-debug-names.c
gdb/dwarf2/read-gdb-index.c
gdb/dwarf2/read.c

index 9b7603263d43fc449beda874818723c0f14fac2a..b085497844b5965657bd97031263ce9f16cc4fe0 100644 (file)
@@ -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;
            }
index 564b2c1a935fd4e93517a0b9d35079e4e3737d0c..b403265a18df0fcd0ac50f7dc662ff7f78aeeb6a 100644 (file)
@@ -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);
index 94586b06ef30d59dc265167678aa8910d9b8e881..771a03d9467c0d7ec4694d3052942189bb645767 100644 (file)
@@ -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);
        }
index a5669bde71e4d6786571bdbd7068a6c720a76553..8e488377439bddc246f7cc0c917a9f278adae411 100644 (file)
@@ -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<unsigned long> (foreign_tu_count));
+              styled_string (file_name_style.style (),
+                             filename),
+              static_cast<unsigned long> (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;
        }
     }
index 0848c8393e64059dfcbc3c3868fc9c2cb7b1fd88..2d204737bd29b8cc36a32ef94af9521d74e69a74 100644 (file)
@@ -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;
        }
     }
index f23a9af19f34648fc798cf38b62cb50e927cd7b8..efe0b046f15d4055f8829e1bf3b4e7f6eb519cf3 100644 (file)
@@ -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;
 }