blob: 6e1684981da2ebae47f4d91105fc74819e14ee59 [file] [log] [blame]
Jason Baron86151fd2009-02-05 11:53:15 -05001
2Introduction
3============
4
Jim Cromie29e36c92012-04-27 14:30:41 -06005This document describes how to use the dynamic debug (dyndbg) feature.
Jason Baron86151fd2009-02-05 11:53:15 -05006
Jim Cromie29e36c92012-04-27 14:30:41 -06007Dynamic debug is designed to allow you to dynamically enable/disable
8kernel code to obtain additional kernel information. Currently, if
9CONFIG_DYNAMIC_DEBUG is set, then all pr_debug()/dev_dbg() calls can
10be dynamically enabled per-callsite.
Jason Baron86151fd2009-02-05 11:53:15 -050011
12Dynamic debug has even more useful features:
13
Jim Cromie29e36c92012-04-27 14:30:41 -060014 * Simple query language allows turning on and off debugging
15 statements by matching any combination of 0 or 1 of:
Jason Baron86151fd2009-02-05 11:53:15 -050016
17 - source filename
18 - function name
19 - line number (including ranges of line numbers)
20 - module name
21 - format string
22
Jim Cromie29e36c92012-04-27 14:30:41 -060023 * Provides a debugfs control file: <debugfs>/dynamic_debug/control
24 which can be read to display the complete list of known debug
25 statements, to help guide you
Jason Baron86151fd2009-02-05 11:53:15 -050026
27Controlling dynamic debug Behaviour
Thomas Renningera648ec02010-08-06 16:11:02 +020028===================================
Jason Baron86151fd2009-02-05 11:53:15 -050029
Jonathan Corbet9cad7962011-03-25 10:42:17 -060030The behaviour of pr_debug()/dev_dbg()s are controlled via writing to a
Jim Cromie29e36c92012-04-27 14:30:41 -060031control file in the 'debugfs' filesystem. Thus, you must first mount
32the debugfs filesystem, in order to make use of this feature.
33Subsequently, we refer to the control file as:
34<debugfs>/dynamic_debug/control. For example, if you want to enable
35printing from source file 'svcsock.c', line 1603 you simply do:
Jason Baron86151fd2009-02-05 11:53:15 -050036
37nullarbor:~ # echo 'file svcsock.c line 1603 +p' >
38 <debugfs>/dynamic_debug/control
39
40If you make a mistake with the syntax, the write will fail thus:
41
42nullarbor:~ # echo 'file svcsock.c wtf 1 +p' >
43 <debugfs>/dynamic_debug/control
44-bash: echo: write error: Invalid argument
45
46Viewing Dynamic Debug Behaviour
47===========================
48
Jim Cromie29e36c92012-04-27 14:30:41 -060049You can view the currently configured behaviour of all the debug
50statements via:
Jason Baron86151fd2009-02-05 11:53:15 -050051
52nullarbor:~ # cat <debugfs>/dynamic_debug/control
53# filename:lineno [module]function flags format
Jim Cromie29e36c92012-04-27 14:30:41 -060054/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"
55/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:341 [svcxprt_rdma]svc_rdma_init =_ "\011max_inline : %d\012"
56/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:340 [svcxprt_rdma]svc_rdma_init =_ "\011sq_depth : %d\012"
57/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:338 [svcxprt_rdma]svc_rdma_init =_ "\011max_requests : %d\012"
Jason Baron86151fd2009-02-05 11:53:15 -050058...
59
60
61You can also apply standard Unix text manipulation filters to this
62data, e.g.
63
64nullarbor:~ # grep -i rdma <debugfs>/dynamic_debug/control | wc -l
6562
66
67nullarbor:~ # grep -i tcp <debugfs>/dynamic_debug/control | wc -l
6842
69
Jim Cromie29e36c92012-04-27 14:30:41 -060070The third column shows the currently enabled flags for each debug
71statement callsite (see below for definitions of the flags). The
72default value, with no flags enabled, is "=_". So you can view all
73the debug statement callsites with any non-default flags:
Jason Baron86151fd2009-02-05 11:53:15 -050074
Jim Cromie29e36c92012-04-27 14:30:41 -060075nullarbor:~ # awk '$3 != "=_"' <debugfs>/dynamic_debug/control
Jason Baron86151fd2009-02-05 11:53:15 -050076# filename:lineno [module]function flags format
Greg Banks9898abb2009-02-06 12:54:26 +110077/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"
Jason Baron86151fd2009-02-05 11:53:15 -050078
79
80Command Language Reference
81==========================
82
83At the lexical level, a command comprises a sequence of words separated
Jim Cromie85f7f6c2011-12-19 17:13:21 -050084by spaces or tabs. So these are all equivalent:
Jason Baron86151fd2009-02-05 11:53:15 -050085
86nullarbor:~ # echo -c 'file svcsock.c line 1603 +p' >
87 <debugfs>/dynamic_debug/control
88nullarbor:~ # echo -c ' file svcsock.c line 1603 +p ' >
89 <debugfs>/dynamic_debug/control
Jason Baron86151fd2009-02-05 11:53:15 -050090nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' >
91 <debugfs>/dynamic_debug/control
92
Jim Cromie85f7f6c2011-12-19 17:13:21 -050093Command submissions are bounded by a write() system call.
94Multiple commands can be written together, separated by ';' or '\n'.
Jason Baron86151fd2009-02-05 11:53:15 -050095
Jim Cromie85f7f6c2011-12-19 17:13:21 -050096 ~# echo "func pnpacpi_get_resources +p; func pnp_assign_mem +p" \
97 > <debugfs>/dynamic_debug/control
Jason Baron86151fd2009-02-05 11:53:15 -050098
Jim Cromie85f7f6c2011-12-19 17:13:21 -050099If your query set is big, you can batch them too:
Jason Baron86151fd2009-02-05 11:53:15 -0500100
Jim Cromie85f7f6c2011-12-19 17:13:21 -0500101 ~# cat query-batch-file > <debugfs>/dynamic_debug/control
Jason Baron86151fd2009-02-05 11:53:15 -0500102
103At the syntactical level, a command comprises a sequence of match
104specifications, followed by a flags change specification.
105
106command ::= match-spec* flags-spec
107
Jim Cromie29e36c92012-04-27 14:30:41 -0600108The match-spec's are used to choose a subset of the known pr_debug()
Jason Baron86151fd2009-02-05 11:53:15 -0500109callsites to which to apply the flags-spec. Think of them as a query
110with implicit ANDs between each pair. Note that an empty list of
Jim Cromie29e36c92012-04-27 14:30:41 -0600111match-specs will select all debug statement callsites.
Jason Baron86151fd2009-02-05 11:53:15 -0500112
Jim Cromie29e36c92012-04-27 14:30:41 -0600113A match specification comprises a keyword, which controls the
114attribute of the callsite to be compared, and a value to compare
115against. Possible keywords are:
Jason Baron86151fd2009-02-05 11:53:15 -0500116
117match-spec ::= 'func' string |
118 'file' string |
119 'module' string |
120 'format' string |
121 'line' line-range
122
123line-range ::= lineno |
124 '-'lineno |
125 lineno'-' |
126 lineno'-'lineno
127// Note: line-range cannot contain space, e.g.
128// "1-30" is valid range but "1 - 30" is not.
129
130lineno ::= unsigned-int
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
140file
Jim Cromie2b678312011-12-19 17:13:12 -0500141 The given string is compared against either the full pathname, the
142 src-root relative pathname, or the basename of the source file of
143 each callsite. Examples:
Jason Baron86151fd2009-02-05 11:53:15 -0500144
145 file svcsock.c
Jim Cromie2b678312011-12-19 17:13:12 -0500146 file kernel/freezer.c
Jason Baron86151fd2009-02-05 11:53:15 -0500147 file /usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svcsock.c
148
149module
150 The given string is compared against the module name
151 of each callsite. The module name is the string as
152 seen in "lsmod", i.e. without the directory or the .ko
153 suffix and with '-' changed to '_'. Examples:
154
155 module sunrpc
156 module nfsd
157
158format
159 The given string is searched for in the dynamic debug format
160 string. Note that the string does not need to match the
161 entire format, only some part. Whitespace and other
162 special characters can be escaped using C octal character
163 escape \ooo notation, e.g. the space character is \040.
Greg Banks9898abb2009-02-06 12:54:26 +1100164 Alternatively, the string can be enclosed in double quote
165 characters (") or single quote characters (').
Jason Baron86151fd2009-02-05 11:53:15 -0500166 Examples:
167
Jim Cromie29e36c92012-04-27 14:30:41 -0600168 format svcrdma: // many of the NFS/RDMA server pr_debugs
169 format readahead // some pr_debugs in the readahead cache
Greg Banks9898abb2009-02-06 12:54:26 +1100170 format nfsd:\040SETATTR // one way to match a format with whitespace
171 format "nfsd: SETATTR" // a neater way to match a format with whitespace
172 format 'nfsd: SETATTR' // yet another way to match a format with whitespace
Jason Baron86151fd2009-02-05 11:53:15 -0500173
174line
175 The given line number or range of line numbers is compared
Jim Cromie29e36c92012-04-27 14:30:41 -0600176 against the line number of each pr_debug() callsite. A single
Jason Baron86151fd2009-02-05 11:53:15 -0500177 line number matches the callsite line number exactly. A
178 range of line numbers matches any callsite between the first
179 and last line number inclusive. An empty first number means
180 the first line in the file, an empty line number means the
181 last number in the file. Examples:
182
183 line 1603 // exactly line 1603
184 line 1600-1605 // the six lines from line 1600 to line 1605
185 line -1605 // the 1605 lines from line 1 to line 1605
186 line 1600- // all lines from line 1600 to the end of the file
187
188The flags specification comprises a change operation followed
189by one or more flag characters. The change operation is one
190of the characters:
191
Jim Cromie29e36c92012-04-27 14:30:41 -0600192 - remove the given flags
193 + add the given flags
194 = set the flags to the given flags
Jason Baron86151fd2009-02-05 11:53:15 -0500195
196The flags are:
197
Jim Cromie29e36c92012-04-27 14:30:41 -0600198 p enables the pr_debug() callsite.
199 f Include the function name in the printed message
200 l Include line number in the printed message
201 m Include module name in the printed message
202 t Include thread ID in messages not generated from interrupt context
203 _ No flags are set. (Or'd with others on input)
Jason Baron86151fd2009-02-05 11:53:15 -0500204
Jim Cromie29e36c92012-04-27 14:30:41 -0600205For display, the flags are preceded by '='
206(mnemonic: what the flags are currently equal to).
207
208Note the regexp ^[-+=][flmpt_]+$ matches a flags specification.
209To clear all flags at once, use "=_" or "-flmpt".
Jason Baron86151fd2009-02-05 11:53:15 -0500210
Thomas Renningera648ec02010-08-06 16:11:02 +0200211
Jim Cromie29e36c92012-04-27 14:30:41 -0600212Debug messages during Boot Process
Thomas Renningera648ec02010-08-06 16:11:02 +0200213==================================
214
Jim Cromie29e36c92012-04-27 14:30:41 -0600215To activate debug messages for core code and built-in modules during
216the boot process, even before userspace and debugfs exists, use
217dyndbg="QUERY", module.dyndbg="QUERY", or ddebug_query="QUERY"
218(ddebug_query is obsoleted by dyndbg, and deprecated). QUERY follows
219the syntax described above, but must not exceed 1023 characters. Your
220bootloader may impose lower limits.
Thomas Renningera648ec02010-08-06 16:11:02 +0200221
Jim Cromie29e36c92012-04-27 14:30:41 -0600222These dyndbg params are processed just after the ddebug tables are
223processed, as part of the arch_initcall. Thus you can enable debug
224messages in all code run after this arch_initcall via this boot
225parameter.
226
Thomas Renningera648ec02010-08-06 16:11:02 +0200227On an x86 system for example ACPI enablement is a subsys_initcall and
Jim Cromie29e36c92012-04-27 14:30:41 -0600228 dyndbg="file ec.c +p"
Thomas Renningera648ec02010-08-06 16:11:02 +0200229will show early Embedded Controller transactions during ACPI setup if
230your machine (typically a laptop) has an Embedded Controller.
231PCI (or other devices) initialization also is a hot candidate for using
232this boot parameter for debugging purposes.
233
Jim Cromie29e36c92012-04-27 14:30:41 -0600234If foo module is not built-in, foo.dyndbg will still be processed at
235boot time, without effect, but will be reprocessed when module is
236loaded later. dyndbg_query= and bare dyndbg= are only processed at
237boot.
238
239
240Debug Messages at Module Initialization Time
241============================================
242
243When "modprobe foo" is called, modprobe scans /proc/cmdline for
244foo.params, strips "foo.", and passes them to the kernel along with
245params given in modprobe args or /etc/modprob.d/*.conf files,
246in the following order:
247
2481. # parameters given via /etc/modprobe.d/*.conf
249 options foo dyndbg=+pt
250 options foo dyndbg # defaults to +p
251
2522. # foo.dyndbg as given in boot args, "foo." is stripped and passed
253 foo.dyndbg=" func bar +p; func buz +mp"
254
2553. # args to modprobe
256 modprobe foo dyndbg==pmf # override previous settings
257
258These dyndbg queries are applied in order, with last having final say.
259This allows boot args to override or modify those from /etc/modprobe.d
260(sensible, since 1 is system wide, 2 is kernel or boot specific), and
261modprobe args to override both.
262
263In the foo.dyndbg="QUERY" form, the query must exclude "module foo".
264"foo" is extracted from the param-name, and applied to each query in
265"QUERY", and only 1 match-spec of each type is allowed.
266
267The dyndbg option is a "fake" module parameter, which means:
268
269- modules do not need to define it explicitly
270- every module gets it tacitly, whether they use pr_debug or not
271- it doesnt appear in /sys/module/$module/parameters/
272 To see it, grep the control file, or inspect /proc/cmdline.
273
274For CONFIG_DYNAMIC_DEBUG kernels, any settings given at boot-time (or
275enabled by -DDEBUG flag during compilation) can be disabled later via
276the sysfs interface if the debug messages are no longer needed:
277
278 echo "module module_name -p" > <debugfs>/dynamic_debug/control
Thomas Renningera648ec02010-08-06 16:11:02 +0200279
Jason Baron86151fd2009-02-05 11:53:15 -0500280Examples
281========
282
283// enable the message at line 1603 of file svcsock.c
284nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' >
285 <debugfs>/dynamic_debug/control
286
287// enable all the messages in file svcsock.c
288nullarbor:~ # echo -n 'file svcsock.c +p' >
289 <debugfs>/dynamic_debug/control
290
291// enable all the messages in the NFS server module
292nullarbor:~ # echo -n 'module nfsd +p' >
293 <debugfs>/dynamic_debug/control
294
295// enable all 12 messages in the function svc_process()
296nullarbor:~ # echo -n 'func svc_process +p' >
297 <debugfs>/dynamic_debug/control
298
299// disable all 12 messages in the function svc_process()
300nullarbor:~ # echo -n 'func svc_process -p' >
301 <debugfs>/dynamic_debug/control
Greg Banks9898abb2009-02-06 12:54:26 +1100302
303// enable messages for NFS calls READ, READLINK, READDIR and READDIR+.
304nullarbor:~ # echo -n 'format "nfsd: READ" +p' >
305 <debugfs>/dynamic_debug/control
Jim Cromie29e36c92012-04-27 14:30:41 -0600306
307// enable all messages
308nullarbor:~ # echo -n '+p' > <debugfs>/dynamic_debug/control
309
310// add module, function to all enabled messages
311nullarbor:~ # echo -n '+mf' > <debugfs>/dynamic_debug/control
312
313// boot-args example, with newlines and comments for readability
314Kernel command line: ...
315 // see whats going on in dyndbg=value processing
316 dynamic_debug.verbose=1
317 // enable pr_debugs in 2 builtins, #cmt is stripped
318 dyndbg="module params +p #cmt ; module sys +p"
319 // enable pr_debugs in 2 functions in a module loaded later
320 pc87360.dyndbg="func pc87360_init_device +p; func pc87360_find +p"