zoukankan      html  css  js  c++  java
  • 打印调试

      针对常用的调试手段之一——打印调试,设计此打印调试模块,可实现精确定位,Release版很容易去除。

     1 /**
     2   file     utilDebug.h
     3   rief    调试工具
     4   details  代码中嵌入该测试模块,可针对打印调试实现精确定位
     5  */
     6 #ifndef _UTIL_DEBUG_2013_01_08_H_
     7 #define _UTIL_DEBUG_2013_01_08_H_
     8 
     9 #if defined(__cplusplus)
    10 extern "C" 
    11 {
    12 #endif
    13 
    14 #ifndef UTIL_DEBUG
    15 #define UTIL_DEBUG          /**< release版请注释该行并重新编译所有相关工程*/
    16 #endif
    17 
    18 #ifdef UTIL_DEBUG
    19 /**<  打印调试*/
    20 #include <stdio.h>
    21 
    22 /**
    23   rief    打印的调试版本
    24  */
    25 #define DEBUG_PRINT(str, ...) do {
    26     printf(str, ##__VA_ARGS__);
    27 } while (0);
    28 
    29 /**
    30   rief    默认错误打印
    31   details  仅打印错误所在文件名、函数名及代码行
    32  */
    33 #define DEBUG_ERROR_DEFAULT() do {
    34     printf("file: %s, fun: %s, line: %d
    ", __FILE__, __FUNCTION__, __LINE__);
    35 }while (0)
    36 
    37 /**
    38   rief    错误码打印
    39   details  在默认错误打印的基础上增加错误码的打印
    40 
    41   param[in]  code  错误码(整形)
    42  */
    43 #define DEBUG_ERROR_CODE(code) do {
    44     printf("file: %s, fun: %s, line: %d, code: 0x%x.
    ", __FILE__,  __FUNCTION__, __LINE__, code);
    45 }while (0)
    46 
    47 /**
    48   rief    错误原因打印
    49   details  在默认错误打印的基础上增加错误原因的打印
    50 
    51   param[in]  str   错误原因(字符串)
    52  */
    53 #define DEBUG_ERROR_REASON(str) do {
    54     printf("file: %s, fun: %s, line: %d, reason: %s.
    ", __FILE__,  __FUNCTION__, __LINE__, str);
    55 }while (0)
    56 
    57 /**
    58   rief    错误码及错误原因打印
    59   details  在默认错误打印的基础上增加错误码和错误原因的打印
    60 
    61   param[in]  code  错误码(整形)
    62   param[in]  str   错误原因(字符串)
    63   */
    64 #define DEBUG_ERROR_CR(code, str) do {
    65     printf("file: %s, fun: %s, line: %d, code: 0x%x, reason: %s.
    ", __FILE__,  __FUNCTION__, __LINE__, code, str);
    66 }while (0)
    67 
    68 
    69 /*  断言调试  */
    70 #include <assert.h>
    71 /**
    72   rief    断言的调试版本
    73  */
    74 #define DEBUG_ASSERT(exp) do {
    75     assert(exp);
    76 } while (0)
    77 
    78 #else
    79 
    80 #define DEBUG_PRINT(str, ...)
    81 
    82 #define DEBUG_ERROR_DEFAULT()
    83 
    84 #define DEBUG_ERROR_CODE(code)
    85 
    86 #define DEBUG_ERROR_REASON(str)
    87 
    88 #define DEBUG_ERROR_CR(code, str)
    89 
    90 #define DEBUG_ASSERT(exp)
    91 
    92 #endif
    93 
    94 #if defined(__cplusplus)
    95 }
    96 #endif
    97 #endif/**< _UTIL_DEBUG_2013_01_08_H_*/
  • 相关阅读:
    前端模块的前生今世
    variable fonts
    node
    webpack tree shaking
    es6 proxy浅析
    如何实现优美的骨架屏
    阿里巴巴Java开发手册建议创建HashMap时设置初始化容量,但是多少合适呢?
    新来个技术总监,禁止我们使用Lombok!
    2020年Java程序员应该学习的10大技术
    为啥HashMap的默认容量是16?
  • 原文地址:https://www.cnblogs.com/hackvilin/p/3256592.html
Copyright © 2011-2022 走看看