Linux kernel 动态调试

何时使用
#if defined(CONFIG_DYNAMIC_DEBUG)
#include <linux/dynamic_debug.h>

/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
#define pr_debug(fmt, ...) \
	dynamic_pr_debug(fmt, ##__VA_ARGS__)
#elif defined(DEBUG)
#define pr_debug(fmt, ...) \
	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#else
#define pr_debug(fmt, ...) \
	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#endif

/*

可以看到pr_debug 会用到,其他用到的暂不举例,一般是是有宏CONFIG_DYNAMIC_DEBUG 条件判断的

官方介绍

  | Symbol: DYNAMIC_DEBUG [=y]                                                     |  
  | Type  : boolean                                                                |  
  | Prompt: Enable dynamic printk() support                                        |  
  |   Location:                                                                    |  
  |     -> Kernel hacking                                                          |  
  |       -> printk and dmesg options                                              |  
  |   Defined at lib/Kconfig.debug:47                                              |  
  |   Depends on: PRINTK [=y] && DEBUG_FS [=y]  
操作方法

通过看Kconfig文件或者执行make menuconfig 查看如何打开kernel动态调试宏

可以把编译选项编译进内核或者手动修改文件(debugfs 文件控制)


CONFIG_PRINTK=y
CONFIG_DEBUG_FS=y
CONFIG_DYNAMIC_DEBUG=y

现在内核已经支持,只需后面几步操作即可看到动态打印效果

实验

正常在下面目录有很多打印

/sys/kernel/debug/dynamic_debug/control

可以用cat 命令打开,最好结合grep 命令使用

查看举例

"internal phy\012"
drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c:163 [dwmac_meson]network_interface_setup =_ "wol not set\012"
drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c:166 [dwmac_meson]network_interface_setup =_ "Ethernet :got wol %d .set it\012"
drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c:218 [dwmac_meson]network_interface_setup =_ "Ethernet: gpio reset ok\012"
drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c:227 [dwmac_meson]network_interface_setup =_ 

注意动态打印信息级别为7,在小于8(控制台打印机别)可以打印出来

1、所以加一条命令

echo 8 > /proc/sys/kernel/printk

2、打开输出

# echo -n 'file stmmac_main.c +p' > /sys/kernel/debug/dynamic_debug/control

对比

		snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x",
			 priv->plat->bus_id);

		snprintf(phy_id_fmt, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
			 priv->plat->phy_addr);
		pr_debug("stmmac_init_phy:  trying to attach to %s\n",
			 phy_id_fmt);

		phydev = phy_connect(dev, phy_id_fmt, &stmmac_adjust_link,
				     interface);

	}

3、结果

[ 1923.119522@3] stmmac_init_phy:  trying to attach to stmmac-0:00 // pr
[ 1923.122955@3] 
[ 1923.129107@3] stmmac_init_phy:  eth0: attached to PHY (UID 0x1cc816) Link = 1
[ 1923.136176@3] stmmac_init_phy:  eth0: attached to PHY (UID 0x1cc816) Link = 1
[ 1923.143889@0] (init_dma_desc_rings) dma_rx_phy=0x1f850000 dma_tx_phy=0x1f852000

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值