8 This document describes how to use the dynamic debug (dyndbg) feature.
10 Dynamic debug is designed to allow you to dynamically enable/disable
11 kernel code to obtain additional kernel information. Currently, if
12 ``CONFIG_DYNAMIC_DEBUG`` is set, then all ``pr_debug()``/``dev_dbg()`` and
13 ``print_hex_dump_debug()``/``print_hex_dump_bytes()`` calls can be dynamically
16 If ``CONFIG_DYNAMIC_DEBUG`` is not set, ``print_hex_dump_debug()`` is just
17 shortcut for ``print_hex_dump(KERN_DEBUG)``.
19 For ``print_hex_dump_debug()``/``print_hex_dump_bytes()``, format string is
20 its ``prefix_str`` argument, if it is constant string; or ``hexdump``
21 in case ``prefix_str`` is built dynamically.
23 Dynamic debug has even more useful features:
25 * Simple query language allows turning on and off debugging
26 statements by matching any combination of 0 or 1 of:
30 - line number (including ranges of line numbers)
34 * Provides a debugfs control file: ``<debugfs>/dynamic_debug/control``
35 which can be read to display the complete list of known debug
36 statements, to help guide you
38 Controlling dynamic debug Behaviour
39 ===================================
41 The behaviour of ``pr_debug()``/``dev_dbg()`` are controlled via writing to a
42 control file in the 'debugfs' filesystem. Thus, you must first mount
43 the debugfs filesystem, in order to make use of this feature.
44 Subsequently, we refer to the control file as:
45 ``<debugfs>/dynamic_debug/control``. For example, if you want to enable
46 printing from source file ``svcsock.c``, line 1603 you simply do::
48 nullarbor:~ # echo 'file svcsock.c line 1603 +p' >
49 <debugfs>/dynamic_debug/control
51 If you make a mistake with the syntax, the write will fail thus::
53 nullarbor:~ # echo 'file svcsock.c wtf 1 +p' >
54 <debugfs>/dynamic_debug/control
55 -bash: echo: write error: Invalid argument
57 Note, for systems without 'debugfs' enabled, the control file can be
58 found in ``/proc/dynamic_debug/control``.
60 Viewing Dynamic Debug Behaviour
61 ===============================
63 You can view the currently configured behaviour of all the debug
66 nullarbor:~ # cat <debugfs>/dynamic_debug/control
67 # filename:lineno [module]function flags format
68 /usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:323 [svcxprt_rdma]svc_rdma_cleanup =_ "SVCRDMA Module Removed, deregister RPC RDMA transport\012"
69 /usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:341 [svcxprt_rdma]svc_rdma_init =_ "\011max_inline : %d\012"
70 /usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:340 [svcxprt_rdma]svc_rdma_init =_ "\011sq_depth : %d\012"
71 /usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:338 [svcxprt_rdma]svc_rdma_init =_ "\011max_requests : %d\012"
75 You can also apply standard Unix text manipulation filters to this
78 nullarbor:~ # grep -i rdma <debugfs>/dynamic_debug/control | wc -l
81 nullarbor:~ # grep -i tcp <debugfs>/dynamic_debug/control | wc -l
84 The third column shows the currently enabled flags for each debug
85 statement callsite (see below for definitions of the flags). The
86 default value, with no flags enabled, is ``=_``. So you can view all
87 the debug statement callsites with any non-default flags::
89 nullarbor:~ # awk '$3 != "=_"' <debugfs>/dynamic_debug/control
90 # filename:lineno [module]function flags format
91 /usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svcsock.c:1603 [sunrpc]svc_send p "svc_process: st_sendto returned %d\012"
93 Command Language Reference
94 ==========================
96 At the lexical level, a command comprises a sequence of words separated
97 by spaces or tabs. So these are all equivalent::
99 nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' >
100 <debugfs>/dynamic_debug/control
101 nullarbor:~ # echo -n ' file svcsock.c line 1603 +p ' >
102 <debugfs>/dynamic_debug/control
103 nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' >
104 <debugfs>/dynamic_debug/control
106 Command submissions are bounded by a write() system call.
107 Multiple commands can be written together, separated by ``;`` or ``\n``::
109 ~# echo "func pnpacpi_get_resources +p; func pnp_assign_mem +p" \
110 > <debugfs>/dynamic_debug/control
112 If your query set is big, you can batch them too::
114 ~# cat query-batch-file > <debugfs>/dynamic_debug/control
116 Another way is to use wildcards. The match rule supports ``*`` (matches
117 zero or more characters) and ``?`` (matches exactly one character). For
118 example, you can match all usb drivers::
120 ~# echo "file drivers/usb/* +p" > <debugfs>/dynamic_debug/control
122 At the syntactical level, a command comprises a sequence of match
123 specifications, followed by a flags change specification::
125 command ::= match-spec* flags-spec
127 The match-spec's are used to choose a subset of the known pr_debug()
128 callsites to which to apply the flags-spec. Think of them as a query
129 with implicit ANDs between each pair. Note that an empty list of
130 match-specs will select all debug statement callsites.
132 A match specification comprises a keyword, which controls the
133 attribute of the callsite to be compared, and a value to compare
134 against. Possible keywords are:::
136 match-spec ::= 'func' string |
142 line-range ::= lineno |
147 lineno ::= unsigned-int
151 ``line-range`` cannot contain space, e.g.
152 "1-30" is valid range but "1 - 30" is not.
155 The meanings of each keyword are:
158 The given string is compared against the function name
159 of each callsite. Example::
164 The given string is compared against either the full pathname, the
165 src-root relative pathname, or the basename of the source file of
166 each callsite. Examples::
169 file kernel/freezer.c
170 file /usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svcsock.c
173 The given string is compared against the module name
174 of each callsite. The module name is the string as
175 seen in ``lsmod``, i.e. without the directory or the ``.ko``
176 suffix and with ``-`` changed to ``_``. Examples::
182 The given string is searched for in the dynamic debug format
183 string. Note that the string does not need to match the
184 entire format, only some part. Whitespace and other
185 special characters can be escaped using C octal character
186 escape ``\ooo`` notation, e.g. the space character is ``\040``.
187 Alternatively, the string can be enclosed in double quote
188 characters (``"``) or single quote characters (``'``).
191 format svcrdma: // many of the NFS/RDMA server pr_debugs
192 format readahead // some pr_debugs in the readahead cache
193 format nfsd:\040SETATTR // one way to match a format with whitespace
194 format "nfsd: SETATTR" // a neater way to match a format with whitespace
195 format 'nfsd: SETATTR' // yet another way to match a format with whitespace
198 The given line number or range of line numbers is compared
199 against the line number of each ``pr_debug()`` callsite. A single
200 line number matches the callsite line number exactly. A
201 range of line numbers matches any callsite between the first
202 and last line number inclusive. An empty first number means
203 the first line in the file, an empty last line number means the
204 last line number in the file. Examples::
206 line 1603 // exactly line 1603
207 line 1600-1605 // the six lines from line 1600 to line 1605
208 line -1605 // the 1605 lines from line 1 to line 1605
209 line 1600- // all lines from line 1600 to the end of the file
211 The flags specification comprises a change operation followed
212 by one or more flag characters. The change operation is one
215 - remove the given flags
216 + add the given flags
217 = set the flags to the given flags
221 p enables the pr_debug() callsite.
222 f Include the function name in the printed message
223 l Include line number in the printed message
224 m Include module name in the printed message
225 t Include thread ID in messages not generated from interrupt context
226 _ No flags are set. (Or'd with others on input)
228 For ``print_hex_dump_debug()`` and ``print_hex_dump_bytes()``, only ``p`` flag
229 have meaning, other flags ignored.
231 For display, the flags are preceded by ``=``
232 (mnemonic: what the flags are currently equal to).
234 Note the regexp ``^[-+=][flmpt_]+$`` matches a flags specification.
235 To clear all flags at once, use ``=_`` or ``-flmpt``.
238 Debug messages during Boot Process
239 ==================================
241 To activate debug messages for core code and built-in modules during
242 the boot process, even before userspace and debugfs exists, use
243 ``dyndbg="QUERY"``, ``module.dyndbg="QUERY"``, or ``ddebug_query="QUERY"``
244 (``ddebug_query`` is obsoleted by ``dyndbg``, and deprecated). QUERY follows
245 the syntax described above, but must not exceed 1023 characters. Your
246 bootloader may impose lower limits.
248 These ``dyndbg`` params are processed just after the ddebug tables are
249 processed, as part of the arch_initcall. Thus you can enable debug
250 messages in all code run after this arch_initcall via this boot
253 On an x86 system for example ACPI enablement is a subsys_initcall and::
255 dyndbg="file ec.c +p"
257 will show early Embedded Controller transactions during ACPI setup if
258 your machine (typically a laptop) has an Embedded Controller.
259 PCI (or other devices) initialization also is a hot candidate for using
260 this boot parameter for debugging purposes.
262 If ``foo`` module is not built-in, ``foo.dyndbg`` will still be processed at
263 boot time, without effect, but will be reprocessed when module is
264 loaded later. ``ddebug_query=`` and bare ``dyndbg=`` are only processed at
268 Debug Messages at Module Initialization Time
269 ============================================
271 When ``modprobe foo`` is called, modprobe scans ``/proc/cmdline`` for
272 ``foo.params``, strips ``foo.``, and passes them to the kernel along with
273 params given in modprobe args or ``/etc/modprob.d/*.conf`` files,
274 in the following order:
276 1. parameters given via ``/etc/modprobe.d/*.conf``::
278 options foo dyndbg=+pt
279 options foo dyndbg # defaults to +p
281 2. ``foo.dyndbg`` as given in boot args, ``foo.`` is stripped and passed::
283 foo.dyndbg=" func bar +p; func buz +mp"
285 3. args to modprobe::
287 modprobe foo dyndbg==pmf # override previous settings
289 These ``dyndbg`` queries are applied in order, with last having final say.
290 This allows boot args to override or modify those from ``/etc/modprobe.d``
291 (sensible, since 1 is system wide, 2 is kernel or boot specific), and
292 modprobe args to override both.
294 In the ``foo.dyndbg="QUERY"`` form, the query must exclude ``module foo``.
295 ``foo`` is extracted from the param-name, and applied to each query in
296 ``QUERY``, and only 1 match-spec of each type is allowed.
298 The ``dyndbg`` option is a "fake" module parameter, which means:
300 - modules do not need to define it explicitly
301 - every module gets it tacitly, whether they use pr_debug or not
302 - it doesn't appear in ``/sys/module/$module/parameters/``
303 To see it, grep the control file, or inspect ``/proc/cmdline.``
305 For ``CONFIG_DYNAMIC_DEBUG`` kernels, any settings given at boot-time (or
306 enabled by ``-DDEBUG`` flag during compilation) can be disabled later via
307 the debugfs interface if the debug messages are no longer needed::
309 echo "module module_name -p" > <debugfs>/dynamic_debug/control
316 // enable the message at line 1603 of file svcsock.c
317 nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' >
318 <debugfs>/dynamic_debug/control
320 // enable all the messages in file svcsock.c
321 nullarbor:~ # echo -n 'file svcsock.c +p' >
322 <debugfs>/dynamic_debug/control
324 // enable all the messages in the NFS server module
325 nullarbor:~ # echo -n 'module nfsd +p' >
326 <debugfs>/dynamic_debug/control
328 // enable all 12 messages in the function svc_process()
329 nullarbor:~ # echo -n 'func svc_process +p' >
330 <debugfs>/dynamic_debug/control
332 // disable all 12 messages in the function svc_process()
333 nullarbor:~ # echo -n 'func svc_process -p' >
334 <debugfs>/dynamic_debug/control
336 // enable messages for NFS calls READ, READLINK, READDIR and READDIR+.
337 nullarbor:~ # echo -n 'format "nfsd: READ" +p' >
338 <debugfs>/dynamic_debug/control
340 // enable messages in files of which the paths include string "usb"
341 nullarbor:~ # echo -n '*usb* +p' > <debugfs>/dynamic_debug/control
343 // enable all messages
344 nullarbor:~ # echo -n '+p' > <debugfs>/dynamic_debug/control
346 // add module, function to all enabled messages
347 nullarbor:~ # echo -n '+mf' > <debugfs>/dynamic_debug/control
349 // boot-args example, with newlines and comments for readability
350 Kernel command line: ...
351 // see whats going on in dyndbg=value processing
352 dynamic_debug.verbose=1
353 // enable pr_debugs in 2 builtins, #cmt is stripped
354 dyndbg="module params +p #cmt ; module sys +p"
355 // enable pr_debugs in 2 functions in a module loaded later
356 pc87360.dyndbg="func pc87360_init_device +p; func pc87360_find +p"