[4/5,v7] Introduce common-debug.h

Message ID 1407923779-22149-5-git-send-email-gbenson@redhat.com
State Committed
Headers

Commit Message

Gary Benson Aug. 13, 2014, 9:56 a.m. UTC
  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/
2014-08-13  Tom Tromey  <tromey@redhat.com>
	    Gary Benson  <gbenson@redhat.com>

	* 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/
2014-08-13  Tom Tromey  <tromey@redhat.com>
	    Gary Benson  <gbenson@redhat.com>

	* 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/ChangeLog             |   15 +++++++++++++++
 gdb/Makefile.in           |   11 ++++++++---
 gdb/common/agent.c        |   24 +++++++++++++++---------
 gdb/common/common-debug.c |   37 +++++++++++++++++++++++++++++++++++++
 gdb/common/common-debug.h |   36 ++++++++++++++++++++++++++++++++++++
 gdb/common/common-defs.h  |    1 +
 gdb/debug.c               |   28 ++++++++++++++++++++++++++++
 gdb/gdbserver/ChangeLog   |   10 ++++++++++
 gdb/gdbserver/Makefile.in |   10 +++++++---
 gdb/gdbserver/debug.c     |   11 ++++-------
 gdb/gdbserver/debug.h     |    1 -
 gdb/nat/i386-dregs.c      |    4 ----
 12 files changed, 161 insertions(+), 27 deletions(-)
 create mode 100644 gdb/common/common-debug.c
 create mode 100644 gdb/common/common-debug.h
 create mode 100644 gdb/debug.c
  

Comments

Doug Evans Aug. 18, 2014, 4:38 p.m. UTC | #1
On Wed, Aug 13, 2014 at 2:56 AM, Gary Benson <gbenson@redhat.com> wrote:
> 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/
> 2014-08-13  Tom Tromey  <tromey@redhat.com>
>             Gary Benson  <gbenson@redhat.com>
>
>         * 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/
> 2014-08-13  Tom Tromey  <tromey@redhat.com>
>             Gary Benson  <gbenson@redhat.com>
>
>         * 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.

LGTM
  
Gary Benson Aug. 19, 2014, 9:12 a.m. UTC | #2
Doug Evans wrote:
> On Wed, Aug 13, 2014 at 2:56 AM, Gary Benson <gbenson@redhat.com> wrote:
> > 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/
> > 2014-08-13  Tom Tromey  <tromey@redhat.com>
> >             Gary Benson  <gbenson@redhat.com>
> >
> >         * 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/
> > 2014-08-13  Tom Tromey  <tromey@redhat.com>
> >             Gary Benson  <gbenson@redhat.com>
> >
> >         * 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.
> 
> LGTM

I've pushed this series up to here.  Thanks for reviewing this Doug.

Cheers,
Gary
  
Steve Ellcey Aug. 19, 2014, 11:22 p.m. UTC | #3
On Tue, 2014-08-19 at 10:12 +0100, Gary Benson wrote:

> > > 2014-08-13  Tom Tromey  <tromey@redhat.com>
> > >             Gary Benson  <gbenson@redhat.com>
> > >
> > >         * 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.

I just built gdb for mips (mips-linux-gnu and mips-mti-linux-gnu) and it
died with:

/local/home/sellcey/gcc/non_mti_linux/src/binutils-gdb/sim/mips/../common/sim-trace.c:1326: multiple definition of `debug_printf'
common-debug.o:/local/home/sellcey/gcc/non_mti_linux/src/binutils-gdb/gdb/common/common-debug.c:31: first defined here
collect2: ld returned 1 exit status
make[1]: *** [gdb] Error 1

I am assuming it has something to do with this patch.

Steve Ellcey
sellcey@mips.com
  
Gary Benson Aug. 20, 2014, 8:52 a.m. UTC | #4
[Cc'ing Mike and Frank (SIM global maintainer and SIM common
maintainer)]

Steve Ellcey wrote:
> On Tue, 2014-08-19 at 10:12 +0100, Gary Benson wrote:
> > > > 2014-08-13  Tom Tromey  <tromey@redhat.com>
> > > >             Gary Benson  <gbenson@redhat.com>
> > > >
> > > >         * 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.
> 
> I just built gdb for mips (mips-linux-gnu and mips-mti-linux-gnu)
> and it died with:
> 
> /local/home/sellcey/gcc/non_mti_linux/src/binutils-gdb/sim/mips/../common/sim-trace.c:1326: multiple definition of `debug_printf'
> common-debug.o:/local/home/sellcey/gcc/non_mti_linux/src/binutils-gdb/gdb/common/common-debug.c:31: first defined here
> collect2: ld returned 1 exit status
> make[1]: *** [gdb] Error 1
> 
> I am assuming it has something to do with this patch.

Yeah.  This patch adds a "debug_printf" function to GDB, but it looks
like SIM already had one.

I don't see any callers for SIM's debug_printf.  Is this dead code
that can be removed, or is it provided as a convenience/library
function?

Steve, you can probably work around this for now by adding:

  #define debug_printf gdb_debug_printf

at the top of GDB's common/common-debug.h.  If SIM's debug_printf
cannot be removed then maybe we will have to add some hack like
this to GDB permanently.

Thanks,
Gary
  
Mike Frysinger Aug. 20, 2014, 9:42 a.m. UTC | #5
On Wed 20 Aug 2014 09:52:43 Gary Benson wrote:
> [Cc'ing Mike and Frank (SIM global maintainer and SIM common
> maintainer)]
> 
> Steve Ellcey wrote:
> > On Tue, 2014-08-19 at 10:12 +0100, Gary Benson wrote:
> > > > > 2014-08-13  Tom Tromey  <tromey@redhat.com>
> > > > > 
> > > > >             Gary Benson  <gbenson@redhat.com>
> > > > >         
> > > > >         * 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.
> > 
> > I just built gdb for mips (mips-linux-gnu and mips-mti-linux-gnu)
> > and it died with:
> > 
> > /local/home/sellcey/gcc/non_mti_linux/src/binutils-gdb/sim/mips/../common/
> > sim-trace.c:1326: multiple definition of `debug_printf'
> > common-debug.o:/local/home/sellcey/gcc/non_mti_linux/src/binutils-gdb/gdb
> > /common/common-debug.c:31: first defined here collect2: ld returned 1 exit
> > status
> > make[1]: *** [gdb] Error 1
> > 
> > I am assuming it has something to do with this patch.
> 
> Yeah.  This patch adds a "debug_printf" function to GDB, but it looks
> like SIM already had one.
> 
> I don't see any callers for SIM's debug_printf.  Is this dead code
> that can be removed, or is it provided as a convenience/library
> function?

it is not currently being used, but it really really should be in some targets

> Steve, you can probably work around this for now by adding:
> 
>   #define debug_printf gdb_debug_printf
> 
> at the top of GDB's common/common-debug.h.  If SIM's debug_printf
> cannot be removed then maybe we will have to add some hack like
> this to GDB permanently.

i'm fine with updating sim/common/sim-trace.h with that idea:
#define debug_printf sim_debug_printf

all the symbols coming out of the sim really should be namespaced
-mike
  
Gary Benson Aug. 20, 2014, 12:09 p.m. UTC | #6
Mike Frysinger wrote:
> On Wed 20 Aug 2014 09:52:43 Gary Benson wrote:
> > I don't see any callers for SIM's debug_printf.  Is this dead code
> > that can be removed, or is it provided as a convenience/library
> > function?
> 
> it is not currently being used, but it really really should be in
> some targets

Ok.

> > Steve, you can probably work around this for now by adding:
> > 
> >   #define debug_printf gdb_debug_printf
> > 
> > at the top of GDB's common/common-debug.h.  If SIM's debug_printf
> > cannot be removed then maybe we will have to add some hack like
> > this to GDB permanently.
> 
> i'm fine with updating sim/common/sim-trace.h with that idea:
> #define debug_printf sim_debug_printf
> 
> all the symbols coming out of the sim really should be namespaced

Great.  I can put together a patch if you like (or I can make the
change, or you can... whatever's easiest!)  I don't know much about
SIM... is there a list to mail patches to?  And, is its upstream
repo the same as binutils+GDB or is it imported from somewhere else
like libiberty?

Cheers,
Gary
  
Frank Ch. Eigler Aug. 20, 2014, 1:31 p.m. UTC | #7
Hi -


> > [...]
> > i'm fine with updating sim/common/sim-trace.h with that idea:
> > #define debug_printf sim_debug_printf
> > all the symbols coming out of the sim really should be namespaced

IMHO, names this generic should be avoided in *both* application (gdb)
and library (sim), lest another future library come & interfere later.


> Great.  I can put together a patch if you like (or I can make the
> change, or you can... whatever's easiest!)  I don't know much about
> SIM... is there a list to mail patches to?  And, is its upstream
> repo the same as binutils+GDB or is it imported from somewhere else
> like libiberty?

sim is part of the binutils-gdb.git repo, patches here fine.  The main
problem with testing the sim for changes like this is its inability to
easily build all targets, and its aggressive use of macros, which
makes it hard to know you've actually covered all the cases for a
symbol-rename.

- FChE
  
Mike Frysinger Aug. 20, 2014, 3:32 p.m. UTC | #8
On Wed 20 Aug 2014 13:09:34 Gary Benson wrote:
> Mike Frysinger wrote:
> > On Wed 20 Aug 2014 09:52:43 Gary Benson wrote:
> > > Steve, you can probably work around this for now by adding:
> > >   #define debug_printf gdb_debug_printf
> > > 
> > > at the top of GDB's common/common-debug.h.  If SIM's debug_printf
> > > cannot be removed then maybe we will have to add some hack like
> > > this to GDB permanently.
> > 
> > i'm fine with updating sim/common/sim-trace.h with that idea:
> > #define debug_printf sim_debug_printf
> > 
> > all the symbols coming out of the sim really should be namespaced
> 
> Great.  I can put together a patch if you like (or I can make the
> change, or you can... whatever's easiest!)  I don't know much about
> SIM... is there a list to mail patches to?  And, is its upstream
> repo the same as binutils+GDB or is it imported from somewhere else
> like libiberty?

it would be great if you could put together the patch :).  sim patches go to 
the same place as gdb (same repo), and i can approve them when i see them.
-mike
  
Gary Benson Aug. 20, 2014, 7:16 p.m. UTC | #9
Frank Ch. Eigler wrote:
> > > [...]
> > > i'm fine with updating sim/common/sim-trace.h with that idea:
> > > #define debug_printf sim_debug_printf
> > > all the symbols coming out of the sim really should be namespaced
> 
> IMHO, names this generic should be avoided in *both* application (gdb)
> and library (sim), lest another future library come & interfere later.

Yeah, I should know this by now :/

> > Great.  I can put together a patch if you like (or I can make the
> > change, or you can... whatever's easiest!)  I don't know much about
> > SIM... is there a list to mail patches to?  And, is its upstream
> > repo the same as binutils+GDB or is it imported from somewhere else
> > like libiberty?
> 
> sim is part of the binutils-gdb.git repo, patches here fine.  The
> main problem with testing the sim for changes like this is its
> inability to easily build all targets, and its aggressive use of
> macros, which makes it hard to know you've actually covered all the
> cases for a symbol-rename.

Yuck :(

Frank, if you're not ok with the patch I just mailed then let me know
and I'll figure something out when I get back from PTO.

Thanks,
Gary
  
Frank Ch. Eigler Aug. 20, 2014, 9:40 p.m. UTC | #10
Hi -

On Wed, Aug 20, 2014 at 08:16:19PM +0100, Gary Benson wrote:
> [...]
> Frank, if you're not ok with the patch I just mailed then let me know
> and I'll figure something out when I get back from PTO.

(I have no objection to the #define in gdb/*.)

- FChE
  
Gary Benson Aug. 20, 2014, 9:58 p.m. UTC | #11
Frank Ch. Eigler wrote:
> On Wed, Aug 20, 2014 at 08:16:19PM +0100, Gary Benson wrote:
> > [...]
> > Frank, if you're not ok with the patch I just mailed then let me know
> > and I'll figure something out when I get back from PTO.
> 
> (I have no objection to the #define in gdb/*.)

I take this to mean you do object to a #define in sim/*.
Ok, I'll submit a GDB patch when I get back.

Thanks,
Gary

--
http://gbenson.net/
  
Doug Evans Aug. 20, 2014, 9:58 p.m. UTC | #12
On Wed, Aug 20, 2014 at 2:40 PM, Frank Ch. Eigler <fche@redhat.com> wrote:
> Hi -
>
> On Wed, Aug 20, 2014 at 08:16:19PM +0100, Gary Benson wrote:
>> [...]
>> Frank, if you're not ok with the patch I just mailed then let me know
>> and I'll figure something out when I get back from PTO.
>
> (I have no objection to the #define in gdb/*.)

Of course you don't. :-)
[that smiley is a sincere smiley, not a sarcastic one!]
[and I'm assuming that's not a typo, and you didn't mean to say sim/*]

How much effort is involved in renaming sim's debug_printf?
  
Frank Ch. Eigler Aug. 20, 2014, 10:47 p.m. UTC | #13
Hi -

> > (I have no objection to the #define in gdb/*.)
> I take this to mean you do object to a #define in sim/*.

No - just that a gdb/* patch the only one I think I saw.  Making an
analogue for sim/* would be fine, but testing it for wide buildability
will be a hassle.

- FChE
  
Mike Frysinger Aug. 21, 2014, 1:19 a.m. UTC | #14
On Wed 20 Aug 2014 18:47:41 Frank Ch. Eigler wrote:
> > > (I have no objection to the #define in gdb/*.)
> > 
> > I take this to mean you do object to a #define in sim/*.
> 
> No - just that a gdb/* patch the only one I think I saw.  Making an
> analogue for sim/* would be fine, but testing it for wide buildability
> will be a hassle.

i wouldn't worry too much about that ... i have local builds for most every 
target, and i think some others notice when things break too
-mike
  

Patch

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 76ca0da..b33defe 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -851,7 +851,7 @@  SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
 	common/ptid.c common/buffer.c gdb-dlfcn.c common/agent.c \
 	common/format.c common/filestuff.c btrace.c record-btrace.c ctf.c \
 	target/waitstatus.c common/print-utils.c common/rsp-low.c \
-	common/errors.c
+	common/errors.c common/common-debug.c
 
 LINTFILES = $(SFILES) $(YYFILES) $(CONFIG_SRCS) init.c
 
@@ -936,7 +936,8 @@  gdb_bfd.h sparc-ravenscar-thread.h ppc-ravenscar-thread.h nat/linux-btrace.h \
 ctf.h nat/i386-cpuid.h nat/i386-gcc-cpuid.h target/resume.h \
 target/wait.h target/waitstatus.h nat/linux-nat.h nat/linux-waitpid.h \
 common/print-utils.h common/rsp-low.h nat/i386-dregs.h x86-linux-nat.h \
-i386-linux-nat.h common/common-defs.h common/errors.h common/common-types.h
+i386-linux-nat.h common/common-defs.h common/errors.h common/common-types.h \
+common/common-debug.h
 
 # Header files that already have srcdir in them, or which are in objdir.
 
@@ -1035,7 +1036,7 @@  COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	gdb_vecs.o jit.o progspace.o skip.o probe.o \
 	common-utils.o buffer.o ptid.o gdb-dlfcn.o common-agent.o \
 	format.o registry.o btrace.o record-btrace.o waitstatus.o \
-	print-utils.o rsp-low.o errors.o
+	print-utils.o rsp-low.o errors.o common-debug.o debug.o
 
 TSOBS = inflow.o
 
@@ -2149,6 +2150,10 @@  errors.o: ${srcdir}/common/errors.c
 	$(COMPILE) $(srcdir)/common/errors.c
 	$(POSTCOMPILE)
 
+common-debug.o: ${srcdir}/common/common-debug.c
+	$(COMPILE) $(srcdir)/common/common-debug.c
+	$(POSTCOMPILE)
+
 #
 # gdb/target/ dependencies
 #
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 <http://www.gnu.org/licenses/>.  */
+
+#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 <http://www.gnu.org/licenses/>.  */
+
+#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 */
diff --git a/gdb/debug.c b/gdb/debug.c
new file mode 100644
index 0000000..95cf617
--- /dev/null
+++ b/gdb/debug.c
@@ -0,0 +1,28 @@ 
+/* 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 <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+
+/* See common/common-debug.h.  */
+
+void
+debug_vprintf (const char *fmt, va_list ap)
+{
+  vfprintf_unfiltered (gdb_stdlog, fmt, ap);
+}
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 1faa00c..18486c6 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -169,7 +169,8 @@  SFILES=	$(srcdir)/gdbreplay.c $(srcdir)/inferiors.c $(srcdir)/dll.c \
 	$(srcdir)/common/buffer.c $(srcdir)/nat/linux-btrace.c \
 	$(srcdir)/common/filestuff.c $(srcdir)/target/waitstatus.c \
 	$(srcdir)/nat/mips-linux-watch.c $(srcdir)/common/print-utils.c \
-	$(srcdir)/common/rsp-low.c $(srcdir)/common/errors.c
+	$(srcdir)/common/rsp-low.c $(srcdir)/common/errors.c \
+	$(srcdir)/common/common-debug.c
 
 DEPFILES = @GDBSERVER_DEPFILES@
 
@@ -182,8 +183,8 @@  OBS = agent.o ax.o inferiors.o regcache.o remote-utils.o server.o signals.o \
       target.o waitstatus.o utils.o debug.o version.o vec.o gdb_vecs.o \
       mem-break.o hostio.o event-loop.o tracepoint.o xml-utils.o \
       common-utils.o ptid.o buffer.o format.o filestuff.o dll.o notif.o \
-      tdesc.o print-utils.o rsp-low.o errors.o $(XML_BUILTIN) $(DEPFILES) \
-      $(LIBOBJS)
+      tdesc.o print-utils.o rsp-low.o errors.o common-debug.o \
+      $(XML_BUILTIN) $(DEPFILES) $(LIBOBJS)
 GDBREPLAY_OBS = gdbreplay.o version.o
 GDBSERVER_LIBS = @GDBSERVER_LIBS@
 XM_CLIBS = @LIBS@
@@ -540,6 +541,9 @@  agent.o: ../common/agent.c
 errors.o: ../common/errors.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
+common-debug.o: ../common/common-debug.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 waitstatus.o: ../target/waitstatus.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
diff --git a/gdb/gdbserver/debug.c b/gdb/gdbserver/debug.c
index c50af76..339e33c 100644
--- a/gdb/gdbserver/debug.c
+++ b/gdb/gdbserver/debug.c
@@ -33,9 +33,8 @@  int debug_timestamp;
    previous call ended with "\n".  */
 
 void
-debug_printf (const char *msg, ...)
+debug_vprintf (const char *format, va_list ap)
 {
-  va_list args;
 #if !defined (IN_PROCESS_AGENT)
   /* N.B. Not thread safe, and can't be used, as is, with IPA.  */
   static int new_line = 1;
@@ -53,13 +52,11 @@  debug_printf (const char *msg, ...)
     }
 #endif
 
-  va_start (args, msg);
-  vfprintf (stderr, msg, args);
-  va_end (args);
+  vfprintf (stderr, format, ap);
 
 #if !defined (IN_PROCESS_AGENT)
-  if (*msg)
-    new_line = msg[strlen (msg) - 1] == '\n';
+  if (*format)
+    new_line = format[strlen (format) - 1] == '\n';
 #endif
 }
 
diff --git a/gdb/gdbserver/debug.h b/gdb/gdbserver/debug.h
index 0f056ca..42a3f21 100644
--- a/gdb/gdbserver/debug.h
+++ b/gdb/gdbserver/debug.h
@@ -29,7 +29,6 @@ 
 extern int debug_threads;
 extern int debug_timestamp;
 
-void debug_printf (const char *msg, ...) ATTRIBUTE_PRINTF (1, 2);
 void debug_flush (void);
 void do_debug_enter (const char *function_name);
 void do_debug_exit (const char *function_name);
diff --git a/gdb/nat/i386-dregs.c b/gdb/nat/i386-dregs.c
index 1fa5c19..e3272cd 100644
--- a/gdb/nat/i386-dregs.c
+++ b/gdb/nat/i386-dregs.c
@@ -178,10 +178,6 @@  typedef enum { WP_INSERT, WP_REMOVE, WP_COUNT } i386_wp_op_t;
 #ifndef GDBSERVER
 /* Whether or not to print the mirrored debug registers.  */
 extern int debug_hw_points;
-
-/* Print debugging messages.  */
-#define debug_printf(fmt, args...) \
-  fprintf_unfiltered (gdb_stdlog, fmt, ##args);
 #endif
 
 /* Print the values of the mirrored debug registers.  */