Linux printk formats

  • 了解 linxu printk formats

1.Integer types

 14     If variable is of Type,     use printk format specifier:
 15     ------------------------------------------------------------
 16         int         %d or %x
 17         unsigned int        %u or %x
 18         long            %ld or %lx
 19         unsigned long       %lu or %lx
 20         long long       %lld or %llx
 21         unsigned long long  %llu or %llx
 22         size_t          %zu or %zx
 23         ssize_t         %zd or %zx
 24         s32         %d or %x
 25         u32         %u or %x
 26         s64         %lld or %llx
 27         u64         %llu or %llx                                                                         

2.Symbols/Function Pointers

 53     %pF versatile_init+0x0/0x110
 54     %pf versatile_init
 55     %pS versatile_init+0x0/0x110
 56     %pSR    versatile_init+0x9/0x110
 57         (with __builtin_extract_return_addr() translation)
 58     %ps versatile_init
 59     %pB prev_fn_of_versatile_init+0x88/0x88

 78 Examples::
 80     printk("Going to call: %pF\n", gettimeofday);
 81     printk("Going to call: %pF\n", p->func);
 82     printk("%s: called from %pS\n", __func__, (void *)_RET_IP_);
 83     printk("%s: called from %pS\n", __func__,
 84                 (void *)__builtin_return_address(0));                                                    
 85     printk("Faulted at %pS\n", (void *)regs->ip);
 86     printk(" %s%pB\n", (reliable ? "" : "? "), (void *)*stack);

3.kobjects

352 kobjects
353 ========                                                                                                 
354 
357     %pO
358 
359     Base specifier for kobject based structs. Must be followed with
360     character for specific type of kobject as listed below:
361 
362     Device tree nodes:
363 
364     %pOF[fnpPcCF]
365 
366     For printing device tree nodes. The optional arguments are:
367         f device node full_name
368         n device node name
369         p device node phandle
370         P device node path spec (name + @unit)
371         F device node flags
372         c major compatible string                                                                        
373         C full compatible string
374     Without any arguments prints full_name (same as %pOFf)
375     The separator when using multiple arguments is ':'

377     Examples:
378 
379     %pOF    /foo/bar@0          - Node full name
380     %pOFf   /foo/bar@0          - Same as above
381     %pOFfp  /foo/bar@0:10           - Node full name + phandle
382     %pOFfcF /foo/bar@0:foo,device:--P-  - Node full name +
383                                               major compatible string +
384                           node flags
385                             D - dynamic
386                             d - detached
387                             P - Populated
388                             B - Populated bus

4.Virtual kernel memory layout print

问题描述:查看kernel log,发现.text等无法显示地址,如下所示:

[    0.000000] Virtual kernel memory layout:
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[    0.000000]     fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
[    0.000000]     vmalloc : 0xf0800000 - 0xff800000   ( 240 MB)
[    0.000000]     lowmem  : 0xc0000000 - 0xf0000000   ( 768 MB)
[    0.000000]     pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)
[    0.000000]     modules : 0xbf000000 - 0xbfe00000   (  14 MB)
[    0.000000]       .text : 0x(ptrval) - 0x(ptrval)   (4064 kB)
[    0.000000]       .init : 0x(ptrval) - 0x(ptrval)   (1024 kB)
[    0.000000]       .data : 0x(ptrval) - 0x(ptrval)   ( 158 kB)
[    0.000000]        .bss : 0x(ptrval) - 0x(ptrval)   (7425 kB)

解决方法:使用%px即可。

arch/arm/mm/init.c:
  540             "      .text : 0x%px" " - 0x%px" "   (%4td kB)\n"                                            
  541             "      .init : 0x%px" " - 0x%px" "   (%4td kB)\n"
  542             "      .data : 0x%px" " - 0x%px" "   (%4td kB)\n"
  543             "       .bss : 0x%px" " - 0x%px" "   (%4td kB)\n",
  544 

修改之后:

[    0.000000] Virtual kernel memory layout:
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[    0.000000]     fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
[    0.000000]     vmalloc : 0xf0800000 - 0xff800000   ( 240 MB)
[    0.000000]     lowmem  : 0xc0000000 - 0xf0000000   ( 768 MB)
[    0.000000]     pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)
[    0.000000]     modules : 0xbf000000 - 0xbfe00000   (  14 MB)
[    0.000000]       .text : 0xc0008000 - 0xc0400000   (4064 kB)
[    0.000000]       .init : 0xc0500000 - 0xc0600000   (1024 kB)
[    0.000000]       .data : 0xc0600000 - 0xc06274a8   ( 158 kB)
[    0.000000]        .bss : 0xc062d170 - 0xc0d6d250   (7425 kB)

参考:
Documentation/printk-formats.txt(linux-4.14)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值