{
if (result < 0)
{
- print_sys_errmsg (msg, errno);
+ gdb_printf (gdb_stderr, "%s:%s.\n", msg,
+ safe_strerror (errno));
_exit (1);
}
}
struct stat st;
if (stat (new_datadir, &st) < 0)
- {
- int save_errno = errno;
-
- gdb_printf (gdb_stderr, "Warning: ");
- print_sys_errmsg (new_datadir, save_errno);
- }
+ warning_filename_and_errno (new_datadir, errno);
else if (!S_ISDIR (st.st_mode))
warning (_("%ps is not a directory."),
styled_string (file_name_style.style (), new_datadir));
#include "gdbsupport/scoped_fd.h"
#include "gdbsupport/pathstuff.h"
#include "gdbsupport/buildargv.h"
+#include "cli/cli-style.h"
/* This module provides the interface between GDB and the
/proc file system, which is used on many versions of Unix
static void
dead_procinfo (procinfo *pi, const char *msg, int kill_p)
{
- print_sys_errmsg (pi->pathname, errno);
+ warning_filename_and_errno (pi->pathname, errno);
if (kill_p == KILL)
kill (pi->pid, SIGKILL);
proc_warn (procinfo *pi, const char *func, int line)
{
int saved_errno = errno;
- std::string errmsg
- = string_printf ("procfs: %s line %d, %s", func, line, pi->pathname);
- print_sys_errmsg (errmsg.c_str (), saved_errno);
+ warning ("procfs: %s line %d, %ps: %s",
+ func, line, styled_string (file_name_style.style (),
+ pi->pathname),
+ safe_strerror (saved_errno));
}
static void
proc_error (procinfo *pi, const char *func, int line)
{
int saved_errno = errno;
- std::string errmsg
- = string_printf ("procfs: %s line %d, %s", func, line, pi->pathname);
- perror_with_name (errmsg.c_str (), saved_errno);
+ error ("procfs: %s line %d, %ps: %s",
+ func, line, styled_string (file_name_style.style (),
+ pi->pathname),
+ safe_strerror (saved_errno));
}
/* Updates the status struct in the procinfo. There is a 'valid'
a directory/etc, then having them in the path should be
harmless. */
if (stat (name, &st) < 0)
- {
- int save_errno = errno;
-
- gdb_printf (gdb_stderr, "Warning: ");
- print_sys_errmsg (name, save_errno);
- }
+ warning_filename_and_errno (name, errno);
else if ((st.st_mode & S_IFMT) != S_IFDIR)
warning (_("%ps is not a directory."),
styled_string (file_name_style.style (), name));
if (!(flags & PRINT_SOURCE_LINES_NOERROR))
{
const char *filename = symtab_to_filename_for_display (s);
- int len = strlen (filename) + 100;
- char *name = (char *) alloca (len);
-
- xsnprintf (name, len, "%d\t%s", line, filename);
- print_sys_errmsg (name, errcode);
+ warning (_("%d\t%ps: %s"), line,
+ styled_string (file_name_style.style (), filename),
+ safe_strerror (errcode));
}
else
{
int res = stat (filename, &new_statbuf);
if (res != 0)
{
- /* FIXME, should use print_sys_errmsg but it's not filtered. */
- gdb_printf (_("`%ps' has disappeared; keeping its symbols.\n"),
- styled_string (file_name_style.style (), filename));
+ warning (_("`%ps' has disappeared; keeping its symbols."),
+ styled_string (file_name_style.style (), filename));
continue;
}
time_t new_modtime = new_statbuf.st_mtime;
# Make sure GDB doesn't load the syscalls xml from the system
# data directory.
gdb_test "set data-directory /the/path/to/nowhere" \
- "Warning: /the/path/to/nowhere: .*"
+ "warning: /the/path/to/nowhere: .*"
# Testing to see if we receive a warning when calling "catch
# syscall" without XML support (without datadir).
# Make sure GDB doesn't load the syscalls xml from the system data
# directory.
gdb_test "set data-directory /the/path/to/nowhere" \
- "Warning: /the/path/to/nowhere: .*"
+ "warning: /the/path/to/nowhere: .*"
# Let's test if we can catch syscalls without XML support.
# We should succeed, but GDB is not supposed to print syscall names.
}
gdb_test "l imported_unit.c:1" \
- "1\timported_unit.c: No such file or directory\."
+ "warning: 1\timported_unit.c: No such file or directory"
gdb_test "info source" "\r\nCurrent source file is imported_unit.c\r\n.*" \
"info source for imported_unit.c"
warning (_("%s"), combined.c_str ());
}
-/* Print the system error message for ERRCODE, and also mention STRING
- as the file name for which the error was encountered. */
+/* See utils.h. */
void
-print_sys_errmsg (const char *string, int errcode)
+warning_filename_and_errno (const char *filename, int saved_errno)
{
- const char *err = safe_strerror (errcode);
- gdb_printf (gdb_stderr, "%s: %s.\n", string, err);
+ warning (_("%ps: %s"), styled_string (file_name_style.style (), filename),
+ safe_strerror (saved_errno));
}
/* Control C eventually causes this to be called, at a convenient time. */
extern void perror_warning_with_name (const char *string);
-extern void print_sys_errmsg (const char *, int);
+/* Issue a warning formatted as '<filename>: <explanation>', where
+ <filename> is FILENAME with filename styling applied. As such, don't
+ pass anything more than a filename in this string. The <explanation>
+ is a string returned from calling safe_strerror(SAVED_ERRNO). */
+
+extern void warning_filename_and_errno (const char *filename,
+ int saved_errno);
\f
/* Warnings and error messages. */
tty = open (inferior_tty.c_str (), O_RDWR | O_NOCTTY);
if (tty < 0)
{
- print_sys_errmsg (inferior_tty.c_str (), errno);
+ warning_filename_and_errno (inferior_tty.c_str (), errno);
ostdin = ostdout = ostderr = -1;
}
else