From: prafulla_wadaskar <prafu...@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 <prafu...@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 <prafu...@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 <prafu...@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 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot