public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] debug_print macros support
@ 2009-04-03 11:49 Prafulla Wadaskar
  2009-04-03 11:49 ` [U-Boot] [PATCH] bin_dep.sh Support Prafulla Wadaskar
  2009-04-03 17:53 ` [U-Boot] [PATCH] debug_print macros support Wolfgang Denk
  0 siblings, 2 replies; 35+ messages in thread
From: Prafulla Wadaskar @ 2009-04-03 11:49 UTC (permalink / raw)
  To: u-boot

From: prafulla_wadaskar <prafulla@marvell.com>

This debug_prints strategy provides-
A. pre-formatted debug and print macros to be used in a code
B. flexiblility to enable selective debug prints without
   modifying a source code
For more details refer doc/README.debug_prints

Signed-off-by: prafulla_wadaskar <prafulla@marvell.com>
---
 config.mk               |    6 +++
 doc/README.debug_prints |   89 +++++++++++++++++++++++++++++++++++++++++++++++
 include/debug_prints.h  |   83 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 178 insertions(+), 0 deletions(-)
 create mode 100644 doc/README.debug_prints
 create mode 100644 include/debug_prints.h

diff --git a/config.mk b/config.mk
index b1254e9..6e85cb5 100644
--- a/config.mk
+++ b/config.mk
@@ -198,6 +198,12 @@ ifeq ($(PCI_CLOCK),PCI_66M)
 CFLAGS := $(CFLAGS) -DPCI_66M
 endif
 
+CFLAGS := $(CFLAGS) $(shell for dbgprn in $(DEBUG_PRINTS); do \
+			if [ "$$dbgprn" != "" ]; then \
+				echo "-D$$dbgprn "; \
+			fi ;	\
+		done)
+
 #########################################################################
 
 export	HPATH HOSTCC HOSTCFLAGS CROSS_COMPILE \
