debug.h revision d14abf155341d55053c76eeec58b787a456b753b
#ifndef _DEBUG_H_
#define _DEBUG_H_
/* TBA - complete debug.h file content */
#ifdef __LINUX
#elif defined(USER_LINUX)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#endif
#include "bcmtype.h"
#define DBG_ERR_STR "(!)"
#define DBG_WRN_STR "(?)"
// convert __FILE__ to wchar_t - __WFILE__
#define WIDEN2(x) L ## x
// This is a substitution for __FILE__ in order to get rid of entire file path
#if !(defined _VBD_CMD_)
#else // VBD_CMD
#define __FILE_STRIPPED__ __FILE__
#define __WFILE_STRIPPED__ __WFILE__
// Currently only VBD_CMD support it but maybe other USER_MODE like WineDiag should support it as well
#define printf_ex printf_color
#endif // !(_VBD_CMD_)
#define MAX_STR_DBG_LOGGER_NAME 100
// logger callback prototype
typedef u8_t (*debug_logger_cb_t)( void *context, long msg_code, long gui_code, u8_t b_raise_gui, u32_t string_cnt, u32_t data_cnt, ...) ;
// logger functins prototype
long msg_code,
long gui_code,
void* context,
u32_t times_to_log ) ;
u8_t debug_execute_loggers ( unsigned short* wsz_file, unsigned long line, unsigned short* wsz_cond ) ;
// max number of loggers
#define MAX_DEBUG_LOGGER_CNT 3
typedef struct _dbg_logger_t
{
void* context ; // unique context
} dbg_logger_t ;
/* Debug Break Filters */
extern u32_t g_dbg_flags;
#define MEMORY_ALLOCATION_FAILURE 0x1
#define FW_SANITY_UPLOAD_CHECK 0x2
#define UNDER_TEST 0x4
#define INVALID_MESSAGE_ID 0x8
#define ABORTIVE_DISCONNECT_DURING_IND 0x10
#define SRIOV_TEST 0x20
/* Storage defined in the module main c file */
extern u8_t dbg_trace_level;
extern u32_t dbg_code_path;
/* code paths */
/* more code paths can be added
* bits that are still not defined can be privately used in each module */
#define CP_ALL 0xffffff00
#define CP_MASK 0xffffff00
/* Message levels. */
typedef enum
{
LV_VERBOSE = 0x04,
LV_INFORM = 0x03,
LV_WARN = 0x02,
LV_FATAL = 0x01
} msg_level_t;
#define LV_MASK 0xff
/* Code path and messsage level combined. These are the first argument
* of the DbgMessage macro. */
/* Error Recovery */
/* Elink */
/* Encapsulated packets */
/* This is an existing debug macro in 2.6.27 Linux kernel */
#ifdef WARN
#endif
#if defined(_VBD_)
#define WARN (0)
#else
#endif
#define DbgBreakIfAll(_cond) do {\
if(_cond) \
{ \
log_message("DEBUG BREAK! Condition failed: if("#_cond##") at file %s (line %4d)\n", __FILE_STRIPPED__, __LINE__); \
assert(0); \
} \
} while(0)
#define EXECUTE_LOGGERS(_s) do {\
} while(0)
#include <assert.h>
#include <string.h>
#define DbgBreakIfAll(_cond) do {\
if(_cond) \
{ \
assert(0); \
} \
} while(0)
#define DbgBreakIfAll(_cond) do {\
if(_cond) \
{ \
debug_break(); \
} \
} while(0)
#if defined(__SunOS_MDB)
#define DbgBreakIfAll(_c) \
do { \
if (_c) \
{ \
/* nop in MDB */ ; \
} \
} while (0)
#else /* !__SunOS_MDB */
#define DbgBreakIfAll(_c) \
do { \
if (_c) \
{ \
__LINE__); \
} \
} while (0)
#endif /* __SunOS_MDB */
#define EXECUTE_LOGGERS(_s)
#else // Windows
long msg_code,
long gui_code,
unsigned char b_raise_gui,
unsigned int string_cnt,
unsigned int data_cnt,
...);
#if DBG
#else
#include <ntddk.h>
#include <wchar.h>
/*******************************************************************************
* Debug Print callback - printk (DbgPrint/vDbgPrintEx)
******************************************************************************/
typedef
...);
extern PFN_DRIVER_TRACE printk;
#define DbgBreakIfAll(_cond) do {\
if(_cond) \
{ \
if ( win_debug_enter_fatal_state(FALSE) )\
{\
DbgBreakPoint();\
}\
} \
} while(0)
#endif //DBG
#endif
#if DBG
/* These constants control the output of messages.
* Set your debug message output level and code path here. */
#ifndef DBG_MSG_CP
#endif
#ifndef DBG_MSG_LV
#ifdef _VBD_CMD_
#define DBG_MSG_LV dbg_trace_level
#else
//change this to higher level than FATAL to open debug messages.
#endif
#endif
//STATIC is now not empty define
#ifndef STATIC
#define STATIC static
#endif
//#define DbgBreak(_c)
/* This is the original implementation where both code path and debug level can only be defined
once at compile time */
#if 0
#endif
/* per OS methods */
#if defined(UEFI)
#include <stdio.h>
#include <assert.h>
#include <string.h>
void console_cleanup(void);
void
void
);
void * console_buffer_p
);
void __cdecl
unsigned long level,
char *msg,
...);
do { \
} while (0)
//void DbgMessage(void *dummy, int level, char *msg, ...);
#define DbgMessage
#define log_message
#define debug_break() do { \
console_print(NULL); \
assert(0); \
} while(0)
#define DbgBreak() debug_break()
#define DbgBreakIf(_cond) do {\
if(_cond) \
{ \
debug_break(); \
} \
} while(0)
#define DbgBreakMsg(_s) do { \
debug_break(); \
} while(0)
#define DbgBreakFastPath() DbgBreak()
#define dbg_out(_c, _m, _s, _d1) debug_msgx((WARN), "TrLv<%d>, %s (%4d): %p"##_s" %s\n", ((WARN) & LV_MASK), __FILE_STRIPPED__, __LINE__, _c, _d1 )
#include <stdio.h>
#include <assert.h>
#include <string.h>
void console_cleanup(void);
void
void
);
void * console_buffer_p
);
void __cdecl
unsigned long level,
char *msg,
...);
void __cdecl
char *msg,
...);
// DOS
// TODO: need to relate to dbg_trace_module_name
/*
#define MessageHdr(_dev, _level) \
debug_message("%s, TrLv<%d>, %s (%d): %p ", dbg_trace_module_name, (_level), __FILE_STRIPPED__, __LINE__, _dev )
*/
// DOS
do { \
debug_message((_level), "TrLv<%d>, %s (%4d): ", ((_level) & LV_MASK), __FILE_STRIPPED__, __LINE__); \
} while (0)
do { \
} while(0)
// DOS
#define debug_break() do { \
console_print(NULL); \
assert(0); \
} while(0)
// DOS
#define DbgBreak() debug_break()
// DOS
#define DbgBreakIf(_cond) do {\
if(_cond) \
{ \
debug_break(); \
} \
} while(0)
// DOS
#define DbgBreakMsg(_s) do { \
debug_break(); \
} while(0)
// DOS
#define DbgBreakFastPath() DbgBreak()
// DOS
#define dbg_out(_c, _m, _s, _d1) debug_msgx((WARN), "TrLv<%d>, %s (%4d): %p"##_s" %s\n", ((WARN) & LV_MASK), __FILE_STRIPPED__, __LINE__, _c, _d1 )
#elif defined(__USER_MODE_DEBUG)
#include <stdio.h>
#include <assert.h>
#include <string.h>
void __cdecl
char *msg,
...);
// TODO: need to relate to dbg_trace_module_name
/*
#define MessageHdr(_dev, _level) \
debug_message("%s, TrLv<%d>, %s (%d): %p ", dbg_trace_module_name, (_level), __FILE_STRIPPED__, __LINE__, _dev )
*/
// __USER_MODE_DEBUG
debug_message("TrLv<%d>, %-12s (%4d): %p ", ((_level) & LV_MASK), __FILE_STRIPPED__, __LINE__, _dev )
{ \
}
// __USER_MODE_DEBUG
#define debug_break() do { \
assert(0); \
} while(0)
// __USER_MODE_DEBUG
#define DbgBreak() debug_break()
#define DbgBreakIf(_cond) do {\
if(_cond) \
{ \
debug_break(); \
} \
} while(0)
// __USER_MODE_DEBUG
#define DbgBreakMsg(_s) do { \
debug_break(); \
} while(0)
// __USER_MODE_DEBUG
#define DbgBreakFastPath() DbgBreak()
//#define dbg_out(_c, _m, _s, _d1) DbgMessage((_c), (_m), (_s), (_d1))
#define __cdecl
#define DbgBreak debug_break
#ifdef __LINUX
char *os_if_strrchr(char *a, int n);
#define __FILE_STRIPPED__ os_if_strrchr(__FILE__, '/') ? os_if_strrchr(__FILE__, '/') + 1 : __FILE__
#else
#endif
/*******************************************************************************
* Debug break and output routines.
******************************************************************************/
void __cdecl
unsigned long level,
char *msg,
...);
#ifdef USER_LINUX
void __cdecl
char *msg,
...);
#define debug_break() do { \
exit(1); \
} while(0)
#else /* KERNEL */
do { \
} while (0)
void debug_break(void);
#endif
#ifdef USER_LINUX
{ \
}
#else /* __LINUX */
{ \
}
#endif
#define DbgMessage DbgMessageXX
// LINUX
#ifdef USER_LINUX
#define DbgBreakIf(_c) \
if(_c) \
{ \
DbgBreak(); \
}
#else /* __LINUX */
#define DbgBreakIf(_c) \
{ \
DbgBreak(); \
}
#endif
// LINUX
// LINUX
#define DbgBreakFastPath() DbgBreak()
#define dbg_out(_c, _m, _s, _d1) debug_msgx(_m, "TrLv<%d>, %s (%4d): %p"_s" %s\n", ((WARN) & LV_MASK), __FILE_STRIPPED__, __LINE__, _c, _d1 )
#if defined(__SunOS_MDB)
#define DbgBreak()
#define DbgBreakIf(_cond)
#define DbgBreakMsg(_s)
#define DbgBreakFastPath()
#define DbgBreakIfFastPath(_cond)
#define DbgBreakMsgFastPath(_s)
#else
#include "bnxe_debug.h"
#endif
#else
#if defined(_VBD_)
#include <SAL.h>
#endif
#ifndef _In_
#define _In_
#endif
#ifndef _Out_
#define _Out_
#endif
/*******************************************************************************
* Debug break and output routines.
******************************************************************************/
void
void *ctx);
void __cdecl
void *ctx,
unsigned long level,
unsigned long line,
...);
void __cdecl
void *ctx,
unsigned long level,
...);
void um_dbg_log_msg(void* ctx, char *file, char *function, unsigned long line, const char* format_msg, unsigned int args_num, ...);
#define VA_NUM_ARGS_SIZE_PREFIX__VA_NUM_ARGS_SIZE_POSTFIX ,,,,,,,,,,0
#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMP_((VA_NUM_ARGS_SIZE_PREFIX_ ## __VA_ARGS__ ## _VA_NUM_ARGS_SIZE_POSTFIX,10,9,8,7,6,5,4,3,2,1,0))
// WINDDK
{ \
um_dbg_log_msg(_c, __FILE__, __FUNCTION__, __LINE__, _s, VA_NUM_ARGS(##__VA_ARGS__), ##__VA_ARGS__); \
}
// WINDDK
#define DbgBreakIf(_c) \
if(_c) \
{ \
__debugbreak(); \
}
// WINDDK
// WINDDK
// WINDDK (debug)
#define DbgBreakFastPath() DbgBreak()
// WINDDK
#endif //OS architectures
// Error Macros (Currently supports Windows DDK & DOS):
// in debug builds - outputs a debug message and enter condition in case TRUE
// in release builds - enters condition in case TRUE (like debug but without the debug print)
// Macro for checking parameter for NULL value
// Usage Example:
// if( CHECK_NULL( ptr ))
// {
// return FALSE ;
// }
#define CHK_NULL(p) ((p==NULL) ? (dbg_out(NULL, WARN, DBG_ERR_STR" %s is NULL\n",#p), TRUE): FALSE )
// Macros that returns the value of the expression and outputs a debug string in debug versions
// Usage Example:
// if( ERR_IF( val < 0 ))
// {
// return FALSE ;
// }
#define ERR_IF(cond)(((cond)==TRUE) ? (dbg_out(NULL, WARN, DBG_ERR_STR" ErrIf failed %s\n",#cond), TRUE): FALSE )
#define WRN_IF(cond)(((cond)==TRUE) ? (dbg_out(NULL, WARN, DBG_WRN_STR" WrnIf failed %s\n",#cond), TRUE): FALSE )
#else // !DBG
#define STATIC static
// WINDDK DbgBreak (retail) and logging an event
#define DbgBreakIf(_cond) if(_cond){ debug_execute_loggers( __WFILE_STRIPPED__ , __LINE__, WIDEN(#_cond##) ); }
// WINDDK DbgBreak (retail) without logging an event
#define DbgBreakNoLog()
#define DbgBreakIfNoLog(_cond)
#define DbgBreakMsgNoLog(_s)
// WINDDK DbgBreak FastPath (retail)
#define DbgBreakFastPath() DbgBreakNoLog()
#else // WIN_DIAG and Linux and Solaris
#define DbgBreak()
#define DbgBreakIf(_cond)
#define DbgBreakMsg(_s)
#define DbgBreakFastPath()
#define DbgBreakIfFastPath(_cond)
#define DbgBreakMsgFastPath(_s)
#endif // !WIN_DIAG
#endif // !DBG
#endif /* _DEBUG_H_ */