標籤:debug
/* *Author : DavidLin *Date : 2014-12-26pm *Email : [email protected] or [email protected] *world : the city of SZ, in China *Ver : 000.000.001 *For : threads for rxtx! *history : editor time do * 1)LinPeng 2014-12-26 created this file! * 2) */ /* assert_self.h */#ifndef __ASSERT_SELF_H__#define __ASSERT_SELF_H__#include<stdio.h>#define ASSERT_ENABLE (1)#define xprintf printf /* xprintf can be tty print or uart print, etc */#if ASSERT_ENABLE#define assert_error() do { xprintf("[ERROR] Assert FILE: %s: LINE %d\n", __FILE__, __LINE__); \ }while(0)#define ASSERT1(para) do { if(!para) { assert_error(); } }while(0) #else /* if ! ASSERT_ENABLE */ #define ASSERT1(para) do { if(para) { } }while(0) #endif /* end of ASSERT_ENABLE */#endif /* end of __ASSERT_SELF_H__*/
測試案例
/* test case : test.c */#include<stdio.h>#include"assert_self.h" int main(int argc, char* argv[]){ switch(argc) {case 2: ASSERT1(atoi(argv[1])); break;default: printf("ARG ACCEPT 1\n"); break; } exit(0);}
軟體Bug定位,很多時候,比如利用Assert宏,可以把48小時的調試大餐壓縮成1口可以吃掉的飯後甜點,每個軟體小組都在重新演化,過去的經驗總是得不到很好的傳承,這就是我們!
軟體調試:利用斷言ASSERT宏定位軟體bug