Linux-kernel debug printouts?

前端 未结 2 1309
陌清茗
陌清茗 2020-12-30 06:17

Is there a better way to debug printouts in the Linux kernel?

Right now littering the code with:

printk(KERN_DBG \"%s:%d - %s() \", __         


        
2条回答
  •  醉梦人生
    2020-12-30 07:12

    Use

    /* At the top of the file, before any includes */
    #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
    
    #include 
    
    /* in code... */
    pr_devel("foobar happened\n");
    

    as a basis (the standard practice). You can then add __FILE__ or __LINE__ to the pr_fmt definition if you need.

提交回复
热议问题