如何输出dev_dbg log

本文介绍了一种在Linux内核中利用动态调试功能输出特定模块日志的方法,通过修改debugfs中的控制文件,可以灵活地控制dev_dbg等宏的输出,避免频繁修改源代码和重新编译。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<div id="article_content" class="article_content">


<span style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">&nbsp; &nbsp; kernel里面默认都配置了CONFIG_DYNAMIC_DEBUG=y;</span><br style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">
<span style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">&nbsp;&nbsp; &nbsp; 假如我们要打印acpuclock-krait.c中的</span><br style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">
<span style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">&nbsp;&nbsp; &nbsp; dev_dbg(drv.dev, "ACPU%d speed change complete\n", cpu);</span><br style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">
<span style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">&nbsp;&nbsp; &nbsp; 在adb shell中输入:</span><br style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">
<span style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">&nbsp;&nbsp; &nbsp; mount –t debugfs none /sys/kernel/debug&nbsp;</span><br style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">
<span style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">&nbsp;&nbsp; &nbsp; cd /sys/kernel/debug&nbsp;</span><br style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">
<span style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">&nbsp;&nbsp; &nbsp; echo -n 'file acpuclock-krait.c +p' &gt; dynamic_debug/control</span><br style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">
<p><span style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">&nbsp;&nbsp; &nbsp; 上面是大家熟悉的debugfs;下面是打印出的log:</span></p>
<p><span style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px"><img src="https://img-blog.youkuaiyun.com/20130525222623659" alt=""><br>
</span></p>
<br style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">
<span style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">&nbsp; &nbsp; 个人觉得懂得这个方法输出log很重要,linux里面许许多多的地方使用了dev_dbg,总不能每次想输出log改成dev_err,再build fastboot,</span><br style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">
<span style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">为什么这样就可以输出Log了?请参考网上文章:</span><br style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">
<a href="http://blog.youkuaiyun.com/pillarbuaa/article/details/7634546" target="_blank" style="outline:none; color:rgb(61,94,134); font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">http://blog.<wbr>youkuaiyun.com/pil<wbr>larbuaa/arti<wbr>cle/details/<wbr>7634546</a><br style="font-family:'lucida Grande',Verdana; font-size:14px; line-height:23px">
   
</div>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值