+2020-08-24 Simon Marchi <simon.marchi@efficios.com>
+
+ * debug.h: New file.
+ * debug.c (debug_prefixed_vprintf): New function.
+ * infrun.c (infrun_debug_printf_1): Use debug_prefixed_vprintf.
+ * linux-nat.c (linux_nat_debug_printf_1): Likewise.
+
2020-08-24 Simon Marchi <simon.marchi@efficios.com>
* infrun.h (infrun_debug_printf_1): New function declaration.
#include "defs.h"
+#include "debug.h"
+
/* See gdbsupport/common-debug.h. */
void
{
vfprintf_unfiltered (gdb_stdlog, fmt, ap);
}
+
+/* See debug.h. */
+
+void
+debug_prefixed_vprintf (const char *module, const char *func, const char *format,
+ va_list args)
+{
+ debug_printf ("[%s] %s: ", module, func);
+ debug_vprintf (format, args);
+ debug_printf ("\n");
+}
--- /dev/null
+/* Helpers to format and print debug statements
+
+ Copyright (C) 2020 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef DEBUG_H
+#define DEBUG_H
+
+/* Print a debug statement prefixed with the module and function name, and
+ with a newline at the end. */
+
+void ATTRIBUTE_PRINTF (3, 0)
+debug_prefixed_vprintf (const char *module, const char *func, const char *format,
+ va_list args);
+
+#endif /* DEBUG_H */
+
+
#include "gdbsupport/selftest.h"
#include "scoped-mock-context.h"
#include "test-target.h"
+#include "debug.h"
/* Prototypes for local functions */
void
infrun_debug_printf_1 (const char *func_name, const char *fmt, ...)
{
- debug_printf ("[infrun] %s: ", func_name);
-
va_list ap;
va_start (ap, fmt);
- debug_vprintf (fmt, ap);
+ debug_prefixed_vprintf ("infrun", func_name, fmt, ap);
va_end (ap);
-
- debug_printf ("\n");
}
/* See infrun.h. */
#include "gdbsupport/fileio.h"
#include "gdbsupport/scope-exit.h"
#include "gdbsupport/gdb-sigmask.h"
+#include "debug.h"
/* This comment documents high-level logic of this file.
static void ATTRIBUTE_PRINTF (2, 3)
linux_nat_debug_printf_1 (const char *func_name, const char *fmt, ...)
{
- debug_printf ("[linux-nat] %s: ", func_name);
-
va_list ap;
va_start (ap, fmt);
- debug_vprintf (fmt, ap);
+ debug_prefixed_vprintf ("linux-nat", func_name, fmt, ap);
va_end (ap);
-
- debug_printf ("\n");
}
#define linux_nat_debug_printf(fmt, ...) \