Software debugging: using assertion ASSERT macro positioning software bug
/ * * Author: DavidLin * Date: 2014-12-26pm * Email: linpeng1577@163.com or linpeng1577@gmail.com * 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#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 case: test.c * / # include#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);}
Software Bug positioning, in many cases, such as the use of Assert macros, you can compress the 48-hour debugging meal into a dessert that can be eaten, each software team is re-evolving, the past experience is not always a good inheritance, this is us!