[转]printk usage

原文地址:http://elinux.org/Debugging_by_printing#Usage 

If variable is of Type, use printk format specifier:
---------------------------------------------------------
int %d or %x
unsigned int %u or %x
long %ld or %lx
unsigned long %lu or %lx
long long %lld or %llx
unsigned long long %llu or %llx
size_t %zu or %zx
ssize_t %zd or %zx

Raw pointer value SHOULD be printed with %p. The kernel supports
the following extended format specifiers for pointer types:

Symbols/Function Pointers:

%pF versatile_init+0x0/0x110
%pf versatile_init
%pS versatile_init+0x0/0x110
%pSR versatile_init+0x9/0x110
(with __builtin_extract_return_addr() translation)
%ps versatile_init
%pB prev_fn_of_versatile_init+0x88/0x88

For printing symbols and function pointers. The ‘S‘ and ‘s‘ specifiers
result in the symbol name with (‘S‘) or without (‘s‘) offsets. Where
this is used on a kernel without KALLSYMS - the symbol address is
printed instead.

The ‘B‘ specifier results in the symbol name with offsets and should be
used when printing stack backtraces. The specifier takes into
consideration the effect of compiler optimisations which may occur
when tail-call‘s are used and marked with the noreturn GCC attribute.

On ia64, ppc64 and parisc64 architectures function pointers are
actually function descriptors which must first be resolved. The ‘F‘ and
‘f‘ specifiers perform this resolution and then provide the same
functionality as the ‘S‘ and ‘s‘ specifiers.

Kernel Pointers:

%pK 0x01234567 or 0x0123456789abcdef

For printing kernel pointers which should be hidden from unprivileged
users. The behaviour of %pK depends on the kptr_restrict sysctl - see
Documentation/sysctl/kernel.txt for more details.

Struct Resources:

%pr [mem 0x60000000-0x6fffffff flags 0x2200] or
[mem 0x0000000060000000-0x000000006fffffff flags 0x2200]
%pR [mem 0x60000000-0x6fffffff pref] or
[mem 0x0000000060000000-0x000000006fffffff pref]

For printing struct resources. The ‘R‘ and ‘r‘ specifiers result in a
printed resource with (‘R‘) or without (‘r‘) a decoded flags member.

Physical addresses:

%pa 0x01234567 or 0x0123456789abcdef

For printing a phys_addr_t type (and its derivatives, such as
resource_size_t) which can vary based on build options, regardless of
the width of the CPU data path. Passed by reference.

Raw buffer as a hex string:
%*ph 00 01 02 ... 3f
%*phC 00:01:02: ... :3f
%*phD 00-01-02- ... -3f
%*phN 000102 ... 3f

For printing a small buffers (up to 64 bytes long) as a hex string with
certain separator. For the larger buffers consider to use
print_hex_dump().

MAC/FDDI addresses:

%pM 00:01:02:03:04:05
%pMR 05:04:03:02:01:00
%pMF 00-01-02-03-04-05
%pm 000102030405
%pmR 050403020100

For printing 6-byte MAC/FDDI addresses in hex notation. The ‘M‘ and ‘m‘
specifiers result in a printed address with (‘M‘) or without (‘m‘) byte
separators. The default byte separator is the colon (‘:‘).

Where FDDI addresses are concerned the ‘F‘ specifier can be used after
the ‘M‘ specifier to use dash (‘-‘) separators instead of the default
separator.

For Bluetooth addresses the ‘R‘ specifier shall be used after the ‘M‘
specifier to use reversed byte order suitable for visual interpretation
of Bluetooth addresses which are in the little endian order.

IPv4 addresses:

%pI4 1.2.3.4
%pi4 001.002.003.004
%p[Ii][hnbl]

For printing IPv4 dot-separated decimal addresses. The ‘I4‘ and ‘i4‘
specifiers result in a printed address with (‘i4‘) or without (‘I4‘)
leading zeros.

The additional ‘h‘, ‘n‘, ‘b‘, and ‘l‘ specifiers are used to specify
host, network, big or little endian order addresses respectively. Where
no specifier is provided the default network/big endian order is used.

IPv6 addresses:

%pI6 0001:0002:0003:0004:0005:0006:0007:0008
%pi6 00010002000300040005000600070008
%pI6c 1:2:3:4:5:6:7:8

For printing IPv6 network-order 16-bit hex addresses. The ‘I6‘ and ‘i6‘
specifiers result in a printed address with (‘I6‘) or without (‘i6‘)
colon-separators. Leading zeros are always used.

The additional ‘c‘ specifier can be used with the ‘I‘ specifier to
print a compressed IPv6 address as described by
http://tools.ietf.org/html/rfc5952

UUID/GUID addresses:

