8 Dynamic debug allows you to dynamically enable/disable kernel
9 debug-print code to obtain additional kernel information.
11 If ``/proc/dynamic_debug/control`` exists, your kernel has dynamic
12 debug. You'll need root access (sudo su) to use this.
14 Dynamic debug provides:
16 * a Catalog of all *prdbgs* in your kernel.
17 ``cat /proc/dynamic_debug/control`` to see them.
19 * a Simple query/command language to alter *prdbgs* by selecting on
20 any combination of 0 or 1 of:
24 - line number (including ranges of line numbers)
27 - class name (as known/declared by each module)
29 NOTE: To actually get the debug-print output on the console, you may
30 need to adjust the kernel ``loglevel=``, or use ``ignore_loglevel``.
31 Read about these kernel parameters in
32 Documentation/admin-guide/kernel-parameters.rst.
34 Viewing Dynamic Debug Behaviour
35 ===============================
37 You can view the currently configured behaviour in the *prdbg* catalog::
39 :#> head -n7 /proc/dynamic_debug/control
40 # filename:lineno [module]function flags format
41 init/main.c:1179 [main]initcall_blacklist =_ "blacklisting initcall %s\012
42 init/main.c:1218 [main]initcall_blacklisted =_ "initcall %s blacklisted\012"
43 init/main.c:1424 [main]run_init_process =_ " with arguments:\012"
44 init/main.c:1426 [main]run_init_process =_ " %s\012"
45 init/main.c:1427 [main]run_init_process =_ " with environment:\012"
46 init/main.c:1429 [main]run_init_process =_ " %s\012"
48 The 3rd space-delimited column shows the current flags, preceded by
49 a ``=`` for easy use with grep/cut. ``=p`` shows enabled callsites.
51 Controlling dynamic debug Behaviour
52 ===================================
54 The behaviour of *prdbg* sites are controlled by writing
55 query/commands to the control file. Example::
57 # grease the interface
58 :#> alias ddcmd='echo $* > /proc/dynamic_debug/control'
60 :#> ddcmd '-p; module main func run* +p'
61 :#> grep =p /proc/dynamic_debug/control
62 init/main.c:1424 [main]run_init_process =p " with arguments:\012"
63 init/main.c:1426 [main]run_init_process =p " %s\012"
64 init/main.c:1427 [main]run_init_process =p " with environment:\012"
65 init/main.c:1429 [main]run_init_process =p " %s\012"
67 Error messages go to console/syslog::
70 dyndbg: unknown keyword "mode"
71 dyndbg: query parse failed
72 bash: echo: write error: Invalid argument
74 If debugfs is also enabled and mounted, ``dynamic_debug/control`` is
75 also under the mount-dir, typically ``/sys/kernel/debug/``.
77 Command Language Reference
78 ==========================
80 At the basic lexical level, a command is a sequence of words separated
81 by spaces or tabs. So these are all equivalent::
83 :#> ddcmd file svcsock.c line 1603 +p
84 :#> ddcmd "file svcsock.c line 1603 +p"
85 :#> ddcmd ' file svcsock.c line 1603 +p '
87 Command submissions are bounded by a write() system call.
88 Multiple commands can be written together, separated by ``;`` or ``\n``::
90 :#> ddcmd "func pnpacpi_get_resources +p; func pnp_assign_mem +p"
92 func pnpacpi_get_resources +p
93 func pnp_assign_mem +p
95 :#> cat query-batch-file > /proc/dynamic_debug/control
97 You can also use wildcards in each query term. The match rule supports
98 ``*`` (matches zero or more characters) and ``?`` (matches exactly one
99 character). For example, you can match all usb drivers::
101 :#> ddcmd file "drivers/usb/*" +p # "" to suppress shell expansion
103 Syntactically, a command is pairs of keyword values, followed by a
104 flags change or setting::
106 command ::= match-spec* flags-spec
108 The match-spec's select *prdbgs* from the catalog, upon which to apply
109 the flags-spec, all constraints are ANDed together. An absent keyword
110 is the same as keyword "*".
113 A match specification is a keyword, which selects the attribute of
114 the callsite to be compared, and a value to compare against. Possible
117 match-spec ::= 'func' string |
124 line-range ::= lineno |
129 lineno ::= unsigned-int
133 ``line-range`` cannot contain space, e.g.
134 "1-30" is valid range but "1 - 30" is not.
137 The meanings of each keyword are:
140 The given string is compared against the function name
141 of each callsite. Example::
144 func *recv* # in rfcomm, bluetooth, ping, tcp
147 The given string is compared against either the src-root relative
148 pathname, or the basename of the source file of each callsite.
152 file kernel/freezer.c # ie column 1 of control file
153 file drivers/usb/* # all callsites under it
154 file inode.c:start_* # parse :tail as a func (above)
155 file inode.c:1-100 # parse :tail as a line-range (above)
158 The given string is compared against the module name
159 of each callsite. The module name is the string as
160 seen in ``lsmod``, i.e. without the directory or the ``.ko``
161 suffix and with ``-`` changed to ``_``. Examples::
165 module drm* # both drm, drm_kms_helper
168 The given string is searched for in the dynamic debug format
169 string. Note that the string does not need to match the
170 entire format, only some part. Whitespace and other
171 special characters can be escaped using C octal character
172 escape ``\ooo`` notation, e.g. the space character is ``\040``.
173 Alternatively, the string can be enclosed in double quote
174 characters (``"``) or single quote characters (``'``).
177 format svcrdma: // many of the NFS/RDMA server pr_debugs
178 format readahead // some pr_debugs in the readahead cache
179 format nfsd:\040SETATTR // one way to match a format with whitespace
180 format "nfsd: SETATTR" // a neater way to match a format with whitespace
181 format 'nfsd: SETATTR' // yet another way to match a format with whitespace
184 The given class_name is validated against each module, which may
185 have declared a list of known class_names. If the class_name is
186 found for a module, callsite & class matching and adjustment
189 class DRM_UT_KMS # a DRM.debug category
190 class JUNK # silent non-match
191 // class TLD_* # NOTICE: no wildcard in class names
194 The given line number or range of line numbers is compared
195 against the line number of each ``pr_debug()`` callsite. A single
196 line number matches the callsite line number exactly. A
197 range of line numbers matches any callsite between the first
198 and last line number inclusive. An empty first number means
199 the first line in the file, an empty last line number means the
200 last line number in the file. Examples::
202 line 1603 // exactly line 1603
203 line 1600-1605 // the six lines from line 1600 to line 1605
204 line -1605 // the 1605 lines from line 1 to line 1605
205 line 1600- // all lines from line 1600 to the end of the file
207 The flags specification comprises a change operation followed
208 by one or more flag characters. The change operation is one
211 - remove the given flags
212 + add the given flags
213 = set the flags to the given flags
217 p enables the pr_debug() callsite.
220 Decorator flags add to the message-prefix, in order:
221 t Include thread ID, or <intr>
222 m Include module name
223 f Include the function name
224 s Include the source file name
225 l Include line number
227 For ``print_hex_dump_debug()`` and ``print_hex_dump_bytes()``, only
228 the ``p`` flag has meaning, other flags are ignored.
230 Note the regexp ``^[-+=][fslmpt_]+$`` matches a flags specification.
231 To clear all flags at once, use ``=_`` or ``-fslmpt``.
234 Debug messages during Boot Process
235 ==================================
237 To activate debug messages for core code and built-in modules during
238 the boot process, even before userspace and debugfs exists, use
239 ``dyndbg="QUERY"`` or ``module.dyndbg="QUERY"``. QUERY follows
240 the syntax described above, but must not exceed 1023 characters. Your
241 bootloader may impose lower limits.
243 These ``dyndbg`` params are processed just after the ddebug tables are
244 processed, as part of the early_initcall. Thus you can enable debug
245 messages in all code run after this early_initcall via this boot
248 On an x86 system for example ACPI enablement is a subsys_initcall and::
250 dyndbg="file ec.c +p"
252 will show early Embedded Controller transactions during ACPI setup if
253 your machine (typically a laptop) has an Embedded Controller.
254 PCI (or other devices) initialization also is a hot candidate for using
255 this boot parameter for debugging purposes.
257 If ``foo`` module is not built-in, ``foo.dyndbg`` will still be processed at
258 boot time, without effect, but will be reprocessed when module is
259 loaded later. Bare ``dyndbg=`` is only processed at boot.
262 Debug Messages at Module Initialization Time
263 ============================================
265 When ``modprobe foo`` is called, modprobe scans ``/proc/cmdline`` for
266 ``foo.params``, strips ``foo.``, and passes them to the kernel along with
267 params given in modprobe args or ``/etc/modprobe.d/*.conf`` files,
268 in the following order:
270 1. parameters given via ``/etc/modprobe.d/*.conf``::
272 options foo dyndbg=+pt
273 options foo dyndbg # defaults to +p
275 2. ``foo.dyndbg`` as given in boot args, ``foo.`` is stripped and passed::
277 foo.dyndbg=" func bar +p; func buz +mp"
279 3. args to modprobe::
281 modprobe foo dyndbg==pmf # override previous settings
283 These ``dyndbg`` queries are applied in order, with last having final say.
284 This allows boot args to override or modify those from ``/etc/modprobe.d``
285 (sensible, since 1 is system wide, 2 is kernel or boot specific), and
286 modprobe args to override both.
288 In the ``foo.dyndbg="QUERY"`` form, the query must exclude ``module foo``.
289 ``foo`` is extracted from the param-name, and applied to each query in
290 ``QUERY``, and only 1 match-spec of each type is allowed.
292 The ``dyndbg`` option is a "fake" module parameter, which means:
294 - modules do not need to define it explicitly
295 - every module gets it tacitly, whether they use pr_debug or not
296 - it doesn't appear in ``/sys/module/$module/parameters/``
297 To see it, grep the control file, or inspect ``/proc/cmdline.``
299 For ``CONFIG_DYNAMIC_DEBUG`` kernels, any settings given at boot-time (or
300 enabled by ``-DDEBUG`` flag during compilation) can be disabled later via
301 the debugfs interface if the debug messages are no longer needed::
303 echo "module module_name -p" > /proc/dynamic_debug/control
310 // enable the message at line 1603 of file svcsock.c
311 :#> ddcmd 'file svcsock.c line 1603 +p'
313 // enable all the messages in file svcsock.c
314 :#> ddcmd 'file svcsock.c +p'
316 // enable all the messages in the NFS server module
317 :#> ddcmd 'module nfsd +p'
319 // enable all 12 messages in the function svc_process()
320 :#> ddcmd 'func svc_process +p'
322 // disable all 12 messages in the function svc_process()
323 :#> ddcmd 'func svc_process -p'
325 // enable messages for NFS calls READ, READLINK, READDIR and READDIR+.
326 :#> ddcmd 'format "nfsd: READ" +p'
328 // enable messages in files of which the paths include string "usb"
329 :#> ddcmd 'file *usb* +p'
331 // enable all messages
334 // add module, function to all enabled messages
337 // boot-args example, with newlines and comments for readability
338 Kernel command line: ...
339 // see what's going on in dyndbg=value processing
340 dynamic_debug.verbose=3
341 // enable pr_debugs in the btrfs module (can be builtin or loadable)
343 // enable pr_debugs in all files under init/
344 // and the function parse_one, #cmt is stripped
345 dyndbg="file init/* +p #cmt ; func parse_one +p"
346 // enable pr_debugs in 2 functions in a module loaded later
347 pc87360.dyndbg="func pc87360_init_device +p; func pc87360_find +p"
352 Dynamic Debug is enabled via kernel config items::
354 CONFIG_DYNAMIC_DEBUG=y # build catalog, enables CORE
355 CONFIG_DYNAMIC_DEBUG_CORE=y # enable mechanics only, skip catalog
357 If you do not want to enable dynamic debug globally (i.e. in some embedded
358 system), you may set ``CONFIG_DYNAMIC_DEBUG_CORE`` as basic support of dynamic
359 debug and add ``ccflags := -DDYNAMIC_DEBUG_MODULE`` into the Makefile of any
360 modules which you'd like to dynamically debug later.
366 The following functions are cataloged and controllable when dynamic
371 print_hex_dump_debug()
372 print_hex_dump_bytes()
374 Otherwise, they are off by default; ``ccflags += -DDEBUG`` or
375 ``#define DEBUG`` in a source file will enable them appropriately.
377 If ``CONFIG_DYNAMIC_DEBUG`` is not set, ``print_hex_dump_debug()`` is
378 just a shortcut for ``print_hex_dump(KERN_DEBUG)``.
380 For ``print_hex_dump_debug()``/``print_hex_dump_bytes()``, format string is
381 its ``prefix_str`` argument, if it is constant string; or ``hexdump``
382 in case ``prefix_str`` is built dynamically.