您的位置:首页 > 编程语言 > C语言/C++

C语言建造自己的调试信息系统

2017-01-04 15:50 621 查看
直接看代码

1: soc_cm_debug(DK_ERR, ("Port %s: soc_link_fwd_set failed: %s\n SOC_PORT_NAME(unit, port), bcm_errmsg(rv)));

 

DK_ERR: 可以这样设置, 全局静态变量 my_debug可以设置标志位,不同级别的调试信息。如下:

#define DK_ERROR 0x00000001

#define DK_WARN 0x00000002

 

#define soc_cm_debug(x,y) \

      If(my_debug & x)   printf y

如果条件成立,才进行打印

 

#define bcm_errmsg(rv)          \

_SHR_ERRMSG(rv)

#define _SHR_ERRMSG(r)          \

        _shr_errmsg[(((int)r) <= 0 && ((int)r) > _SHR_E_LIMIT) ? -(r) : -_SHR_E_LIMIT]

错误信息数组

/*rv 的值*/

typedef enum {

    _SHR_E_NONE                 = 0,

    _SHR_E_INTERNAL             = -1,

    _SHR_E_MEMORY               = -2,

    _SHR_E_UNIT                 = -3,

    _SHR_E_PARAM                = -4,

    _SHR_E_EMPTY                = -5,

    _SHR_E_FULL                 = -6,

    _SHR_E_NOT_FOUND            = -7,

    _SHR_E_EXISTS               = -8,

    _SHR_E_TIMEOUT              = -9,

    _SHR_E_BUSY                 = -10,

    _SHR_E_FAIL                 = -11,

    _SHR_E_DISABLED             = -12,

    _SHR_E_BADID                = -13,

    _SHR_E_RESOURCE             = -14,

    _SHR_E_CONFIG               = -15,

    _SHR_E_UNAVAIL              = -16,

    _SHR_E_INIT                 = -17,

    _SHR_E_PORT                 = -18,

 

    _SHR_E_LIMIT                = -19           /* Must come last */

} _shr_error_t;

 

char *_shr_errmsg[] = _SHR_ERRMSG_INIT;

/*定义自己的系统功能出错类别*/

#define _SHR_ERRMSG_INIT        { \

        "Ok",                           /* E_NONE */ \

        "Internal error",               /* E_INTERNAL */ \

        "Out of memory",                /* E_MEMORY */ \

        "Invalid unit",                 /* E_UNIT */ \

        "Invalid parameter",            /* E_PARAM */ \

        "Table empty",                  /* E_EMPTY */ \

        "Table full",                   /* E_FULL */ \

        "Entry not found",              /* E_NOT_FOUND */ \

        "Entry exists",                 /* E_EXISTS */ \

        "Operation timed out",          /* E_TIMEOUT */ \

        "Operation still running",      /* E_BUSY */ \

        "Operation failed",             /* E_FAIL */ \

        "Operation disabled",           /* E_DISABLED */ \

        "Invalid identifier",           /* E_BADID */ \

        "No resources for operation",   /* E_RESOURCE */ \

        "Invalid configuration",        /* E_CONFIG */ \

        "Feature unavailable",          /* E_UNAVAIL */ \

        "Feature not initialized",      /* E_INIT */ \

        "Invalid port",                 /* E_PORT */ \

        "Unknown error"                 /* E_LIMIT */ \

        }

 

简单设计添加到自己代码中即可实现,问题原因的定位,查看函数返回值的问题情况

 

 

一个小例子如下:

#include <stdio.h>

#define MYDEBUG(X,Y) \

        if(X & TEST) printf Y

 

static int TEST = 1;

 

char *mymsg[] = {"one","two","three"};

 

enum LISTM{

    DEBUG_1,

    DEBUG_2,

    DEBUG_3

};

 

 

int main()

{

    MYDEBUG(1,("MYTEST:%s\n",mymsg[DEBUG_1]));

    MYDEBUG(0,("MYTEST:%s\n",mymsg[DEBUG_2]));

    return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  struct c语言