diff --git a/doc/README.debug_prints b/doc/README.debug_prints
new file mode 100644
index 0000000..f03cb4c
--- /dev/null
+++ b/doc/README.debug_prints
@@ -0,0 +1,89 @@
+#
+# (C) Copyright 2009
+# Marvell Semiconductor <www.marvell.com>
+# Prafulla Wadaskar <prafulla@marvell.com>
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# 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 2 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, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301 USA
+#
+
+1.1 Debugging Strategy
+======================
+This debug strategy provides predefined macros to be used in code
+
+DEBUGGING LEVELS
+0 To disable all debug messages
+1 To enable normal debug macro- debug_print
+2 To enable flow trace debug macro- debug_print_ftrace
+4 To enable interrupt and timer debug macroc- debug_print4
+8 To enable any special debug messages defined by macro- debug_print8
+
+1.2 How to use Debugging strategy in a code ?
+=============================================
+
+1. make sure #include <debug_prints.h> line present in c code
+2. define following lines at the top in your code
+	#ifndef <DBG_FLAG_NAME>
+	#define <DBG_FLAG_NAME>	0
+	#endif
+	#define DEBUG_PRINT	<DBG_FLAG_NAME>
+   DBG_FLAG_NAME is an identification that is used during build to enable
+   debug prints
+3. define DEBUG_PFX to a small string to identify debug message in a code
+	This is an optional setting, if you don't define DEBUG_PFX,
+	by default "dbg: " will be used.
+4. use the debug_print, debug_ftrace, debug_print4, debug_print8 macros
+   in a code wjere ever required
+
+1.3 How to activate debug messages?
+====================================
+
+Debug messages can be activated during build time by passing desired
+debug level
+
+1. Enabling Debug messages by passing additional parameter to make
+	This is a recommended method of debug messages implimentation.
+	this method give flexibility to enable/disable debug messages
+	during build without modifying code
+	Additional command line parameters:-
+	(a) To enable debug_print messages:-
+		DEBUG_PRINTS=<DBG_FLAG_NAME>
+	(b) To enable debug_print_ftrace function:-
+		DEBUG_PRINTS=<DBG_FLAG_NAME>=2
+	(c) To enable debug_print4 messages:-
+		DEBUG_PRINTS=<DBG_FLAG_NAME>=4
+	(d) To enable debug_print8 messages:-
+		DEBUG_PRINTS=<DBG_FLAG_NAME>=8
+	(e) you can enable selective debug prints.
+	    for ex. if you want to enable debug_print and debug_print4 messages
+	    then you can pass ORed debug level value (i.e. 1 for debug_print and
+	    4 for debug_print4 (1 | 4 = 5)
+		DEBUG_PRINTS=<DBG_FLAG_NAME>=5
+	(f) if you want to enable debug_print defined in more than one c files
+	then you can pass additional debug flag names as
+		DEBUG_PRINTS="<DBG_FLAG_NAME1>=1 <DBG_FLAG_NAME2>=2
+	the above parameters will enable debug_print messages in a code where
+	<DBG_FLAG_NAME1> is defined and will enable debug_print_ftrace functions
+	in a code where <DBG_FLAG_NAME2> is defined
+
+2. Enabling Debug messages by hardcoding in source file
+	This is simplest implimentation, just define DEBUG_PRINT to
+	desired debug level and compile the code, the disadvantage of this
+	method is, it does not offer flexibility and code with debug message
+	may become part of your release if not taken care properly.
+
diff --git a/include/debug_prints.h b/include/debug_prints.h
new file mode 100644
index 0000000..8a374ff
--- /dev/null
+++ b/include/debug_prints.h
@@ -0,0 +1,83 @@
+/*
+ * (C) Copyright 2009
+ * Marvell Semiconductor <www.marvell.com>
+ * Prafulla Wadaskar <prafulla@marvell.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+
+/*
+ * refer doc/README.debug_prints for more details
+ */
+
+#ifndef __DEBUG_PRINTS_H__
+#define __DEBUG_PRINTS_H__
+
+#ifndef KERN_ERR
+#define KERN_ERR	"Err :"
+#endif
+
+#ifndef KERN_INFO
+#define KERN_INFO	"Info:"
+#endif
+
+#ifndef KERN_WARNING
+#define KERN_WARNING	"Warn:"
+#endif
+
+#ifndef KERN_DBG
+#define KERN_DBG	"dbg :"
+#endif
+
+#ifndef DEBUG_PRINT_PFX
+#define DEBUG_PRINT_PFX	""
+#endif
+
+#ifndef DEBUG_PRINT
+#define DEBUG_PRINT 	0
+#endif
+
+#define error_print(format, arg...)	\
+		printf(KERN_ERR DEBUG_PRINT_PFX format "\n" , ## arg)
+#define info_print(format, arg...) 	\
+		printf(KERN_INFO DEBUG_PRINT_PFX format "\n" , ## arg)
+#define warn_print(format, arg...) 	\
+		printf(KERN_WARNING DEBUG_PRINT_PFX format "\n" , ## arg)
+
+#define debug_print(format, arg...)		\
+		(DEBUG_PRINT & 1) ? 	\
+		 (printf(KERN_DBG DEBUG_PRINT_PFX format "\n" , ## arg))\
+		 : ({do {} while (0);})
+
+#define debug_print_ftrace(format, arg...)	\
+		(DEBUG_PRINT & 2) ?	\
+		 (printf(KERN_DBG DEBUG_PRINT_PFX "%s() called\n",	\
+		 ( __FUNCTION__ ))) : ({do {} while (0);})
+
+#define debug_print4(format, arg...)		\
+		(DEBUG_PRINT & 4) ?	\
+		 (printf(KERN_DBG DEBUG_PRINT_PFX format "\n" , ## arg))\
+		 : ({do {} while (0);})
+
+#define debug_print8(format, arg...)		\
+		(DEBUG_PRINT & 8) ?		\
+		 (printf(KERN_DBG DEBUG_PRINT_PFX format "\n" , ## arg))\
+		 : ({do {} while (0);})
+
+#endif /* __DEBUG_PRINTS_H__ */
-- 
1.5.3.3

^ permalink raw reply related	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2009-05-26  9:08 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-03 11:49 [U-Boot] [PATCH] debug_print macros support Prafulla Wadaskar
2009-04-03 11:49 ` [U-Boot] [PATCH] bin_dep.sh Support Prafulla Wadaskar
2009-04-03 11:49   ` [U-Boot] [PATCH] Macronix MX25xx MTD SPI flash driver Prafulla Wadaskar
2009-04-03 14:14     ` Mike Frysinger
2009-04-06  7:23       ` Prafulla Wadaskar
2009-04-06  7:39         ` Mike Frysinger
2009-04-06  8:27           ` Prafulla Wadaskar
2009-04-06  8:49             ` Mike Frysinger
2009-04-03 17:54   ` [U-Boot] [PATCH] bin_dep.sh Support Wolfgang Denk
2009-04-06  7:34     ` Prafulla Wadaskar
2009-04-06  8:05       ` Wolfgang Denk
2009-04-06  8:13         ` Ronen Shitrit
2009-04-06  8:24           ` Wolfgang Denk
2009-04-06  8:36             ` Ronen Shitrit
2009-04-06  9:11               ` Wolfgang Denk
2009-04-06  9:03             ` Mike Frysinger
2009-04-06  9:16               ` Wolfgang Denk
2009-04-06  9:33                 ` Mike Frysinger
2009-04-06 10:28                   ` Wolfgang Denk
2009-04-06 10:49                     ` Mike Frysinger
2009-04-06  9:38                 ` Prafulla Wadaskar
2009-04-06 10:16                   ` Mike Frysinger
2009-04-06 11:00                   ` Wolfgang Denk
2009-05-26  9:08                   ` Stefan Roese
2009-04-06 19:30             ` Scott Wood
2009-04-06 19:49               ` Wolfgang Denk
2009-04-06 23:01                 ` Mike Frysinger
2009-04-06  9:39     ` Detlev Zundel
2009-04-06  9:43       ` Prafulla Wadaskar
2009-04-03 17:53 ` [U-Boot] [PATCH] debug_print macros support Wolfgang Denk
2009-04-06  5:32   ` Prafulla Wadaskar
2009-04-06  6:31     ` Mike Frysinger
2009-04-06  6:43       ` Prafulla Wadaskar
2009-04-06  7:56     ` Wolfgang Denk
2009-04-06  8:05       ` Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox