Loading...
1Dynamic debug
2+++++++++++++
3
4
5Introduction
6============
7
8This document describes how to use the dynamic debug (dyndbg) feature.
9
10Dynamic debug is designed to allow you to dynamically enable/disable
11kernel 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
14enabled per-callsite.
15
16If you do not want to enable dynamic debug globally (i.e. in some embedded
17system), you may set ``CONFIG_DYNAMIC_DEBUG_CORE`` as basic support of dynamic
18debug and add ``ccflags := -DDYNAMIC_DEBUG_MODULE`` into the Makefile of any
19modules which you'd like to dynamically debug later.
20
21If ``CONFIG_DYNAMIC_DEBUG`` is not set, ``print_hex_dump_debug()`` is just
22shortcut for ``print_hex_dump(KERN_DEBUG)``.
23
24For ``print_hex_dump_debug()``/``print_hex_dump_bytes()``, format string is
25its ``prefix_str`` argument, if it is constant string; or ``hexdump``
26in case ``prefix_str`` is built dynamically.
27
28Dynamic debug has even more useful features:
29
30 * Simple query language allows turning on and off debugging
31 statements by matching any combination of 0 or 1 of:
32
33 - source filename
34 - function name
35 - line number (including ranges of line numbers)
36 - module name
37 - format string
38
39 * Provides a debugfs control file: ``<debugfs>/dynamic_debug/control``
40 which can be read to display the complete list of known debug
41 statements, to help guide you
42
43Controlling dynamic debug Behaviour
44===================================
45
46The behaviour of ``pr_debug()``/``dev_dbg()`` are controlled via writing to a
47control file in the 'debugfs' filesystem. Thus, you must first mount
48the debugfs filesystem, in order to make use of this feature.
49Subsequently, we refer to the control file as:
50``<debugfs>/dynamic_debug/control``. For example, if you want to enable
51printing from source file ``svcsock.c``, line 1603 you simply do::
52
53 nullarbor:~ # echo 'file svcsock.c line 1603 +p' >
54 <debugfs>/dynamic_debug/control
55
56If you make a mistake with the syntax, the write will fail thus::
57
58 nullarbor:~ # echo 'file svcsock.c wtf 1 +p' >
59 <debugfs>/dynamic_debug/control
60 -bash: echo: write error: Invalid argument
61
62Note, for systems without 'debugfs' enabled, the control file can be
63found in ``/proc/dynamic_debug/control``.
64
65Viewing Dynamic Debug Behaviour
66===============================
67
68You can view the currently configured behaviour of all the debug
69statements via::
70
71 nullarbor:~ # cat <debugfs>/dynamic_debug/control
72 # filename:lineno [module]function flags format
73 net/sunrpc/svc_rdma.c:323 [svcxprt_rdma]svc_rdma_cleanup =_ "SVCRDMA Module Removed, deregister RPC RDMA transport\012"
74 net/sunrpc/svc_rdma.c:341 [svcxprt_rdma]svc_rdma_init =_ "\011max_inline : %d\012"
75 net/sunrpc/svc_rdma.c:340 [svcxprt_rdma]svc_rdma_init =_ "\011sq_depth : %d\012"
76 net/sunrpc/svc_rdma.c:338 [svcxprt_rdma]svc_rdma_init =_ "\011max_requests : %d\012"
77 ...
78
79
80You can also apply standard Unix text manipulation filters to this
81data, e.g.::
82
83 nullarbor:~ # grep -i rdma <debugfs>/dynamic_debug/control | wc -l
84 62
85
86 nullarbor:~ # grep -i tcp <debugfs>/dynamic_debug/control | wc -l
87 42
88
89The third column shows the currently enabled flags for each debug
90statement callsite (see below for definitions of the flags). The
91default value, with no flags enabled, is ``=_``. So you can view all
92the debug statement callsites with any non-default flags::
93
94 nullarbor:~ # awk '$3 != "=_"' <debugfs>/dynamic_debug/control
95 # filename:lineno [module]function flags format
96 net/sunrpc/svcsock.c:1603 [sunrpc]svc_send p "svc_process: st_sendto returned %d\012"
97
98Command Language Reference
99==========================
100
101At the lexical level, a command comprises a sequence of words separated
102by spaces or tabs. So these are all equivalent::
103
104 nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' >
105 <debugfs>/dynamic_debug/control
106 nullarbor:~ # echo -n ' file svcsock.c line 1603 +p ' >
107 <debugfs>/dynamic_debug/control
108 nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' >
109 <debugfs>/dynamic_debug/control
110
111Command submissions are bounded by a write() system call.
112Multiple commands can be written together, separated by ``;`` or ``\n``::
113
114 ~# echo "func pnpacpi_get_resources +p; func pnp_assign_mem +p" \
115 > <debugfs>/dynamic_debug/control
116
117If your query set is big, you can batch them too::
118
119 ~# cat query-batch-file > <debugfs>/dynamic_debug/control
120
121Another way is to use wildcards. The match rule supports ``*`` (matches
122zero or more characters) and ``?`` (matches exactly one character). For
123example, you can match all usb drivers::
124
125 ~# echo "file drivers/usb/* +p" > <debugfs>/dynamic_debug/control
126
127At the syntactical level, a command comprises a sequence of match
128specifications, followed by a flags change specification::
129
130 command ::= match-spec* flags-spec
131
132The match-spec's are used to choose a subset of the known pr_debug()
133callsites to which to apply the flags-spec. Think of them as a query
134with implicit ANDs between each pair. Note that an empty list of
135match-specs will select all debug statement callsites.
136
137A match specification comprises a keyword, which controls the
138attribute of the callsite to be compared, and a value to compare
139against. Possible keywords are:::
140
141 match-spec ::= 'func' string |
142 'file' string |
143 'module' string |
144 'format' string |
145 'line' line-range
146
147 line-range ::= lineno |
148 '-'lineno |
149 lineno'-' |
150 lineno'-'lineno
151
152 lineno ::= unsigned-int
153
154.. note::
155
156 ``line-range`` cannot contain space, e.g.
157 "1-30" is valid range but "1 - 30" is not.
158
159
160The meanings of each keyword are:
161
162func
163 The given string is compared against the function name
164 of each callsite. Example::
165
166 func svc_tcp_accept
167 func *recv* # in rfcomm, bluetooth, ping, tcp
168
169file
170 The given string is compared against either the src-root relative
171 pathname, or the basename of the source file of each callsite.
172 Examples::
173
174 file svcsock.c
175 file kernel/freezer.c # ie column 1 of control file
176 file drivers/usb/* # all callsites under it
177 file inode.c:start_* # parse :tail as a func (above)
178 file inode.c:1-100 # parse :tail as a line-range (above)
179
180module
181 The given string is compared against the module name
182 of each callsite. The module name is the string as
183 seen in ``lsmod``, i.e. without the directory or the ``.ko``
184 suffix and with ``-`` changed to ``_``. Examples::
185
186 module sunrpc
187 module nfsd
188 module drm* # both drm, drm_kms_helper
189
190format
191 The given string is searched for in the dynamic debug format
192 string. Note that the string does not need to match the
193 entire format, only some part. Whitespace and other
194 special characters can be escaped using C octal character
195 escape ``\ooo`` notation, e.g. the space character is ``\040``.
196 Alternatively, the string can be enclosed in double quote
197 characters (``"``) or single quote characters (``'``).
198 Examples::
199
200 format svcrdma: // many of the NFS/RDMA server pr_debugs
201 format readahead // some pr_debugs in the readahead cache
202 format nfsd:\040SETATTR // one way to match a format with whitespace
203 format "nfsd: SETATTR" // a neater way to match a format with whitespace
204 format 'nfsd: SETATTR' // yet another way to match a format with whitespace
205
206line
207 The given line number or range of line numbers is compared
208 against the line number of each ``pr_debug()`` callsite. A single
209 line number matches the callsite line number exactly. A
210 range of line numbers matches any callsite between the first
211 and last line number inclusive. An empty first number means
212 the first line in the file, an empty last line number means the
213 last line number in the file. Examples::
214
215 line 1603 // exactly line 1603
216 line 1600-1605 // the six lines from line 1600 to line 1605
217 line -1605 // the 1605 lines from line 1 to line 1605
218 line 1600- // all lines from line 1600 to the end of the file
219
220The flags specification comprises a change operation followed
221by one or more flag characters. The change operation is one
222of the characters::
223
224 - remove the given flags
225 + add the given flags
226 = set the flags to the given flags
227
228The flags are::
229
230 p enables the pr_debug() callsite.
231 f Include the function name in the printed message
232 l Include line number in the printed message
233 m Include module name in the printed message
234 t Include thread ID in messages not generated from interrupt context
235 _ No flags are set. (Or'd with others on input)
236
237For ``print_hex_dump_debug()`` and ``print_hex_dump_bytes()``, only ``p`` flag
238have meaning, other flags ignored.
239
240For display, the flags are preceded by ``=``
241(mnemonic: what the flags are currently equal to).
242
243Note the regexp ``^[-+=][flmpt_]+$`` matches a flags specification.
244To clear all flags at once, use ``=_`` or ``-flmpt``.
245
246
247Debug messages during Boot Process
248==================================
249
250To activate debug messages for core code and built-in modules during
251the boot process, even before userspace and debugfs exists, use
252``dyndbg="QUERY"``, ``module.dyndbg="QUERY"``, or ``ddebug_query="QUERY"``
253(``ddebug_query`` is obsoleted by ``dyndbg``, and deprecated). QUERY follows
254the syntax described above, but must not exceed 1023 characters. Your
255bootloader may impose lower limits.
256
257These ``dyndbg`` params are processed just after the ddebug tables are
258processed, as part of the early_initcall. Thus you can enable debug
259messages in all code run after this early_initcall via this boot
260parameter.
261
262On an x86 system for example ACPI enablement is a subsys_initcall and::
263
264 dyndbg="file ec.c +p"
265
266will show early Embedded Controller transactions during ACPI setup if
267your machine (typically a laptop) has an Embedded Controller.
268PCI (or other devices) initialization also is a hot candidate for using
269this boot parameter for debugging purposes.
270
271If ``foo`` module is not built-in, ``foo.dyndbg`` will still be processed at
272boot time, without effect, but will be reprocessed when module is
273loaded later. ``ddebug_query=`` and bare ``dyndbg=`` are only processed at
274boot.
275
276
277Debug Messages at Module Initialization Time
278============================================
279
280When ``modprobe foo`` is called, modprobe scans ``/proc/cmdline`` for
281``foo.params``, strips ``foo.``, and passes them to the kernel along with
282params given in modprobe args or ``/etc/modprob.d/*.conf`` files,
283in the following order:
284
2851. parameters given via ``/etc/modprobe.d/*.conf``::
286
287 options foo dyndbg=+pt
288 options foo dyndbg # defaults to +p
289
2902. ``foo.dyndbg`` as given in boot args, ``foo.`` is stripped and passed::
291
292 foo.dyndbg=" func bar +p; func buz +mp"
293
2943. args to modprobe::
295
296 modprobe foo dyndbg==pmf # override previous settings
297
298These ``dyndbg`` queries are applied in order, with last having final say.
299This allows boot args to override or modify those from ``/etc/modprobe.d``
300(sensible, since 1 is system wide, 2 is kernel or boot specific), and
301modprobe args to override both.
302
303In the ``foo.dyndbg="QUERY"`` form, the query must exclude ``module foo``.
304``foo`` is extracted from the param-name, and applied to each query in
305``QUERY``, and only 1 match-spec of each type is allowed.
306
307The ``dyndbg`` option is a "fake" module parameter, which means:
308
309- modules do not need to define it explicitly
310- every module gets it tacitly, whether they use pr_debug or not
311- it doesn't appear in ``/sys/module/$module/parameters/``
312 To see it, grep the control file, or inspect ``/proc/cmdline.``
313
314For ``CONFIG_DYNAMIC_DEBUG`` kernels, any settings given at boot-time (or
315enabled by ``-DDEBUG`` flag during compilation) can be disabled later via
316the debugfs interface if the debug messages are no longer needed::
317
318 echo "module module_name -p" > <debugfs>/dynamic_debug/control
319
320Examples
321========
322
323::
324
325 // enable the message at line 1603 of file svcsock.c
326 nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' >
327 <debugfs>/dynamic_debug/control
328
329 // enable all the messages in file svcsock.c
330 nullarbor:~ # echo -n 'file svcsock.c +p' >
331 <debugfs>/dynamic_debug/control
332
333 // enable all the messages in the NFS server module
334 nullarbor:~ # echo -n 'module nfsd +p' >
335 <debugfs>/dynamic_debug/control
336
337 // enable all 12 messages in the function svc_process()
338 nullarbor:~ # echo -n 'func svc_process +p' >
339 <debugfs>/dynamic_debug/control
340
341 // disable all 12 messages in the function svc_process()
342 nullarbor:~ # echo -n 'func svc_process -p' >
343 <debugfs>/dynamic_debug/control
344
345 // enable messages for NFS calls READ, READLINK, READDIR and READDIR+.
346 nullarbor:~ # echo -n 'format "nfsd: READ" +p' >
347 <debugfs>/dynamic_debug/control
348
349 // enable messages in files of which the paths include string "usb"
350 nullarbor:~ # echo -n '*usb* +p' > <debugfs>/dynamic_debug/control
351
352 // enable all messages
353 nullarbor:~ # echo -n '+p' > <debugfs>/dynamic_debug/control
354
355 // add module, function to all enabled messages
356 nullarbor:~ # echo -n '+mf' > <debugfs>/dynamic_debug/control
357
358 // boot-args example, with newlines and comments for readability
359 Kernel command line: ...
360 // see whats going on in dyndbg=value processing
361 dynamic_debug.verbose=1
362 // enable pr_debugs in 2 builtins, #cmt is stripped
363 dyndbg="module params +p #cmt ; module sys +p"
364 // enable pr_debugs in 2 functions in a module loaded later
365 pc87360.dyndbg="func pc87360_init_device +p; func pc87360_find +p"
1Dynamic debug
2+++++++++++++
3
4
5Introduction
6============
7
8Dynamic debug allows you to dynamically enable/disable kernel
9debug-print code to obtain additional kernel information.
10
11If ``/proc/dynamic_debug/control`` exists, your kernel has dynamic
12debug. You'll need root access (sudo su) to use this.
13
14Dynamic debug provides:
15
16 * a Catalog of all *prdbgs* in your kernel.
17 ``cat /proc/dynamic_debug/control`` to see them.
18
19 * a Simple query/command language to alter *prdbgs* by selecting on
20 any combination of 0 or 1 of:
21
22 - source filename
23 - function name
24 - line number (including ranges of line numbers)
25 - module name
26 - format string
27 - class name (as known/declared by each module)
28
29Viewing Dynamic Debug Behaviour
30===============================
31
32You can view the currently configured behaviour in the *prdbg* catalog::
33
34 :#> head -n7 /proc/dynamic_debug/control
35 # filename:lineno [module]function flags format
36 init/main.c:1179 [main]initcall_blacklist =_ "blacklisting initcall %s\012
37 init/main.c:1218 [main]initcall_blacklisted =_ "initcall %s blacklisted\012"
38 init/main.c:1424 [main]run_init_process =_ " with arguments:\012"
39 init/main.c:1426 [main]run_init_process =_ " %s\012"
40 init/main.c:1427 [main]run_init_process =_ " with environment:\012"
41 init/main.c:1429 [main]run_init_process =_ " %s\012"
42
43The 3rd space-delimited column shows the current flags, preceded by
44a ``=`` for easy use with grep/cut. ``=p`` shows enabled callsites.
45
46Controlling dynamic debug Behaviour
47===================================
48
49The behaviour of *prdbg* sites are controlled by writing
50query/commands to the control file. Example::
51
52 # grease the interface
53 :#> alias ddcmd='echo $* > /proc/dynamic_debug/control'
54
55 :#> ddcmd '-p; module main func run* +p'
56 :#> grep =p /proc/dynamic_debug/control
57 init/main.c:1424 [main]run_init_process =p " with arguments:\012"
58 init/main.c:1426 [main]run_init_process =p " %s\012"
59 init/main.c:1427 [main]run_init_process =p " with environment:\012"
60 init/main.c:1429 [main]run_init_process =p " %s\012"
61
62Error messages go to console/syslog::
63
64 :#> ddcmd mode foo +p
65 dyndbg: unknown keyword "mode"
66 dyndbg: query parse failed
67 bash: echo: write error: Invalid argument
68
69If debugfs is also enabled and mounted, ``dynamic_debug/control`` is
70also under the mount-dir, typically ``/sys/kernel/debug/``.
71
72Command Language Reference
73==========================
74
75At the basic lexical level, a command is a sequence of words separated
76by spaces or tabs. So these are all equivalent::
77
78 :#> ddcmd file svcsock.c line 1603 +p
79 :#> ddcmd "file svcsock.c line 1603 +p"
80 :#> ddcmd ' file svcsock.c line 1603 +p '
81
82Command submissions are bounded by a write() system call.
83Multiple commands can be written together, separated by ``;`` or ``\n``::
84
85 :#> ddcmd "func pnpacpi_get_resources +p; func pnp_assign_mem +p"
86 :#> ddcmd <<"EOC"
87 func pnpacpi_get_resources +p
88 func pnp_assign_mem +p
89 EOC
90 :#> cat query-batch-file > /proc/dynamic_debug/control
91
92You can also use wildcards in each query term. The match rule supports
93``*`` (matches zero or more characters) and ``?`` (matches exactly one
94character). For example, you can match all usb drivers::
95
96 :#> ddcmd file "drivers/usb/*" +p # "" to suppress shell expansion
97
98Syntactically, a command is pairs of keyword values, followed by a
99flags change or setting::
100
101 command ::= match-spec* flags-spec
102
103The match-spec's select *prdbgs* from the catalog, upon which to apply
104the flags-spec, all constraints are ANDed together. An absent keyword
105is the same as keyword "*".
106
107
108A match specification is a keyword, which selects the attribute of
109the callsite to be compared, and a value to compare against. Possible
110keywords are:::
111
112 match-spec ::= 'func' string |
113 'file' string |
114 'module' string |
115 'format' string |
116 'class' string |
117 'line' line-range
118
119 line-range ::= lineno |
120 '-'lineno |
121 lineno'-' |
122 lineno'-'lineno
123
124 lineno ::= unsigned-int
125
126.. note::
127
128 ``line-range`` cannot contain space, e.g.
129 "1-30" is valid range but "1 - 30" is not.
130
131
132The meanings of each keyword are:
133
134func
135 The given string is compared against the function name
136 of each callsite. Example::
137
138 func svc_tcp_accept
139 func *recv* # in rfcomm, bluetooth, ping, tcp
140
141file
142 The given string is compared against either the src-root relative
143 pathname, or the basename of the source file of each callsite.
144 Examples::
145
146 file svcsock.c
147 file kernel/freezer.c # ie column 1 of control file
148 file drivers/usb/* # all callsites under it
149 file inode.c:start_* # parse :tail as a func (above)
150 file inode.c:1-100 # parse :tail as a line-range (above)
151
152module
153 The given string is compared against the module name
154 of each callsite. The module name is the string as
155 seen in ``lsmod``, i.e. without the directory or the ``.ko``
156 suffix and with ``-`` changed to ``_``. Examples::
157
158 module sunrpc
159 module nfsd
160 module drm* # both drm, drm_kms_helper
161
162format
163 The given string is searched for in the dynamic debug format
164 string. Note that the string does not need to match the
165 entire format, only some part. Whitespace and other
166 special characters can be escaped using C octal character
167 escape ``\ooo`` notation, e.g. the space character is ``\040``.
168 Alternatively, the string can be enclosed in double quote
169 characters (``"``) or single quote characters (``'``).
170 Examples::
171
172 format svcrdma: // many of the NFS/RDMA server pr_debugs
173 format readahead // some pr_debugs in the readahead cache
174 format nfsd:\040SETATTR // one way to match a format with whitespace
175 format "nfsd: SETATTR" // a neater way to match a format with whitespace
176 format 'nfsd: SETATTR' // yet another way to match a format with whitespace
177
178class
179 The given class_name is validated against each module, which may
180 have declared a list of known class_names. If the class_name is
181 found for a module, callsite & class matching and adjustment
182 proceeds. Examples::
183
184 class DRM_UT_KMS # a DRM.debug category
185 class JUNK # silent non-match
186 // class TLD_* # NOTICE: no wildcard in class names
187
188line
189 The given line number or range of line numbers is compared
190 against the line number of each ``pr_debug()`` callsite. A single
191 line number matches the callsite line number exactly. A
192 range of line numbers matches any callsite between the first
193 and last line number inclusive. An empty first number means
194 the first line in the file, an empty last line number means the
195 last line number in the file. Examples::
196
197 line 1603 // exactly line 1603
198 line 1600-1605 // the six lines from line 1600 to line 1605
199 line -1605 // the 1605 lines from line 1 to line 1605
200 line 1600- // all lines from line 1600 to the end of the file
201
202The flags specification comprises a change operation followed
203by one or more flag characters. The change operation is one
204of the characters::
205
206 - remove the given flags
207 + add the given flags
208 = set the flags to the given flags
209
210The flags are::
211
212 p enables the pr_debug() callsite.
213 _ enables no flags.
214
215 Decorator flags add to the message-prefix, in order:
216 t Include thread ID, or <intr>
217 m Include module name
218 f Include the function name
219 l Include line number
220
221For ``print_hex_dump_debug()`` and ``print_hex_dump_bytes()``, only
222the ``p`` flag has meaning, other flags are ignored.
223
224Note the regexp ``^[-+=][flmpt_]+$`` matches a flags specification.
225To clear all flags at once, use ``=_`` or ``-flmpt``.
226
227
228Debug messages during Boot Process
229==================================
230
231To activate debug messages for core code and built-in modules during
232the boot process, even before userspace and debugfs exists, use
233``dyndbg="QUERY"`` or ``module.dyndbg="QUERY"``. QUERY follows
234the syntax described above, but must not exceed 1023 characters. Your
235bootloader may impose lower limits.
236
237These ``dyndbg`` params are processed just after the ddebug tables are
238processed, as part of the early_initcall. Thus you can enable debug
239messages in all code run after this early_initcall via this boot
240parameter.
241
242On an x86 system for example ACPI enablement is a subsys_initcall and::
243
244 dyndbg="file ec.c +p"
245
246will show early Embedded Controller transactions during ACPI setup if
247your machine (typically a laptop) has an Embedded Controller.
248PCI (or other devices) initialization also is a hot candidate for using
249this boot parameter for debugging purposes.
250
251If ``foo`` module is not built-in, ``foo.dyndbg`` will still be processed at
252boot time, without effect, but will be reprocessed when module is
253loaded later. Bare ``dyndbg=`` is only processed at boot.
254
255
256Debug Messages at Module Initialization Time
257============================================
258
259When ``modprobe foo`` is called, modprobe scans ``/proc/cmdline`` for
260``foo.params``, strips ``foo.``, and passes them to the kernel along with
261params given in modprobe args or ``/etc/modprob.d/*.conf`` files,
262in the following order:
263
2641. parameters given via ``/etc/modprobe.d/*.conf``::
265
266 options foo dyndbg=+pt
267 options foo dyndbg # defaults to +p
268
2692. ``foo.dyndbg`` as given in boot args, ``foo.`` is stripped and passed::
270
271 foo.dyndbg=" func bar +p; func buz +mp"
272
2733. args to modprobe::
274
275 modprobe foo dyndbg==pmf # override previous settings
276
277These ``dyndbg`` queries are applied in order, with last having final say.
278This allows boot args to override or modify those from ``/etc/modprobe.d``
279(sensible, since 1 is system wide, 2 is kernel or boot specific), and
280modprobe args to override both.
281
282In the ``foo.dyndbg="QUERY"`` form, the query must exclude ``module foo``.
283``foo`` is extracted from the param-name, and applied to each query in
284``QUERY``, and only 1 match-spec of each type is allowed.
285
286The ``dyndbg`` option is a "fake" module parameter, which means:
287
288- modules do not need to define it explicitly
289- every module gets it tacitly, whether they use pr_debug or not
290- it doesn't appear in ``/sys/module/$module/parameters/``
291 To see it, grep the control file, or inspect ``/proc/cmdline.``
292
293For ``CONFIG_DYNAMIC_DEBUG`` kernels, any settings given at boot-time (or
294enabled by ``-DDEBUG`` flag during compilation) can be disabled later via
295the debugfs interface if the debug messages are no longer needed::
296
297 echo "module module_name -p" > /proc/dynamic_debug/control
298
299Examples
300========
301
302::
303
304 // enable the message at line 1603 of file svcsock.c
305 :#> ddcmd 'file svcsock.c line 1603 +p'
306
307 // enable all the messages in file svcsock.c
308 :#> ddcmd 'file svcsock.c +p'
309
310 // enable all the messages in the NFS server module
311 :#> ddcmd 'module nfsd +p'
312
313 // enable all 12 messages in the function svc_process()
314 :#> ddcmd 'func svc_process +p'
315
316 // disable all 12 messages in the function svc_process()
317 :#> ddcmd 'func svc_process -p'
318
319 // enable messages for NFS calls READ, READLINK, READDIR and READDIR+.
320 :#> ddcmd 'format "nfsd: READ" +p'
321
322 // enable messages in files of which the paths include string "usb"
323 :#> ddcmd 'file *usb* +p' > /proc/dynamic_debug/control
324
325 // enable all messages
326 :#> ddcmd '+p' > /proc/dynamic_debug/control
327
328 // add module, function to all enabled messages
329 :#> ddcmd '+mf' > /proc/dynamic_debug/control
330
331 // boot-args example, with newlines and comments for readability
332 Kernel command line: ...
333 // see whats going on in dyndbg=value processing
334 dynamic_debug.verbose=3
335 // enable pr_debugs in the btrfs module (can be builtin or loadable)
336 btrfs.dyndbg="+p"
337 // enable pr_debugs in all files under init/
338 // and the function parse_one, #cmt is stripped
339 dyndbg="file init/* +p #cmt ; func parse_one +p"
340 // enable pr_debugs in 2 functions in a module loaded later
341 pc87360.dyndbg="func pc87360_init_device +p; func pc87360_find +p"
342
343Kernel Configuration
344====================
345
346Dynamic Debug is enabled via kernel config items::
347
348 CONFIG_DYNAMIC_DEBUG=y # build catalog, enables CORE
349 CONFIG_DYNAMIC_DEBUG_CORE=y # enable mechanics only, skip catalog
350
351If you do not want to enable dynamic debug globally (i.e. in some embedded
352system), you may set ``CONFIG_DYNAMIC_DEBUG_CORE`` as basic support of dynamic
353debug and add ``ccflags := -DDYNAMIC_DEBUG_MODULE`` into the Makefile of any
354modules which you'd like to dynamically debug later.
355
356
357Kernel *prdbg* API
358==================
359
360The following functions are cataloged and controllable when dynamic
361debug is enabled::
362
363 pr_debug()
364 dev_dbg()
365 print_hex_dump_debug()
366 print_hex_dump_bytes()
367
368Otherwise, they are off by default; ``ccflags += -DDEBUG`` or
369``#define DEBUG`` in a source file will enable them appropriately.
370
371If ``CONFIG_DYNAMIC_DEBUG`` is not set, ``print_hex_dump_debug()`` is
372just a shortcut for ``print_hex_dump(KERN_DEBUG)``.
373
374For ``print_hex_dump_debug()``/``print_hex_dump_bytes()``, format string is
375its ``prefix_str`` argument, if it is constant string; or ``hexdump``
376in case ``prefix_str`` is built dynamically.