From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 2/4] Add filename styling to error messages
Date: Sun, 05 Apr 2026 05:28:39 -0600 [thread overview]
Message-ID: <20260405-more-error-style-v1-2-6c04da718875@tromey.com> (raw)
In-Reply-To: <20260405-more-error-style-v1-0-6c04da718875@tromey.com>
This changes a number of error messages in gdb to use file_name_style.
---
gdb/amd64-linux-tdep.c | 5 +++--
gdb/breakpoint.c | 12 ++++++++----
gdb/cli/cli-cmds.c | 5 +++--
gdb/cli/cli-dump.c | 21 ++++++++++++++-------
gdb/coffread.c | 19 +++++++++++++------
gdb/compile/compile-object-load.c | 36 +++++++++++++++++++++---------------
gdb/corelow.c | 10 ++++++----
gdb/ctfread.c | 16 ++++++++++------
gdb/dwarf2/dwz.c | 9 +++++----
gdb/exec.c | 10 +++++-----
gdb/gcore.c | 9 ++++++---
gdb/gdb_bfd.c | 12 ++++++++----
gdb/linespec.c | 1 +
gdb/linux-nat.c | 4 +++-
gdb/record-full.c | 25 +++++++++++++++----------
gdb/remote.c | 3 ++-
gdb/skip.c | 5 +++--
gdb/solib-aix.c | 16 ++++++++++------
gdb/solib-darwin.c | 7 +++++--
gdb/solib.c | 14 +++++++++-----
gdb/symfile.c | 30 ++++++++++++++++++------------
gdb/symmisc.c | 3 ++-
gdb/target.c | 34 ++++++++++++++++++++++------------
gdb/tracectf.c | 16 ++++++++++------
gdb/tracefile-tfile.c | 6 ++++--
gdb/utils.c | 4 +++-
gdb/xcoffread.c | 6 ++++--
gdb/xml-support.c | 5 ++++-
28 files changed, 217 insertions(+), 126 deletions(-)
diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 17d9f78f32d..a5ac26654cf 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -50,6 +50,7 @@
#include "x86-tdep.h"
#include "dwarf2/frame.h"
#include "frame-unwind.h"
+#include "cli/cli-style.h"
/* The syscall's XML filename for i386. */
#define XML_SYSCALL_FILENAME_AMD64 "syscalls/amd64-linux.xml"
@@ -1868,8 +1869,8 @@ amd64_linux_lam_untag_mask ()
errno = 0;
unsigned long long result = std::strtoul (start, &endptr, 0);
if (errno != 0 || endptr == start)
- error (_("Failed to parse untag_mask from file %s."),
- std::string (filename).c_str ());
+ error (_("Failed to parse untag_mask from file %ps."),
+ styled_string (file_name_style.style (), filename.c_str ()));
return result;
}
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index fdff6e8fc94..13e25067056 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -9498,8 +9498,10 @@ resolve_sal_pc (struct symtab_and_line *sal)
if (sal->pc == 0 && sal->symtab != NULL)
{
if (!find_pc_for_line (sal->symtab, sal->line, &pc))
- error (_("No line %d in file \"%s\"."),
- sal->line, symtab_to_filename_for_display (sal->symtab));
+ error (_("No line %d in file \"%ps\"."),
+ sal->line,
+ styled_string (file_name_style.style (),
+ symtab_to_filename_for_display (sal->symtab)));
sal->pc = pc;
/* If this SAL corresponds to a breakpoint inserted using a line
@@ -14543,8 +14545,10 @@ save_breakpoints (const char *filename, int from_tty,
stdio_file fp;
if (!fp.open (expanded_filename.get (), "w"))
- error (_("Unable to open file '%s' for saving (%s)"),
- expanded_filename.get (), safe_strerror (errno));
+ error (_("Unable to open file '%ps' for saving (%s)"),
+ styled_string (file_name_style.style (),
+ expanded_filename.get ()),
+ safe_strerror (errno));
if (extra_trace_bits)
save_trace_state_variables (&fp);
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 761158f2ae9..63f5a637697 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -1902,8 +1902,9 @@ save_user_command (const char *filename, int from_tty)
std::string expanded_filename = gdb_tilde_expand (filename);
stdio_file fp;
if (!fp.open (expanded_filename.c_str (), "w"))
- error (_("Unable to open file '%s' for saving (%s)"),
- expanded_filename.c_str (), safe_strerror (errno));
+ error (_("Unable to open file '%ps' for saving (%s)"),
+ styled_string (file_name_style.style (), expanded_filename.c_str ()),
+ safe_strerror (errno));
cli_ui_out uiout (&fp);
for (struct cmd_list_element *c = cmdlist; c != nullptr; c = c->next)
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
index 59c5827c093..66ab5922693 100644
--- a/gdb/cli/cli-dump.c
+++ b/gdb/cli/cli-dump.c
@@ -31,6 +31,7 @@
#include "gdbsupport/byte-vector.h"
#include "gdbarch.h"
#include "inferior.h"
+#include "cli/cli-style.h"
static gdb::unique_xmalloc_ptr<char>
scan_expression (const char **cmd, const char *def)
@@ -84,11 +85,13 @@ bfd_openr_or_error (const char *filename, const char *target)
{
gdb_bfd_ref_ptr ibfd (gdb_bfd_openr (filename, target));
if (ibfd == NULL)
- error (_("Failed to open %s: %s."), filename,
+ error (_("Failed to open %ps: %s."),
+ styled_string (file_name_style.style (), filename),
bfd_errmsg (bfd_get_error ()));
if (!bfd_check_format (ibfd.get (), bfd_object))
- error (_("'%s' is not a recognized file format."), filename);
+ error (_("'%ps' is not a recognized file format."),
+ styled_string (file_name_style.style (), filename));
return ibfd;
}
@@ -102,7 +105,8 @@ bfd_openw_or_error (const char *filename, const char *target, const char *mode)
{
obfd = gdb_bfd_openw (filename, target);
if (obfd == NULL)
- error (_("Failed to open %s: %s."), filename,
+ error (_("Failed to open %ps: %s."),
+ styled_string (file_name_style.style (), filename),
bfd_errmsg (bfd_get_error ()));
if (!bfd_set_format (obfd.get (), bfd_object))
error (_("bfd_openw_or_error: %s."), bfd_errmsg (bfd_get_error ()));
@@ -414,7 +418,8 @@ restore_one_section (bfd *ibfd, asection *isec,
/* Get the data. */
gdb::byte_vector buf (size);
if (!bfd_get_section_contents (ibfd, isec, buf.data (), 0, size))
- error (_("Failed to read bfd file %s: '%s'."), bfd_get_filename (ibfd),
+ error (_("Failed to read bfd file %ps: '%s'."),
+ styled_string (file_name_style.style (), bfd_get_filename (ibfd)),
bfd_errmsg (bfd_get_error ()));
gdb_printf ("Restoring section %s (0x%lx to 0x%lx)",
@@ -449,7 +454,9 @@ restore_binary_file (const char *filename, CORE_ADDR load_offset,
long len;
if (file == NULL)
- error (_("Failed to open %s: %s"), filename, safe_strerror (errno));
+ error (_("Failed to open %ps: %s"),
+ styled_string (file_name_style.style (), filename),
+ safe_strerror (errno));
/* Get the file size for reading. */
if (fseek (file.get (), 0, SEEK_END) == 0)
@@ -462,8 +469,8 @@ restore_binary_file (const char *filename, CORE_ADDR load_offset,
perror_with_name (filename);
if (len <= load_start)
- error (_("Start address is greater than length of binary file %s."),
- filename);
+ error (_("Start address is greater than length of binary file %ps."),
+ styled_string (file_name_style.style (), filename));
/* Chop off "len" if it exceeds the requested load_end addr. */
if (load_end != 0 && load_end < len)
diff --git a/gdb/coffread.c b/gdb/coffread.c
index f45b5efd5b3..0a5da42e563 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -27,6 +27,7 @@
#include "target.h"
#include "dwarf2/public.h"
#include "coff-pe-read.h"
+#include "cli/cli-style.h"
/* Simplified internal version of coff symbol table information. */
@@ -324,7 +325,8 @@ coff_reader::symfile_read (symfile_add_flags symfile_flags)
gdb::unique_xmalloc_ptr<char> stringtab_storage;
val = init_stringtab (stringtab_offset, &stringtab_storage);
if (val < 0)
- error (_("\"%s\": can't get string table"), filename);
+ error (_("\"%ps\": can't get string table"),
+ styled_string (file_name_style.style (), filename));
read_minsyms (symtab_offset, num_symbols);
@@ -386,8 +388,10 @@ coff_reader::symtab_read (minimal_symbol_reader &reader,
/* Position to read the symbol table. */
val = bfd_seek (symfile_bfd, symtab_offset, 0);
if (val < 0)
- error (_("Error reading symbols from %s: %s"),
- objfile_name (coffread_objfile), bfd_errmsg (bfd_get_error ()));
+ error (_("Error reading symbols from %ps: %s"),
+ styled_string (file_name_style.style (),
+ objfile_name (coffread_objfile)),
+ bfd_errmsg (bfd_get_error ()));
while (symnum < nsyms)
{
@@ -530,7 +534,9 @@ coff_reader::read_one_sym (struct coff_symbol *cs)
bytes = bfd_read (temp_sym, local_symesz, symfile_bfd);
if (bytes != local_symesz)
- error (_("%s: error reading symbols"), objfile_name (coffread_objfile));
+ error (_("%ps: error reading symbols"),
+ styled_string (file_name_style.style (),
+ objfile_name (coffread_objfile)));
bfd_coff_swap_sym_in (symfile_bfd, temp_sym, &sym);
cs->c_naux = sym.n_numaux & 0xff;
if (cs->c_naux >= 1)
@@ -540,8 +546,9 @@ coff_reader::read_one_sym (struct coff_symbol *cs)
{
bytes = bfd_read (temp_aux, local_auxesz, symfile_bfd);
if (bytes != local_auxesz)
- error (_("%s: error reading symbols"),
- objfile_name (coffread_objfile));
+ error (_("%ps: error reading symbols"),
+ styled_string (file_name_style.style (),
+ objfile_name (coffread_objfile)));
}
}
cs->c_name = getsymname (&sym);
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index fe48979e4f6..4ea924582fb 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -31,6 +31,7 @@
#include "block.h"
#include "arch-utils.h"
#include <algorithm>
+#include "cli/cli-style.h"
/* Add inferior mmap memory range ADDR..ADDR+SIZE (exclusive) to the
list. */
@@ -616,16 +617,18 @@ compile_object_load (const compile_file_names &file_names,
gdb_bfd_ref_ptr abfd (gdb_bfd_open (filename.get (), gnutarget));
if (abfd == NULL)
- error (_("\"%s\": could not open as compiled module: %s"),
- filename.get (), bfd_errmsg (bfd_get_error ()));
+ error (_("\"%ps\": could not open as compiled module: %s"),
+ styled_string (file_name_style.style (), filename.get ()),
+ bfd_errmsg (bfd_get_error ()));
if (!bfd_check_format_matches (abfd.get (), bfd_object, &matching))
- error (_("\"%s\": not in loadable format: %s"),
- filename.get (),
+ error (_("\"%ps\": not in loadable format: %s"),
+ styled_string (file_name_style.style (), filename.get ()),
gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
if ((bfd_get_file_flags (abfd.get ()) & (EXEC_P | DYNAMIC)) != 0)
- error (_("\"%s\": not in object format."), filename.get ());
+ error (_("\"%ps\": not in object format."),
+ styled_string (file_name_style.style (), filename.get ()));
struct setup_sections_data setup_sections_data (abfd.get ());
for (asection *sect : gdb_bfd_sections (abfd))
@@ -644,14 +647,15 @@ compile_object_load (const compile_file_names &file_names,
GCC_FE_WRAPPER_FUNCTION,
SEARCH_VFT).symbol;
if (func_sym == NULL)
- error (_("Cannot find function \"%s\" in compiled module \"%s\"."),
- GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile));
+ error (_("Cannot find function \"%s\" in compiled module \"%ps\"."),
+ GCC_FE_WRAPPER_FUNCTION,
+ styled_string (file_name_style.style (), objfile_name (objfile)));
func_type = func_sym->type ();
if (func_type->code () != TYPE_CODE_FUNC)
error (_("Invalid type code %d of function \"%s\" in compiled "
- "module \"%s\"."),
+ "module \"%ps\"."),
func_type->code (), GCC_FE_WRAPPER_FUNCTION,
- objfile_name (objfile));
+ styled_string (file_name_style.style (), objfile_name (objfile)));
switch (scope)
{
@@ -676,13 +680,14 @@ compile_object_load (const compile_file_names &file_names,
}
if (func_type->num_fields () != expect_parameters)
error (_("Invalid %d parameters of function \"%s\" in compiled "
- "module \"%s\"."),
+ "module \"%ps\"."),
func_type->num_fields (), GCC_FE_WRAPPER_FUNCTION,
- objfile_name (objfile));
+ styled_string (file_name_style.style (), objfile_name (objfile)));
if (!types_deeply_equal (expect_return_type, func_type->target_type ()))
error (_("Invalid return type of function \"%s\" in compiled "
- "module \"%s\"."),
- GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile));
+ "module \"%ps\"."),
+ GCC_FE_WRAPPER_FUNCTION,
+ styled_string (file_name_style.style (), objfile_name (objfile)));
gdb::array_view<asymbol *> symbol_table
= gdb_bfd_canonicalize_symtab (abfd.get ());
@@ -774,8 +779,9 @@ compile_object_load (const compile_file_names &file_names,
break;
default:
warning (_("Could not find symbol \"%s\" "
- "for compiled module \"%s\"."),
- sym->name, filename.get ());
+ "for compiled module \"%ps\"."),
+ sym->name,
+ styled_string (file_name_style.style (), filename.get ()));
missing_symbols++;
}
}
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 954607134f4..8548311b906 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -377,8 +377,9 @@ core_target::core_target (gdb_bfd_ref_ptr cbfd_ref)
if (!m_core_gdbarch
|| !gdbarch_iterate_over_regset_sections_p (m_core_gdbarch))
- error (_("\"%s\": Core file format not supported"),
- bfd_get_filename (this->core_bfd ()));
+ error (_("\"%ps\": Core file format not supported"),
+ styled_string (file_name_style.style (),
+ bfd_get_filename (this->core_bfd ())));
/* Find the data section */
m_core_section_table = build_section_table (this->core_bfd ());
@@ -1041,8 +1042,9 @@ core_target_open (const char *arg, int from_tty)
/* FIXME: should be checking for errors from bfd_close (for one
thing, on error it does not free all the storage associated
with the bfd). */
- error (_("\"%s\" is not a core dump: %s"),
- filename.c_str (), bfd_errmsg (bfd_get_error ()));
+ error (_("\"%ps\" is not a core dump: %s"),
+ styled_string (file_name_style.style (), filename.c_str ()),
+ bfd_errmsg (bfd_get_error ()));
}
core_target *target = new core_target (std::move (temp_bfd));
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index b95cdbed33c..0ddb2325344 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -84,6 +84,7 @@
#include "maint.h"
#include "objfiles.h"
#include "progspace.h"
+#include "cli/cli-style.h"
/* When true, print debug messages related to CTF reading. */
static bool debug_ctf = false;
@@ -1305,13 +1306,15 @@ elfctf_build_symtabs (objfile *objfile)
ctf_archive_up archive (ctf_bfdopen (abfd, &err));
if (archive == nullptr)
- error (_("ctf_bfdopen failed on %s - %s"),
- bfd_get_filename (abfd), ctf_errmsg (err));
+ error (_("ctf_bfdopen failed on %ps - %s"),
+ styled_string (file_name_style.style (), bfd_get_filename (abfd)),
+ ctf_errmsg (err));
ctf_dict_up dict (ctf_dict_open (archive.get (), NULL, &err));
if (dict == nullptr)
- error (_("ctf_dict_open failed on %s - %s"),
- bfd_get_filename (abfd), ctf_errmsg (err));
+ error (_("ctf_dict_open failed on %ps - %s"),
+ styled_string (file_name_style.style (), bfd_get_filename (abfd)),
+ ctf_errmsg (err));
ctf_per_objfile &per_objfile
= ctf_per_objfile_key.emplace (objfile, objfile, std::move (archive),
@@ -1321,8 +1324,9 @@ elfctf_build_symtabs (objfile *objfile)
if (ctf_archive_iter (per_objfile.archive.get (), build_ctf_archive_member,
&iter_data)
< 0)
- error (_("ctf_archive_iter failed in input file %s: - %s"),
- bfd_get_filename (abfd), ctf_errmsg (err));
+ error (_("ctf_archive_iter failed in input file %ps: - %s"),
+ styled_string (file_name_style.style (), bfd_get_filename (abfd)),
+ ctf_errmsg (err));
objfile->qf.emplace_front (std::make_unique<expanded_symbols_functions>
(std::move (iter_data.compunit_symtabs)));
diff --git a/gdb/dwarf2/dwz.c b/gdb/dwarf2/dwz.c
index b403265a18d..8f3d52567ec 100644
--- a/gdb/dwarf2/dwz.c
+++ b/gdb/dwarf2/dwz.c
@@ -97,7 +97,8 @@ locate_dwz_sections (objfile *objfile, dwz_file &dwz_file)
static void
debug_sup_failure (const char *text, bfd *abfd)
{
- error (_("%s [in modules %s]"), text, bfd_get_filename (abfd));
+ error (_("%s [in modules %ps]"), text,
+ styled_string (file_name_style.style (), bfd_get_filename (abfd)));
}
/* Look for the .debug_sup section and read it. If the section does
@@ -390,9 +391,9 @@ dwz_file::read_dwz_file (dwarf2_per_objfile *per_objfile)
}
if (dwz_bfd == NULL)
- error (_("could not find supplementary DWARF file (%s) for %s"),
- filename.c_str (),
- per_bfd->filename ());
+ error (_("could not find supplementary DWARF file (%ps) for %ps"),
+ styled_string (file_name_style.style (), filename.c_str ()),
+ styled_string (file_name_style.style (), per_bfd->filename ()));
dwz_file_up result (new dwz_file (std::move (dwz_bfd)));
diff --git a/gdb/exec.c b/gdb/exec.c
index b1b2d2d190d..873686e6286 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -463,10 +463,9 @@ exec_file_attach (const char *filename, int from_tty)
current_program_space->set_exec_bfd (std::move (temp));
if (!current_program_space->exec_bfd ())
- {
- error (_("\"%s\": could not open as an executable file: %s."),
- scratch_pathname, bfd_errmsg (bfd_get_error ()));
- }
+ error (_("\"%ps\": could not open as an executable file: %s."),
+ styled_string (file_name_style.style (), scratch_pathname),
+ bfd_errmsg (bfd_get_error ()));
/* gdb_realpath_keepfile resolves symlinks on the local
filesystem and so cannot be used for "target:" files. */
@@ -486,7 +485,8 @@ exec_file_attach (const char *filename, int from_tty)
/* Make sure to close exec_bfd, or else "run" might try to use
it. */
current_program_space->exec_close ();
- error (_("\"%s\": not in executable format: %s"), scratch_pathname,
+ error (_("\"%ps\": not in executable format: %s"),
+ styled_string (file_name_style.style (), scratch_pathname),
gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
}
diff --git a/gdb/gcore.c b/gdb/gcore.c
index 48e431ed8f9..ff429098b7e 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -37,6 +37,7 @@
#include "gdbsupport/byte-vector.h"
#include "gdbsupport/scope-exit.h"
#include "auxv.h"
+#include "cli/cli-style.h"
/* To generate sparse cores, we look at the data to write in chunks of
this size when considering whether to skip the write. Only if we
@@ -67,7 +68,8 @@ create_gcore_bfd (const char *filename)
gdb_bfd_ref_ptr obfd (gdb_bfd_openw (filename, default_gcore_target ()));
if (obfd == NULL)
- error (_("Failed to open '%s' for output."), filename);
+ error (_("Failed to open '%ps' for output."),
+ styled_string (file_name_style.style (), filename));
bfd_set_format (obfd.get (), bfd_core);
bfd_set_arch_mach (obfd.get (), default_gcore_arch (), 0);
return obfd;
@@ -101,8 +103,9 @@ write_gcore_file_1 (bfd *obfd)
| SEC_READONLY
| SEC_ALLOC);
if (note_sec == NULL)
- error (_("Failed to create 'note' section for corefile: %s"),
- bfd_errmsg (bfd_get_error ()));
+ error (_("Failed to create 'note' section for corefile: %ps"),
+ styled_string (file_name_style.style (),
+ bfd_errmsg (bfd_get_error ())));
bfd_set_section_vma (note_sec, 0);
bfd_set_section_alignment (note_sec, 0);
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index 342957273cd..952875955ad 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -834,8 +834,10 @@ get_file_crc (bfd *abfd, unsigned long *file_crc_return)
if (bfd_seek (abfd, 0, SEEK_SET) != 0)
{
- warning (_("Problem reading \"%s\" for CRC: %s"),
- bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
+ warning (_("Problem reading \"%ps\" for CRC: %s"),
+ styled_string (file_name_style.style (),
+ bfd_get_filename (abfd)),
+ bfd_errmsg (bfd_get_error ()));
return 0;
}
@@ -847,8 +849,10 @@ get_file_crc (bfd *abfd, unsigned long *file_crc_return)
count = bfd_read (buffer, sizeof (buffer), abfd);
if (count == (bfd_size_type) -1)
{
- warning (_("Problem reading \"%s\" for CRC: %s"),
- bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
+ warning (_("Problem reading \"%ps\" for CRC: %s"),
+ styled_string (file_name_style.style (),
+ bfd_get_filename (abfd)),
+ bfd_errmsg (bfd_get_error ()));
return 0;
}
if (count == 0)
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 7624c92ab25..981bd5faa4f 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -45,6 +45,7 @@
#include <algorithm>
#include "inferior.h"
#include "gdbsupport/unordered_set.h"
+#include "cli/cli-style.h"
/* An enumeration of the various things a user might attempt to
complete for a linespec location. */
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 1d0a4609a3a..218ead00136 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -63,6 +63,7 @@
#include "gdbsupport/scope-exit.h"
#include "gdbsupport/gdb-sigmask.h"
#include "gdbsupport/common-debug.h"
+#include "cli/cli-style.h"
/* This comment documents high-level logic of this file.
@@ -4305,7 +4306,8 @@ linux_proc_pending_signals (int pid, sigset_t *pending,
xsnprintf (fname, sizeof fname, "/proc/%d/status", pid);
gdb_file_up procfile = gdb_fopen_cloexec (fname, "r");
if (procfile == NULL)
- error (_("Could not open %s"), fname);
+ error (_("Could not open %ps"),
+ styled_string (file_name_style.style () ,fname));
while (fgets (buffer, PATH_MAX, procfile.get ()) != NULL)
{
diff --git a/gdb/record-full.c b/gdb/record-full.c
index e0af376f3eb..942bf983792 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -45,6 +45,7 @@
#include "top.h"
#include "valprint.h"
#include "interps.h"
+#include "cli/cli-style.h"
#include <signal.h>
@@ -2310,8 +2311,9 @@ bfdcore_read (bfd *obfd, asection *osec, void *buf, int len, int *offset)
if (ret)
*offset += len;
else
- error (_("Failed to read %d bytes from core file %s ('%s')."),
- len, bfd_get_filename (obfd),
+ error (_("Failed to read %d bytes from core file %ps ('%s')."),
+ len, styled_string (file_name_style.style (),
+ bfd_get_filename (obfd)),
bfd_errmsg (bfd_get_error ()));
}
@@ -2366,8 +2368,9 @@ record_full_restore (struct bfd &cbfd)
/* Check the magic code. */
bfdcore_read (&cbfd, osec, &magic, sizeof (magic), &bfd_offset);
if (magic != RECORD_FULL_FILE_MAGIC)
- error (_("Version mismatch or file format error in core file %s."),
- bfd_get_filename (&cbfd));
+ error (_("Version mismatch or file format error in core file %ps."),
+ styled_string (file_name_style.style (),
+ bfd_get_filename (&cbfd)));
if (record_debug)
gdb_printf (gdb_stdlog,
" Reading 4-byte magic cookie "
@@ -2470,8 +2473,9 @@ record_full_restore (struct bfd &cbfd)
break;
default:
- error (_("Bad entry type in core file %s."),
- bfd_get_filename (&cbfd));
+ error (_("Bad entry type in core file %ps."),
+ styled_string (file_name_style.style (),
+ bfd_get_filename (&cbfd)));
break;
}
@@ -2516,8 +2520,9 @@ bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset)
if (ret)
*offset += len;
else
- error (_("Failed to write %d bytes to core file %s ('%s')."),
- len, bfd_get_filename (obfd),
+ error (_("Failed to write %d bytes to core file %ps ('%s')."),
+ len, styled_string (file_name_style.style (),
+ bfd_get_filename (obfd)),
bfd_errmsg (bfd_get_error ()));
}
@@ -2601,8 +2606,8 @@ record_full_base_target::save_record (const char *recfilename)
SEC_HAS_CONTENTS
| SEC_READONLY);
if (osec == NULL)
- error (_("Failed to create 'precord' section for corefile %s: %s"),
- recfilename,
+ error (_("Failed to create 'precord' section for corefile %ps: %s"),
+ styled_string (file_name_style.style (), recfilename),
bfd_errmsg (bfd_get_error ()));
bfd_set_section_size (osec, save_size);
bfd_set_section_vma (osec, 0);
diff --git a/gdb/remote.c b/gdb/remote.c
index 23ef6145620..0317119f292 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -13998,7 +13998,8 @@ remote_target::remote_file_put (const char *local_file, const char *remote_file,
if (bytes == 0)
{
if (ferror (file.get ()))
- error (_("Error reading %s."), local_file);
+ error (_("Error reading %ps."),
+ styled_string (file_name_style.style (), local_file));
else
{
/* EOF. Unless there is something still in the
diff --git a/gdb/skip.c b/gdb/skip.c
index eb47cee9e34..917b084860d 100644
--- a/gdb/skip.c
+++ b/gdb/skip.c
@@ -1373,8 +1373,9 @@ save_skip_command (const char *filename, int from_tty)
gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename));
stdio_file fp;
if (!fp.open (expanded_filename.get (), "w"))
- error (_("Unable to open file '%s' for saving (%s)"),
- expanded_filename.get (), safe_strerror (errno));
+ error (_("Unable to open file '%ps' for saving (%s)"),
+ styled_string (file_name_style.style (), expanded_filename.get ()),
+ safe_strerror (errno));
for (const auto &entry : skiplist_entries)
entry.print_recreate (&fp);
diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c
index d4367973ad5..4f029529106 100644
--- a/gdb/solib-aix.c
+++ b/gdb/solib-aix.c
@@ -23,6 +23,7 @@
#include "symtab.h"
#include "xcoffread.h"
#include "observable.h"
+#include "cli/cli-style.h"
/* solib_ops for AIX systems. */
@@ -540,8 +541,9 @@ aix_solib_ops::bfd_open (const char *pathname) const
found_file));
if (archive_bfd == NULL)
{
- warning (_("Could not open `%s' as an executable file: %s"),
- filename.c_str (), bfd_errmsg (bfd_get_error ()));
+ warning (_("Could not open `%ps' as an executable file: %s"),
+ styled_string (file_name_style.style (), filename.c_str ()),
+ bfd_errmsg (bfd_get_error ()));
return NULL;
}
@@ -550,8 +552,9 @@ aix_solib_ops::bfd_open (const char *pathname) const
if (! bfd_check_format (archive_bfd.get (), bfd_archive))
{
- warning (_("\"%s\": not in executable format: %s."),
- filename.c_str (), bfd_errmsg (bfd_get_error ()));
+ warning (_("\"%ps\": not in executable format: %s."),
+ styled_string (file_name_style.style (), filename.c_str ()),
+ bfd_errmsg (bfd_get_error ()));
return NULL;
}
@@ -589,8 +592,9 @@ aix_solib_ops::bfd_open (const char *pathname) const
if (! bfd_check_format (object_bfd.get (), bfd_object))
{
- warning (_("%s(%s): not in object format: %s."),
- filename.c_str (), member_name.c_str (),
+ warning (_("%ps(%s): not in object format: %s."),
+ styled_string (file_name_style.style (), filename.c_str ()),
+ member_name.c_str (),
bfd_errmsg (bfd_get_error ()));
return NULL;
}
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index 3412f662910..6e2535ca427 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -26,6 +26,7 @@
#include "inferior.h"
#include "regcache.h"
#include "gdb_bfd.h"
+#include "cli/cli-style.h"
#include "solib.h"
#include "solib-darwin.h"
@@ -623,8 +624,10 @@ darwin_solib_ops::bfd_open (const char *pathname) const
(abfd.get (), bfd_object,
gdbarch_bfd_arch_info (current_inferior ()->arch ())));
if (res == NULL)
- error (_("`%s': not a shared-library: %s"),
- bfd_get_filename (abfd.get ()), bfd_errmsg (bfd_get_error ()));
+ error (_("`%ps': not a shared-library: %s"),
+ styled_string (file_name_style.style (),
+ bfd_get_filename (abfd.get ())),
+ bfd_errmsg (bfd_get_error ()));
/* The current filename for fat-binary BFDs is a name generated
by BFD, usually a string containing the name of the architecture.
diff --git a/gdb/solib.c b/gdb/solib.c
index 2cf9e17738d..782b844aa2f 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -387,7 +387,8 @@ solib_bfd_fopen (const char *pathname, int fd)
gdb_bfd_ref_ptr abfd (gdb_bfd_open (pathname, gnutarget, fd));
if (abfd == NULL)
- error (_("Could not open `%s' as an executable file: %s"), pathname,
+ error (_("Could not open `%ps' as an executable file: %s"),
+ styled_string (file_name_style.style (), pathname),
bfd_errmsg (bfd_get_error ()));
return abfd;
@@ -419,15 +420,18 @@ solib_bfd_open (const char *pathname)
/* Check bfd format. */
if (!bfd_check_format (abfd.get (), bfd_object))
- error (_("`%s': not in executable format: %s"),
- bfd_get_filename (abfd.get ()), bfd_errmsg (bfd_get_error ()));
+ error (_("`%ps': not in executable format: %s"),
+ styled_string (file_name_style.style (),
+ bfd_get_filename (abfd.get ())),
+ bfd_errmsg (bfd_get_error ()));
/* Check bfd arch. */
b = gdbarch_bfd_arch_info (current_inferior ()->arch ());
if (!b->compatible (b, bfd_get_arch_info (abfd.get ())))
- error (_("`%s': Shared library architecture %s is not compatible "
+ error (_("`%ps': Shared library architecture %s is not compatible "
"with target architecture %s."),
- bfd_get_filename (abfd.get ()),
+ styled_string (file_name_style.style (),
+ bfd_get_filename (abfd.get ())),
bfd_get_arch_info (abfd.get ())->printable_name, b->printable_name);
return abfd;
diff --git a/gdb/symfile.c b/gdb/symfile.c
index e3aa81fbc0c..d0ea9506c63 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1699,11 +1699,13 @@ symfile_bfd_open (const char *name)
gdb_bfd_ref_ptr sym_bfd (gdb_bfd_open (name, gnutarget, desc));
if (sym_bfd == NULL)
- error (_("`%s': can't open to read symbols: %s."), name,
+ error (_("`%ps': can't open to read symbols: %s."),
+ styled_string (file_name_style.style (), name),
bfd_errmsg (bfd_get_error ()));
if (!bfd_check_format (sym_bfd.get (), bfd_object))
- error (_("`%s': can't read symbols: %s."), name,
+ error (_("`%ps': can't read symbols: %s."),
+ styled_string (file_name_style.style (), name),
bfd_errmsg (bfd_get_error ()));
return sym_bfd;
@@ -1766,8 +1768,9 @@ find_sym_fns (bfd *abfd)
iter != symtab_fns.end ())
return iter->second;
- error (_("Object file %s could not be read. Symbol format `%s' unknown."),
- abfd->filename, bfd_get_target (abfd));
+ error (_("Object file %ps could not be read. Symbol format `%s' unknown."),
+ styled_string (file_name_style.style (), abfd->filename),
+ bfd_get_target (abfd));
}
\f
@@ -2013,10 +2016,9 @@ generic_load (const char *args, int from_tty)
perror_with_name (filename.get ());
if (!bfd_check_format (loadfile_bfd.get (), bfd_object))
- {
- error (_("\"%s\" is not an object file: %s"), filename.get (),
- bfd_errmsg (bfd_get_error ()));
- }
+ error (_("\"%ps\" is not an object file: %s"),
+ styled_string (file_name_style.style (), filename.get ()),
+ bfd_errmsg (bfd_get_error ()));
for (asection *asec : gdb_bfd_sections (loadfile_bfd))
total_progress.total_size += bfd_section_size (asec);
@@ -2436,8 +2438,9 @@ remove_symbol_file_command (const char *args, int from_tty)
error (_("No symbol file found"));
if (from_tty
- && !query (_("Remove symbol table from file \"%s\"? "),
- objfile_name (objf)))
+ && !query (_("Remove symbol table from file \"%ps\"? "),
+ styled_string (file_name_style.style (),
+ objfile_name (objf))))
error (_("Not confirmed."));
objf->unlink ();
@@ -2551,14 +2554,17 @@ reread_symbols (int from_tty)
gdb_bfd_ref_ptr temp (gdb_bfd_open (obfd_filename, gnutarget));
objfile.obfd = std::move (temp);
if (objfile.obfd == NULL)
- error (_("Can't open %s to read symbols."), obfd_filename);
+ error (_("Can't open %ps to read symbols."),
+ styled_string (file_name_style.style (), obfd_filename));
}
std::string original_name = objfile.original_name;
/* bfd_openr sets cacheable to true, which is what we want. */
if (!bfd_check_format (objfile.obfd.get (), bfd_object))
- error (_("Can't read symbols from %s: %s."), objfile_name (&objfile),
+ error (_("Can't read symbols from %ps: %s."),
+ styled_string (file_name_style.style (),
+ objfile_name (&objfile)),
bfd_errmsg (bfd_get_error ()));
objfile.compunit_symtabs.clear ();
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index a6dbb3b0603..b586f8fdb00 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -499,7 +499,8 @@ maintenance_print_symbols (const char *args, int from_tty)
}
if (source_arg != NULL && !found)
- error (_("No symtab for source file: %s"), source_arg);
+ error (_("No symtab for source file: %ps"),
+ styled_string (file_name_style.style (), source_arg));
}
}
diff --git a/gdb/target.c b/gdb/target.c
index 60c04b04b01..c7a6a318c8f 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1314,39 +1314,49 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset,
break;
case TLS_LOAD_MODULE_NOT_FOUND_ERROR:
if (objfile_is_library)
- error (_("Cannot find shared library `%s' in dynamic"
- " linker's load module list"), objfile_name (objfile));
+ error (_("Cannot find shared library `%ps' in dynamic"
+ " linker's load module list"),
+ styled_string (file_name_style.style (),
+ objfile_name (objfile)));
else
- error (_("Cannot find executable file `%s' in dynamic"
- " linker's load module list"), objfile_name (objfile));
+ error (_("Cannot find executable file `%ps' in dynamic"
+ " linker's load module list"),
+ styled_string (file_name_style.style (),
+ objfile_name (objfile)));
break;
case TLS_NOT_ALLOCATED_YET_ERROR:
if (objfile_is_library)
error (_("The inferior has not yet allocated storage for"
" thread-local variables in\n"
- "the shared library `%s'\n"
+ "the shared library `%ps'\n"
"for %s"),
- objfile_name (objfile),
+ styled_string (file_name_style.style (),
+ objfile_name (objfile)),
target_pid_to_str (ptid).c_str ());
else
error (_("The inferior has not yet allocated storage for"
" thread-local variables in\n"
- "the executable `%s'\n"
+ "the executable `%ps'\n"
"for %s"),
- objfile_name (objfile),
+ styled_string (file_name_style.style (),
+ objfile_name (objfile)),
target_pid_to_str (ptid).c_str ());
break;
case TLS_GENERIC_ERROR:
if (objfile_is_library)
error (_("Cannot find thread-local storage for %s, "
- "shared library %s:\n%s"),
+ "shared library %ps:\n%s"),
target_pid_to_str (ptid).c_str (),
- objfile_name (objfile), ex.what ());
+ styled_string (file_name_style.style (),
+ objfile_name (objfile)),
+ ex.what ());
else
error (_("Cannot find thread-local storage for %s, "
- "executable file %s:\n%s"),
+ "executable file %ps:\n%s"),
target_pid_to_str (ptid).c_str (),
- objfile_name (objfile), ex.what ());
+ styled_string (file_name_style.style (),
+ objfile_name (objfile)),
+ ex.what ());
break;
default:
throw;
diff --git a/gdb/tracectf.c b/gdb/tracectf.c
index aff2da55d66..9246022b517 100644
--- a/gdb/tracectf.c
+++ b/gdb/tracectf.c
@@ -31,6 +31,7 @@
#include <algorithm>
#include "gdbsupport/filestuff.h"
#include "gdbarch.h"
+#include "cli/cli-style.h"
/* GDB saves trace buffers and other information (such as trace
status) got from the remote target into Common Trace Format (CTF).
@@ -317,8 +318,9 @@ ctf_start (struct trace_file_writer *self, const char *dirname)
/* Create DIRNAME. */
if (mkdir (dirname, hmode) && errno != EEXIST)
- error (_("Unable to open directory '%s' for saving trace data (%s)"),
- dirname, safe_strerror (errno));
+ error (_("Unable to open directory '%ps' for saving trace data (%s)"),
+ styled_string (file_name_style.style (), dirname),
+ safe_strerror (errno));
memset (&writer->tcs, '\0', sizeof (writer->tcs));
@@ -327,8 +329,9 @@ ctf_start (struct trace_file_writer *self, const char *dirname)
writer->tcs.metadata_fd
= gdb_fopen_cloexec (file_name.c_str (), "w").release ();
if (writer->tcs.metadata_fd == NULL)
- error (_("Unable to open file '%s' for saving trace data (%s)"),
- file_name.c_str (), safe_strerror (errno));
+ error (_("Unable to open file '%ps' for saving trace data (%s)"),
+ styled_string (file_name_style.style (), file_name.c_str ()),
+ safe_strerror (errno));
ctf_save_metadata_header (&writer->tcs);
@@ -336,8 +339,9 @@ ctf_start (struct trace_file_writer *self, const char *dirname)
writer->tcs.datastream_fd
= gdb_fopen_cloexec (file_name.c_str (), "w").release ();
if (writer->tcs.datastream_fd == NULL)
- error (_("Unable to open file '%s' for saving trace data (%s)"),
- file_name.c_str (), safe_strerror (errno));
+ error (_("Unable to open file '%ps' for saving trace data (%s)"),
+ styled_string (file_name_style.style (), file_name.c_str ()),
+ safe_strerror (errno));
}
/* This is the implementation of trace_file_write_ops method
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index a6f5ae16b91..289e00ff531 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -32,6 +32,7 @@
#include "target-descriptions.h"
#include "gdbsupport/pathstuff.h"
#include <algorithm>
+#include "cli/cli-style.h"
#ifndef O_LARGEFILE
#define O_LARGEFILE 0
@@ -123,8 +124,9 @@ tfile_start (struct trace_file_writer *self, const char *filename)
writer->pathname = gdb_rl_tilde_expand (filename).release ();
writer->fp = gdb_fopen_cloexec (writer->pathname, "wb").release ();
if (writer->fp == NULL)
- error (_("Unable to open file '%s' for saving trace data (%s)"),
- writer->pathname, safe_strerror (errno));
+ error (_("Unable to open file '%ps' for saving trace data (%s)"),
+ styled_string (file_name_style.style (), writer->pathname),
+ safe_strerror (errno));
}
/* This is the implementation of trace_file_write_ops method
diff --git a/gdb/utils.c b/gdb/utils.c
index b073bb9fdf3..f5f19301460 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -3727,7 +3727,9 @@ extract_single_filename_arg (const char *args)
std::string filename = extract_string_maybe_quoted (&args);
args = skip_spaces (args);
if (*args != '\0')
- error (_("Junk after filename \"%s\": %s"), filename.c_str (), args);
+ error (_("Junk after filename \"%ps\": %s"),
+ styled_string (file_name_style.style (), filename.c_str ()),
+ args);
if (!filename.empty ())
filename = gdb_tilde_expand (filename.c_str ());
return filename;
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index fb223416240..73662c47c3d 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -35,6 +35,7 @@
#include "complaints.h"
#include "dwarf2/sect-names.h"
#include "dwarf2/public.h"
+#include "cli/cli-style.h"
struct xcoff_symfile_info
{
@@ -134,8 +135,9 @@ xcoff_find_toc_offset (objfile *objfile)
/* Seek to symbol table location. */
if (bfd_seek (abfd, symtab_offset, SEEK_SET) < 0)
- error (_("Error reading symbols from %s: %s"),
- objfile_name (objfile), bfd_errmsg (bfd_get_error ()));
+ error (_("Error reading symbols from %ps: %s"),
+ styled_string (file_name_style.style (), objfile_name (objfile)),
+ bfd_errmsg (bfd_get_error ()));
unsigned int num_symbols = bfd_get_symcount (abfd);
size_t size = coff_data (abfd)->local_symesz * num_symbols;
diff --git a/gdb/xml-support.c b/gdb/xml-support.c
index a538c16f926..d806b53c9fa 100644
--- a/gdb/xml-support.c
+++ b/gdb/xml-support.c
@@ -23,6 +23,8 @@
#include "gdbsupport/filestuff.h"
#include <vector>
#include <string>
+#include "cli/cli-style.h"
+#include "ui-out.h"
/* Debugging flag. */
static bool debug_xml;
@@ -990,7 +992,8 @@ xml_fetch_content_from_file (const char *filename, const char *dirname)
if (fread (text.data (), 1, len, file.get ()) != len
|| ferror (file.get ()))
{
- warning (_("Read error from \"%s\""), filename);
+ warning (_("Read error from \"%ps\""),
+ styled_string (file_name_style.style (), filename));
return {};
}
--
2.49.0
next prev parent reply other threads:[~2026-04-05 11:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-05 11:28 [PATCH 0/4] Add more styling of " Tom Tromey
2026-04-05 11:28 ` [PATCH 1/4] Add command styling to " Tom Tromey
2026-04-05 11:28 ` Tom Tromey [this message]
2026-04-05 11:28 ` [PATCH 3/4] Add variable " Tom Tromey
2026-04-05 11:28 ` [PATCH 4/4] Add function " Tom Tromey
2026-04-05 12:55 ` [PATCH 0/4] Add more styling of " Andrew Burgess
2026-04-09 1:10 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260405-more-error-style-v1-2-6c04da718875@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox