Using assertion in the Linux kernel

后端 未结 6 1159
挽巷
挽巷 2021-02-05 03:09

I have a question about assert() in Linux: can I use it in the kernel?

If no, what techniques do you usually use if, for example I don\'t want to enter NULL

6条回答
  •  故里飘歌
    2021-02-05 03:41

    I use this macro, it uses BUG() but adds some more info I normally use for debugging, and of course you can edit it to include more info if you wish:

    #define ASSERT(x)                                                       \
    do {    if (x) break;                                                   \
            printk(KERN_EMERG "### ASSERTION FAILED %s: %s: %d: %s\n",      \
                   __FILE__, __func__, __LINE__, #x); dump_stack(); BUG();  \
    } while (0)
    

提交回复
热议问题