printk(%p的各种方式)

来源:互联网 发布:淘宝卖家信誉等级 编辑:程序博客网 时间:2024/06/17 11:05
https://www.kernel.org/doc/Documentation/printk-formats.txtIf variable is of Type,use printk format specifier:---------------------------------------------------------int%d or %xunsigned int%u or %xlong%ld or %lxunsigned long%lu or %lxlong long%lld or %llxunsigned long long%llu or %llxsize_t%zu or %zxssize_t%zd or %zxs32%d or %xu32%u or %xs64%lld or %llxu64%llu or %llxIf <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 aformat 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.The kernel's printf does not support %n. For obvious reasons, floatingpoint formats (%e, %f, %g, %a) are also not recognized. Use of anyunsupported specifier or length qualifier results in a WARN and earlyreturn from vsnprintf.Raw pointer value SHOULD be printed with %p. The kernel supportsthe following extended format specifiers for pointer types:Symbols/Function Pointers:%pFversatile_init+0x0/0x110  //打印出函数。%pfversatile_init%pSversatile_init+0x0/0x110%pSRversatile_init+0x9/0x110(with __builtin_extract_return_addr() translation)%psversatile_init%pBprev_fn_of_versatile_init+0x88/0x88For printing symbols and function pointers. The 'S' and 's' specifiersresult in the symbol name with ('S') or without ('s') offsets. Wherethis is used on a kernel without KALLSYMS - the symbol address isprinted instead.The 'B' specifier results in the symbol name with offsets and should beused when printing stack backtraces. The specifier takes intoconsideration the effect of compiler optimisations which may occurwhen tail-call's are used and marked with the noreturn GCC attribute.On ia64, ppc64 and parisc64 architectures function pointers areactually function descriptors which must first be resolved. The 'F' and'f' specifiers perform this resolution and then provide the samefunctionality as the 'S' and 's' specifiers.Kernel Pointers:%pK0x01234567 or 0x0123456789abcdefFor printing kernel pointers which should be hidden from unprivilegedusers. The behaviour of %pK depends on the kptr_restrict sysctl - seeDocumentation/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 aprinted resource with ('R') or without ('r') a decoded flags member.Passed by reference.Physical addresses types phys_addr_t:%pa[p]0x01234567 or 0x0123456789abcdefFor printing a phys_addr_t type (and its derivatives, such asresource_size_t) which can vary based on build options, regardless ofthe width of the CPU data path. Passed by reference.DMA addresses types dma_addr_t:%pad0x01234567 or 0x0123456789abcdefFor printing a dma_addr_t type which can vary based on build options,regardless of the width of the CPU data path. Passed by reference.Raw buffer as an escaped string:%*pE[achnops]For printing raw buffer as an escaped string. For the following buffer1b 62 20 5c 43 07 22 90 0d 5dfew examples show how the conversion would be done (the result stringwithout surrounding quotes):%*pE"\eb \C\a"\220\r]"%*pEhp"\x1bb \C\x07"\x90\x0d]"%*pEa"\e\142\040\\\103\a\042\220\r\135"The conversion rules are applied according to an optional combinationof flags (see string_escape_mem() kernel documentation for thedetails):a - ESCAPE_ANYc - ESCAPE_SPECIALh - ESCAPE_HEXn - ESCAPE_NULLo - ESCAPE_OCTALp - ESCAPE_NPs - ESCAPE_SPACEBy default ESCAPE_ANY_NP is used.ESCAPE_ANY_NP is the sane choice for many cases, in particularly forprinting SSIDs.If field width is omitted the 1 byte only will be escaped.Raw buffer as a hex string:%*ph00 01 02  ...  3f%*phC00:01:02: ... :3f%*phD00-01-02- ... -3f%*phN000102 ... 3fFor printing a small buffers (up to 64 bytes long) as a hex string withcertain separator. For the larger buffers consider to useprint_hex_dump().MAC/FDDI addresses:%pM00:01:02:03:04:05   //打印出mac.%pMR05:04:03:02:01:00%pMF00-01-02-03-04-05%pm000102030405%pmR050403020100For printing 6-byte MAC/FDDI addresses in hex notation. The 'M' and 'm'specifiers result in a printed address with ('M') or without ('m') byteseparators. The default byte separator is the colon (':').Where FDDI addresses are concerned the 'F' specifier can be used afterthe 'M' specifier to use dash ('-') separators instead of the defaultseparator.For Bluetooth addresses the 'R' specifier shall be used after the 'M'specifier to use reversed byte order suitable for visual interpretationof Bluetooth addresses which are in the little endian order.Passed by reference.IPv4 addresses:%pI41.2.3.4     //打印出IP struct in_addr%pi4001.002.003.004%p[Ii]4[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 specifyhost, network, big or little endian order addresses respectively. Whereno specifier is provided the default network/big endian order is used.Passed by reference.IPv6 addresses:%pI60001:0002:0003:0004:0005:0006:0007:0008   //打印出IP struct in_addr%pi600010002000300040005000600070008%pI6c1:2:3:4:5:6:7:8For 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 toprint a compressed IPv6 address as described byhttp://tools.ietf.org/html/rfc5952Passed by reference.IPv4/IPv6 addresses (generic, with port, flowinfo, scope):%pIS1.2.3.4or 0001:0002:0003:0004:0005:0006:0007:0008%piS001.002.003.004or 00010002000300040005000600070008%pISc1.2.3.4or 1:2:3:4:5:6:7:8%pISpc1.2.3.4:12345or [1:2:3:4:5:6:7:8]:12345%p[Ii]S[pfschnbl]For printing an IP address without the need to distinguish whether it'sof type AF_INET or AF_INET6, a pointer to a valid 'struct sockaddr',specified through 'IS' or 'iS', can be passed to this format specifier.The additional 'p', 'f', and 's' specifiers are used to specify port(IPv4, IPv6), flowinfo (IPv6) and scope (IPv6). Ports have a ':' prefix,flowinfo a '/' and scope a '%', each followed by the actual value.In case of an IPv6 address the compressed IPv6 address as described byhttp://tools.ietf.org/html/rfc5952 is being used if the additionalspecifier 'c' is given. The IPv6 address is surrounded by '[', ']' incase of additional specifiers 'p', 'f' or 's' as suggested byhttps://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-07In case of IPv4 addresses, the additional 'h', 'n', 'b', and 'l'specifiers can be used as well and are ignored in case of an IPv6address.Passed by reference.Further examples:%pISfc1.2.3.4or [1:2:3:4:5:6:7:8]/123456789%pISsc1.2.3.4or [1:2:3:4:5:6:7:8]%1234567890%pISpfc1.2.3.4:12345or [1:2:3:4:5:6:7:8]:12345/123456789UUID/GUID addresses:%pUb00010203-0405-0607-0809-0a0b0c0d0e0f%pUB00010203-0405-0607-0809-0A0B0C0D0E0F%pUl03020100-0504-0706-0809-0a0b0c0e0e0f%pUL03020100-0504-0706-0809-0A0B0C0E0E0FFor printing 16-byte UUID/GUIDs addresses. The additional 'l', 'L','b' and 'B' specifiers are used to specify a little endian order inlower ('l') or upper case ('L') hex characters - and big endian orderin lower ('b') or upper case ('B') hex characters.Where no additional specifiers are used the default big endianorder with lower case hex characters will be printed.Passed by reference.dentry names:%pd{,2,3,4}%pD{,2,3,4}For printing dentry name; if we race with d_move(), the name might bea mix of old and new ones, but it won't oops.  %pd dentry is a saferequivalent of %s dentry->d_name.name we used to use, %pd<n> printsn last components.  %pD does the same thing for struct file.Passed by reference.block_device names:%pgsda, sda1 or loop0p1For printing name of block_device pointers.struct va_format:%pVFor printing struct va_format structures. These contain a format stringand va_list as follows:struct va_format {const char *fmt;va_list *va;};Implements a "recursive vsnprintf".Do not use this feature without some mechanism to verify thecorrectness of the format string and va_list arguments.Passed by reference.struct clk:%pCpll1%pCnpll1%pCr1560000000For printing struct clk structures. '%pC' and '%pCn' print the name(Common Clock Framework) or address (legacy clock framework) of thestructure; '%pCr' prints the current clock rate.Passed by reference.bitmap and its derivatives such as cpumask and nodemask:%*pb0779%*pbl0,3-6,8-10For printing bitmap and its derivatives such as cpumask and nodemask,%*pb output the bitmap with field width as the number of bits and %*pbloutput the bitmap as range list with field width as the number of bits.Passed by reference.Flags bitfields such as page flags, gfp_flags:%pGpreferenced|uptodate|lru|active|private%pGgGFP_USER|GFP_DMA32|GFP_NOWARN%pGvread|exec|mayread|maywrite|mayexec|denywriteFor printing flags bitfields as a collection of symbolic constants thatwould construct the value. The type of flags is given by the thirdcharacter. Currently supported are [p]age flags, [v]ma_flags (bothexpect unsigned long *) and [g]fp_flags (expects gfp_t *). The flagnames and print order depends on the particulartype.Note that this format should not be used directly in TP_printk() partof a tracepoint. Instead, use the show_*_flags() functions from<trace/events/mmflags.h>.Passed by reference.Network device features:%pNF0x000000000000c000For printing netdev_features_t.Passed by reference.If you add other %p extensions, please extend lib/test_printf.c withone or more test cases, if at all feasible.Thank you for your cooperation and attention.By Randy Dunlap <rdunlap@infradead.org> andAndrew Murray <amurray@mpc-data.co.uk>
原创粉丝点击