debug分模块、分级别打印控制代码,调试使用

 

#include

#define PRINT_LEVEL   3
#define debug(level, format, args...)  /
if(level>>8 && (level&0xFF) > PRINT_LEVEL){  /
 printf("%s[%d]:  ", __FILE__, __LINE__);  /
 printf(format, ##args);  /
}

 
#define TRACE_ENTRY()  /
do{  /
 printf("Enter Function %s().../n", __FUNCTION__);  /
}while(0)

#define TRACE_EXIT()  /
do{  /
 printf("Exit Function %s().../n", __FUNCTION__);  /
}while(0)


#define module1  1
#define module2  0

#define level1  1
#define level2  2
#define level3  3
#define level4  4
#define level5  5
#define level6  6

#define moduel1_level1  (module1<<8 | level1)
#define moduel1_level2  (module1<<8 | level2)
#define moduel1_level3  (module1<<8 | level3)
#define moduel1_level4  (module1<<8 | level4)
#define moduel1_level5  (module1<<8 | level5)
#define moduel1_level6  (module1<<8 | level6)

#define moduel2_level1  (module2<<8 | level1)
#define moduel2_level2  (module2<<8 | level2)
#define moduel2_level3  (module2<<8 | level3)
#define moduel2_level4  (module2<<8 | level4)
#define moduel2_level5  (module2<<8 | level5)
#define moduel2_level6  (module2<<8 | level6)

 

int main()
{
 TRACE_ENTRY();

 debug(moduel1_level1, "%s/n", "moduel1_level1");
 debug(moduel1_level2, "%s/n", "moduel1_level2");
 debug(moduel1_level3, "%s/n", "moduel1_level3");
 debug(moduel1_level4, "%s/n", "moduel1_level4");
 debug(moduel1_level5, "%s/n", "moduel1_level5");
 debug(moduel1_level6, "%s/n", "moduel1_level6");
 
 
 debug(moduel2_level1, "%s/n", "moduel2_level1");
 debug(moduel2_level2, "%s/n", "moduel2_level2");
 debug(moduel2_level3, "%s/n", "moduel2_level3");
 debug(moduel2_level4, "%s/n", "moduel2_level4");
 debug(moduel2_level5, "%s/n", "moduel2_level5");
 debug(moduel2_level6, "%s/n", "moduel2_level6");

 TRACE_EXIT();

 return 0;
}

 

 

 

#define signed     char        s8

#define unsigned char        u8

 

#define signed     short       s16

#define unsigned short       u16

 

#define signed     int           s32

#define unsigned int           u32

 

#define signed     long long       s64

#define unsigned long long       u64

 

你可能感兴趣的:(linux编程技术)