From ff7334a2ce536b7f4b1f6d6f93ff4e285a3bd45a Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 19 Jul 2012 08:42:32 -0700 Subject: [PATCH] Only compile dprintf/vdprintf if DEBUG_PORT is defined We really, really don't want to accidentally spew output to a debug port in production, so make it obligatory to define DEBUG_PORT or DEBUG_STDIO in order for the debugging code to be compiled in. Since DEBUG_STDIO just turns the debugging code into stdio references, we only need to compile the code for the DEBUG_PORT case. Add a commented-out line to mk/devel.mk to make it easier for users. Signed-off-by: H. Peter Anvin Cc: Matt Fleming --- com32/include/dprintf.h | 4 ++++ com32/lib/dprintf.c | 4 ++++ com32/lib/vdprintf.c | 8 ++++---- mk/devel.mk | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/com32/include/dprintf.h b/com32/include/dprintf.h index b8a3b84c..26ca734b 100644 --- a/com32/include/dprintf.h +++ b/com32/include/dprintf.h @@ -5,6 +5,10 @@ #ifndef _DPRINTF_H #define _DPRINTF_H +#if !defined(DEBUG_PORT) && !defined(DEBUG_STDIO) +# undef DEBUG +#endif + #ifdef DEBUG # include diff --git a/com32/lib/dprintf.c b/com32/lib/dprintf.c index d22dae95..dea77b39 100644 --- a/com32/lib/dprintf.c +++ b/com32/lib/dprintf.c @@ -5,6 +5,8 @@ #include #include +#ifdef DEBUG_PORT + void vdprintf(const char *, va_list); void dprintf(const char *format, ...) @@ -15,3 +17,5 @@ void dprintf(const char *format, ...) vdprintf(format, ap); va_end(ap); } + +#endif /* DEBUG_PORT */ diff --git a/com32/lib/vdprintf.c b/com32/lib/vdprintf.c index db602959..bcf55bb7 100644 --- a/com32/lib/vdprintf.c +++ b/com32/lib/vdprintf.c @@ -10,6 +10,8 @@ #include #include +#ifdef DEBUG_PORT + #define BUFFER_SIZE 4096 enum serial_port_regs { @@ -27,10 +29,6 @@ enum serial_port_regs { SCR = 7, }; -#ifndef DEBUG_PORT -# define DEBUG_PORT 0x03f8 /* I/O base address */ -#endif - static const uint16_t debug_base = DEBUG_PORT; static void debug_putc(char c) @@ -109,3 +107,5 @@ void vdprintf(const char *format, va_list ap) while (rv--) debug_putc(*p++); } + +#endif /* DEBUG_PORT */ diff --git a/mk/devel.mk b/mk/devel.mk index c05d76e8..8184c30f 100644 --- a/mk/devel.mk +++ b/mk/devel.mk @@ -1,2 +1,3 @@ # Useful while doing development, but not for production. GCCWARN += -Wno-clobbered +# GCCWARN += -DDEBUG_PORT=0x3f8 -DDEBUG=1 -- 2.11.4.GIT