printk-formats.txt 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. If variable is of Type, use printk format specifier:
  2. ---------------------------------------------------------
  3. int %d or %x
  4. unsigned int %u or %x
  5. long %ld or %lx
  6. unsigned long %lu or %lx
  7. long long %lld or %llx
  8. unsigned long long %llu or %llx
  9. size_t %zu or %zx
  10. ssize_t %zd or %zx
  11. s32 %d or %x
  12. u32 %u or %x
  13. s64 %lld or %llx
  14. u64 %llu or %llx
  15. If <type> is dependent on a config option for its size (e.g., sector_t,
  16. blkcnt_t) or is architecture-dependent for its size (e.g., tcflag_t), use a
  17. format specifier of its largest possible type and explicitly cast to it.
  18. Example:
  19. printk("test: sector number/total blocks: %llu/%llu\n",
  20. (unsigned long long)sector, (unsigned long long)blockcount);
  21. Reminder: sizeof() result is of type size_t.
  22. Raw pointer value SHOULD be printed with %p. The kernel supports
  23. the following extended format specifiers for pointer types:
  24. Symbols/Function Pointers:
  25. %pF versatile_init+0x0/0x110
  26. %pf versatile_init
  27. %pS versatile_init+0x0/0x110
  28. %pSR versatile_init+0x9/0x110
  29. (with __builtin_extract_return_addr() translation)
  30. %ps versatile_init
  31. %pB prev_fn_of_versatile_init+0x88/0x88
  32. For printing symbols and function pointers. The 'S' and 's' specifiers
  33. result in the symbol name with ('S') or without ('s') offsets. Where
  34. this is used on a kernel without KALLSYMS - the symbol address is
  35. printed instead.
  36. The 'B' specifier results in the symbol name with offsets and should be
  37. used when printing stack backtraces. The specifier takes into
  38. consideration the effect of compiler optimisations which may occur
  39. when tail-call's are used and marked with the noreturn GCC attribute.
  40. On ia64, ppc64 and parisc64 architectures function pointers are
  41. actually function descriptors which must first be resolved. The 'F' and
  42. 'f' specifiers perform this resolution and then provide the same
  43. functionality as the 'S' and 's' specifiers.
  44. Kernel Pointers:
  45. %pK 0x01234567 or 0x0123456789abcdef
  46. For printing kernel pointers which should be hidden from unprivileged
  47. users. The behaviour of %pK depends on the kptr_restrict sysctl - see
  48. Documentation/sysctl/kernel.txt for more details.
  49. Struct Resources:
  50. %pr [mem 0x60000000-0x6fffffff flags 0x2200] or
  51. [mem 0x0000000060000000-0x000000006fffffff flags 0x2200]
  52. %pR [mem 0x60000000-0x6fffffff pref] or
  53. [mem 0x0000000060000000-0x000000006fffffff pref]
  54. For printing struct resources. The 'R' and 'r' specifiers result in a
  55. printed resource with ('R') or without ('r') a decoded flags member.
  56. Passed by reference.
  57. Physical addresses types phys_addr_t:
  58. %pa[p] 0x01234567 or 0x0123456789abcdef
  59. For printing a phys_addr_t type (and its derivatives, such as
  60. resource_size_t) which can vary based on build options, regardless of
  61. the width of the CPU data path. Passed by reference.
  62. DMA addresses types dma_addr_t:
  63. %pad 0x01234567 or 0x0123456789abcdef
  64. For printing a dma_addr_t type which can vary based on build options,
  65. regardless of the width of the CPU data path. Passed by reference.
  66. Raw buffer as an escaped string:
  67. %*pE[achnops]
  68. For printing raw buffer as an escaped string. For the following buffer
  69. 1b 62 20 5c 43 07 22 90 0d 5d
  70. few examples show how the conversion would be done (the result string
  71. without surrounding quotes):
  72. %*pE "\eb \C\a"\220\r]"
  73. %*pEhp "\x1bb \C\x07"\x90\x0d]"
  74. %*pEa "\e\142\040\\\103\a\042\220\r\135"
  75. The conversion rules are applied according to an optional combination
  76. of flags (see string_escape_mem() kernel documentation for the
  77. details):
  78. a - ESCAPE_ANY
  79. c - ESCAPE_SPECIAL
  80. h - ESCAPE_HEX
  81. n - ESCAPE_NULL
  82. o - ESCAPE_OCTAL
  83. p - ESCAPE_NP
  84. s - ESCAPE_SPACE
  85. By default ESCAPE_ANY_NP is used.
  86. ESCAPE_ANY_NP is the sane choice for many cases, in particularly for
  87. printing SSIDs.
  88. If field width is omitted the 1 byte only will be escaped.
  89. Raw buffer as a hex string:
  90. %*ph 00 01 02 ... 3f
  91. %*phC 00:01:02: ... :3f
  92. %*phD 00-01-02- ... -3f
  93. %*phN 000102 ... 3f
  94. For printing a small buffers (up to 64 bytes long) as a hex string with
  95. certain separator. For the larger buffers consider to use
  96. print_hex_dump().
  97. MAC/FDDI addresses:
  98. %pM 00:01:02:03:04:05
  99. %pMR 05:04:03:02:01:00
  100. %pMF 00-01-02-03-04-05
  101. %pm 000102030405
  102. %pmR 050403020100
  103. For printing 6-byte MAC/FDDI addresses in hex notation. The 'M' and 'm'
  104. specifiers result in a printed address with ('M') or without ('m') byte
  105. separators. The default byte separator is the colon (':').
  106. Where FDDI addresses are concerned the 'F' specifier can be used after
  107. the 'M' specifier to use dash ('-') separators instead of the default
  108. separator.
  109. For Bluetooth addresses the 'R' specifier shall be used after the 'M'
  110. specifier to use reversed byte order suitable for visual interpretation
  111. of Bluetooth addresses which are in the little endian order.
  112. Passed by reference.
  113. IPv4 addresses:
  114. %pI4 1.2.3.4
  115. %pi4 001.002.003.004
  116. %p[Ii]4[hnbl]
  117. For printing IPv4 dot-separated decimal addresses. The 'I4' and 'i4'
  118. specifiers result in a printed address with ('i4') or without ('I4')
  119. leading zeros.
  120. The additional 'h', 'n', 'b', and 'l' specifiers are used to specify
  121. host, network, big or little endian order addresses respectively. Where
  122. no specifier is provided the default network/big endian order is used.
  123. Passed by reference.
  124. IPv6 addresses:
  125. %pI6 0001:0002:0003:0004:0005:0006:0007:0008
  126. %pi6 00010002000300040005000600070008
  127. %pI6c 1:2:3:4:5:6:7:8
  128. For printing IPv6 network-order 16-bit hex addresses. The 'I6' and 'i6'
  129. specifiers result in a printed address with ('I6') or without ('i6')
  130. colon-separators. Leading zeros are always used.
  131. The additional 'c' specifier can be used with the 'I' specifier to
  132. print a compressed IPv6 address as described by
  133. http://tools.ietf.org/html/rfc5952
  134. Passed by reference.
  135. IPv4/IPv6 addresses (generic, with port, flowinfo, scope):
  136. %pIS 1.2.3.4 or 0001:0002:0003:0004:0005:0006:0007:0008
  137. %piS 001.002.003.004 or 00010002000300040005000600070008
  138. %pISc 1.2.3.4 or 1:2:3:4:5:6:7:8
  139. %pISpc 1.2.3.4:12345 or [1:2:3:4:5:6:7:8]:12345
  140. %p[Ii]S[pfschnbl]
  141. For printing an IP address without the need to distinguish whether it's
  142. of type AF_INET or AF_INET6, a pointer to a valid 'struct sockaddr',
  143. specified through 'IS' or 'iS', can be passed to this format specifier.
  144. The additional 'p', 'f', and 's' specifiers are used to specify port
  145. (IPv4, IPv6), flowinfo (IPv6) and scope (IPv6). Ports have a ':' prefix,
  146. flowinfo a '/' and scope a '%', each followed by the actual value.
  147. In case of an IPv6 address the compressed IPv6 address as described by
  148. http://tools.ietf.org/html/rfc5952 is being used if the additional
  149. specifier 'c' is given. The IPv6 address is surrounded by '[', ']' in
  150. case of additional specifiers 'p', 'f' or 's' as suggested by
  151. https://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-07
  152. In case of IPv4 addresses, the additional 'h', 'n', 'b', and 'l'
  153. specifiers can be used as well and are ignored in case of an IPv6
  154. address.
  155. Passed by reference.
  156. Further examples:
  157. %pISfc 1.2.3.4 or [1:2:3:4:5:6:7:8]/123456789
  158. %pISsc 1.2.3.4 or [1:2:3:4:5:6:7:8]%1234567890
  159. %pISpfc 1.2.3.4:12345 or [1:2:3:4:5:6:7:8]:12345/123456789
  160. UUID/GUID addresses:
  161. %pUb 00010203-0405-0607-0809-0a0b0c0d0e0f
  162. %pUB 00010203-0405-0607-0809-0A0B0C0D0E0F
  163. %pUl 03020100-0504-0706-0809-0a0b0c0e0e0f
  164. %pUL 03020100-0504-0706-0809-0A0B0C0E0E0F
  165. For printing 16-byte UUID/GUIDs addresses. The additional 'l', 'L',
  166. 'b' and 'B' specifiers are used to specify a little endian order in
  167. lower ('l') or upper case ('L') hex characters - and big endian order
  168. in lower ('b') or upper case ('B') hex characters.
  169. Where no additional specifiers are used the default big endian
  170. order with lower case hex characters will be printed.
  171. Passed by reference.
  172. dentry names:
  173. %pd{,2,3,4}
  174. %pD{,2,3,4}
  175. For printing dentry name; if we race with d_move(), the name might be
  176. a mix of old and new ones, but it won't oops. %pd dentry is a safer
  177. equivalent of %s dentry->d_name.name we used to use, %pd<n> prints
  178. n last components. %pD does the same thing for struct file.
  179. Passed by reference.
  180. struct va_format:
  181. %pV
  182. For printing struct va_format structures. These contain a format string
  183. and va_list as follows:
  184. struct va_format {
  185. const char *fmt;
  186. va_list *va;
  187. };
  188. Do not use this feature without some mechanism to verify the
  189. correctness of the format string and va_list arguments.
  190. Passed by reference.
  191. struct clk:
  192. %pC pll1
  193. %pCn pll1
  194. %pCr 1560000000
  195. For printing struct clk structures. '%pC' and '%pCn' print the name
  196. (Common Clock Framework) or address (legacy clock framework) of the
  197. structure; '%pCr' prints the current clock rate.
  198. Passed by reference.
  199. bitmap and its derivatives such as cpumask and nodemask:
  200. %*pb 0779
  201. %*pbl 0,3-6,8-10
  202. For printing bitmap and its derivatives such as cpumask and nodemask,
  203. %*pb output the bitmap with field width as the number of bits and %*pbl
  204. output the bitmap as range list with field width as the number of bits.
  205. Passed by reference.
  206. Thank you for your cooperation and attention.
  207. By Randy Dunlap <rdunlap@infradead.org> and
  208. Andrew Murray <amurray@mpc-data.co.uk>