[binutils-gdb] gdb: add debug_prefixed_vprintf

Simon Marchi simark@sourceware.org
Mon Aug 24 19:53:28 GMT 2020


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c426fddb87d29034b50c2433e12a08aa23b7fb9f

commit c426fddb87d29034b50c2433e12a08aa23b7fb9f
Author: Simon Marchi <simon.marchi@efficios.com>
Date:   Mon Aug 24 15:50:19 2020 -0400

    gdb: add debug_prefixed_vprintf
    
    To help ensure that all debug statements have the same format, introduce
    the debug_prefixed_vprintf helper.  Implement linux_nat_debug_printf_1
    and infrun_debug_printf_1 with it.
    
    I would eventually like to style the module and function name with some
    color, to help them stick out, but I don't really know how to do that
    yet, it can always be done later.
    
    gdb/ChangeLog:
    
            * 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.
    
    Change-Id: Iccc290a2dc6b5fffcbe1c2866ed8d804ad380764

Diff:
---
 gdb/ChangeLog   |  7 +++++++
 gdb/debug.c     | 13 +++++++++++++
 gdb/debug.h     | 32 ++++++++++++++++++++++++++++++++
 gdb/infrun.c    |  7 ++-----
 gdb/linux-nat.c |  7 ++-----
 5 files changed, 56 insertions(+), 10 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b95045b039d..ec69531e6b5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+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.
diff --git a/gdb/debug.c b/gdb/debug.c
index 548b29194f8..f845a7e3b1e 100644
--- a/gdb/debug.c
+++ b/gdb/debug.c
@@ -19,6 +19,8 @@
 
 #include "defs.h"
 
+#include "debug.h"
+
 /* See gdbsupport/common-debug.h.  */
 
 void
@@ -26,3 +28,14 @@ debug_vprintf (const char *fmt, va_list ap)
 {
   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");
+}
diff --git a/gdb/debug.h b/gdb/debug.h
new file mode 100644
index 00000000000..1d98fbebec6
--- /dev/null
+++ b/gdb/debug.h
@@ -0,0 +1,32 @@
+/* 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 */
+
+
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 0f2a1bcd4a6..938bc081a1c 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -70,6 +70,7 @@
 #include "gdbsupport/selftest.h"
 #include "scoped-mock-context.h"
 #include "test-target.h"
+#include "debug.h"
 
 /* Prototypes for local functions */
 
@@ -106,14 +107,10 @@ static int infrun_is_async = -1;
 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.  */
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 7a4387ff845..b81014024c7 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -68,6 +68,7 @@
 #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.
 
@@ -203,14 +204,10 @@ show_debug_linux_nat (struct ui_file *file, int from_tty,
 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, ...) \


More information about the Gdb-cvs mailing list