%pUb 00010203-0405-0607-0809-0a0b0c0d0e0f
%pUB 00010203-0405-0607-0809-0A0B0C0D0E0F
%pUl 03020100-0504-0706-0809-0a0b0c0e0e0f
%pUL 03020100-0504-0706-0809-0A0B0C0E0E0F

For printing 16-byte UUID/GUIDs addresses. The additional ‘l‘, ‘L‘,
‘b‘ and ‘B‘ specifiers are used to specify a little endian order in
lower (‘l‘) or upper case (‘L‘) hex characters - and big endian order
in lower (‘b‘) or upper case (‘B‘) hex characters.

Where no additional specifiers are used the default little endian
order with lower case hex characters will be printed.

struct va_format:

%pV

For printing struct va_format structures. These contain a format string
and va_list as follows:

struct va_format {
const char *fmt;
va_list *va;
};

Do not use this feature without some mechanism to verify the
correctness of the format string and va_list arguments.

u64 SHOULD be printed with %llu/%llx, (unsigned long long):

printk("%llu", (unsigned long long)u64_var);

s64 SHOULD be printed with %lld/%llx, (long long):

printk("%lld", (long long)s64_var);

If <type> is dependent on a config option for its size (e.g., sector_t,
blkcnt_t) or is architecture-dependent for its size (e.g., tcflag_t), use a
format specifier of its largest possible type and explicitly cast to it.
Example:

printk("test: sector number/total blocks: %llu/%llu\n",
(unsigned long long)sector, (unsigned long long)blockcount);

Reminder: sizeof() result is of type size_t.

Thank you for your cooperation and attention.

Reference:
http://elinux.org/Kernel_Debugging_Tips#Using_a_kernel_debugger 
http://blog.csdn.net/yihui8/article/details/6736679 
 
By Randy Dunlap <[email protected]> and
Andrew Murray <[email protected]>

[转]printk usage,布布扣,bubuko.com

时间: 2024-10-24 07:06:39

[转]printk usage的相关文章

sharepoint 2013 开启 Usage and Health Data Collection

Usage and Health Data Collection Monitoring the status of your farm's health is a critical aspect of SharePoint administration. This service application collects the various logging information stored in SharePoint and writes it to the logging databa

[转]Disk Space Usage and SQL Server Performance

Disk Space Usage and SQL Server Performance By Gregory A. Larsen When you think of SQL Server performance components, you think of the usage of CPU, memory, and the I/O it takes to process a query. However, there is another component you should consi

CSS减肥的工具–Firefox插件 CSS Usage

首先,我们需要安装Firefox(猛击此处下载),或者确定你已经安装的版本已经高于3.1; 第二步,安装前端开发人员最普及的开发工具 Firebug: 第三步,安装CSS Usage 0.3.4.1: 第四步,在浏览器中打开我们要优化的页面(本地的页面也可以),点击右下角的firebug小图标,打开firebug工具窗口,我们会看到在工具选项中我们有一个 CSS Usage工具的按钮. 首先我们来分析最上面的三个功能按钮的使用 Scan: 通过字面意思我们就能知道,这是一个扫描当前页面的工具,如

关于 printk() 对 spi slave 内核驱动程序的性能影响

调试 imx6 的 spi slave 内核驱动,前期调试总免不了得要追一下寄存器的设置,过程函数的调用. 采用了 printk() 打印语句. 1.采用的硬件方法是: 分析 imx6 spi slave 的各路引脚主要是 clk, cs, mosi, miso, gnd, vcc,连接至spi 主端(CC1110f32 MCU) 的各路对应引脚.对应如下:  imx6 spi 从机 cc1110f32 spi 主机 vcc vcc gnd gnd clk clk cs cs mosi mosi

【DataStructure】Description and usage of queue

[Description] A queue is a collection that implements the first-in-first-out protocal. This means that the only accessiable object in the collection in the first one that was inserted. The most common example of a queue is a waiting line. [Interface]

【DataStructure】One of queue usage: Simulation System

Statements: This blog was written by me, but most of content  is quoted from book[Data Structure with Java Hubbard] [Description] This simulationillustrates objectoriented programming(OOP). Java objects are instantiated to represent all the interacti

Windows 8 Disk Usage Keep up 100%

Recently i find the windows8 Disk Usage always keep up 100%, It must be have some issue. Step1. Go into Open Task Manager Step2. Go to Details tab Step3. Right click the columns headers and click "Select Columns" Step4. From the "Select Col

Linux tar command usage

Linux tar command usage */--> Linux tar command usage Table of Contents 1. Create an archive: 2. Create a gzipped archive: 3. List the files in an archive 4. Add a file or directory to an existing archive The frequently used tar command are listed as

A Complete Guide to Usage of ‘usermod’ command– 15 Practical Examples with Screenshots

https://www.tecmint.com/usermod-command-examples/ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- In Unix/Linux distribut