From 34abf635b3edf9d70b24aa655ffd7d4696d48cde Mon Sep 17 00:00:00 2001 From: Gary Benson Date: Wed, 30 Jul 2014 16:21:55 +0100 Subject: Introduce common-debug.h This introduces common-debug.h. This holds the functions debug_printf and debug_vprintf, two functions that the common code can use to print debugging messages. Clients of the common code are expected to implement debug_vprintf; a debug_vprintf function is written from scratch for GDB, and gdbserver's existing debug_printf is repurposed as debug_vprintf. common/agent.c is changed to use debug_vprintf rather than defining the macro DEBUG_AGENT depending on GDBSERVER. nat/i386-dregs.c is changed to use the externally-implemented debug_printf, rather than defining it itself. gdb/ChangeLog: * common/common-debug.h: New file. * common/common-debug.c: Likewise. * debug.c: Likewise. * Makefile.in (SFILES): Add common/common-debug.c. (HFILES_NO_SRCDIR): Add common/common-debug.h. (COMMON_OBS): Add common-debug.o and debug.o. (common-debug.o): New rule. * common/common-defs.h: Include common-debug.h. * common/agent.c (debug_agent_printf): New function. (DEBUG_AGENT): Redefine. * nat/i386-dregs.c (debug_printf): Undefine. gdb/gdbserver/ChangeLog: * Makefile.in (SFILES): Add common/common-debug.c. (OBS): Add common-debug.o. (common-debug.o): New rule. * debug.h (debug_printf): Don't declare. * debug.c (debug_printf): Renamed and rewritten as... (debug_vprintf): New function. --- gdb/common/agent.c | 24 +++++++++++++++--------- gdb/common/common-debug.c | 37 +++++++++++++++++++++++++++++++++++++ gdb/common/common-debug.h | 36 ++++++++++++++++++++++++++++++++++++ gdb/common/common-defs.h | 1 + 4 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 gdb/common/common-debug.c create mode 100644 gdb/common/common-debug.h (limited to 'gdb/common') diff --git a/gdb/common/agent.c b/gdb/common/agent.c index 3f868ba..2963917 100644 --- a/gdb/common/agent.c +++ b/gdb/common/agent.c @@ -31,15 +31,21 @@ int debug_agent = 0; -#ifdef GDBSERVER -#define DEBUG_AGENT(fmt, args...) \ - if (debug_agent) \ - fprintf (stderr, fmt, ##args); -#else -#define DEBUG_AGENT(fmt, args...) \ - if (debug_agent) \ - fprintf_unfiltered (gdb_stdlog, fmt, ##args); -#endif +/* A stdarg wrapper for debug_vprintf. */ + +static void ATTRIBUTE_PRINTF (1, 2) +debug_agent_printf (const char *fmt, ...) +{ + va_list ap; + + if (!debug_agent) + return; + va_start (ap, fmt); + debug_vprintf (fmt, ap); + va_end (ap); +} + +#define DEBUG_AGENT debug_agent_printf /* Global flag to determine using agent or not. */ int use_agent = 0; diff --git a/gdb/common/common-debug.c b/gdb/common/common-debug.c new file mode 100644 index 0000000..660fc70 --- /dev/null +++ b/gdb/common/common-debug.c @@ -0,0 +1,37 @@ +/* Debug printing functions. + + Copyright (C) 2014 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 . */ + +#ifdef GDBSERVER +#include "server.h" +#else +#include "defs.h" +#endif +#include "common-debug.h" + +/* See common/common-debug.h. */ + +void +debug_printf (const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + debug_vprintf (fmt, ap); + va_end (ap); +} diff --git a/gdb/common/common-debug.h b/gdb/common/common-debug.h new file mode 100644 index 0000000..c2bb192 --- /dev/null +++ b/gdb/common/common-debug.h @@ -0,0 +1,36 @@ +/* Declarations for debug printing functions. + + Copyright (C) 2014 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 . */ + +#ifndef COMMON_DEBUG_H +#define COMMON_DEBUG_H + +/* Print a formatted message to the appropriate channel for + debugging output for the client. */ + +extern void debug_printf (const char *format, ...) + ATTRIBUTE_PRINTF (1, 2); + +/* Print a formatted message to the appropriate channel for + debugging output for the client. This function must be + provided by the client. */ + +extern void debug_vprintf (const char *format, va_list ap) + ATTRIBUTE_PRINTF (1, 0); + +#endif /* COMMON_DEBUG_H */ diff --git a/gdb/common/common-defs.h b/gdb/common/common-defs.h index 66c0d21..2d3444b 100644 --- a/gdb/common/common-defs.h +++ b/gdb/common/common-defs.h @@ -44,5 +44,6 @@ #include "errors.h" #include "common-types.h" #include "print-utils.h" +#include "common-debug.h" #endif /* COMMON_DEFS_H */ -- cgit v1.1