xref: /linux/Documentation/admin-guide/dynamic-debug-howto.rst (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
19d85025bSMauro Carvalho ChehabDynamic debug
29d85025bSMauro Carvalho Chehab+++++++++++++
39d85025bSMauro Carvalho Chehab
49d85025bSMauro Carvalho Chehab
59d85025bSMauro Carvalho ChehabIntroduction
69d85025bSMauro Carvalho Chehab============
79d85025bSMauro Carvalho Chehab
8ace7c4bbSJim CromieDynamic debug allows you to dynamically enable/disable kernel
9ace7c4bbSJim Cromiedebug-print code to obtain additional kernel information.
109d85025bSMauro Carvalho Chehab
11ace7c4bbSJim CromieIf ``/proc/dynamic_debug/control`` exists, your kernel has dynamic
12ace7c4bbSJim Cromiedebug.  You'll need root access (sudo su) to use this.
139d85025bSMauro Carvalho Chehab
14ace7c4bbSJim CromieDynamic debug provides:
15ceabef7dSOrson Zhai
16ace7c4bbSJim Cromie * a Catalog of all *prdbgs* in your kernel.
17ace7c4bbSJim Cromie   ``cat /proc/dynamic_debug/control`` to see them.
189d85025bSMauro Carvalho Chehab
19ace7c4bbSJim Cromie * a Simple query/command language to alter *prdbgs* by selecting on
20ace7c4bbSJim Cromie   any combination of 0 or 1 of:
219d85025bSMauro Carvalho Chehab
229d85025bSMauro Carvalho Chehab   - source filename
239d85025bSMauro Carvalho Chehab   - function name
249d85025bSMauro Carvalho Chehab   - line number (including ranges of line numbers)
259d85025bSMauro Carvalho Chehab   - module name
269d85025bSMauro Carvalho Chehab   - format string
27753914edSJim Cromie   - class name (as known/declared by each module)
289d85025bSMauro Carvalho Chehab
29*9784f29bSDaniel LublinNOTE: To actually get the debug-print output on the console, you may
30*9784f29bSDaniel Lublinneed to adjust the kernel ``loglevel=``, or use ``ignore_loglevel``.
31*9784f29bSDaniel LublinRead about these kernel parameters in
32*9784f29bSDaniel LublinDocumentation/admin-guide/kernel-parameters.rst.
33*9784f29bSDaniel Lublin
34ace7c4bbSJim CromieViewing Dynamic Debug Behaviour
35ace7c4bbSJim Cromie===============================
36ace7c4bbSJim Cromie
37ace7c4bbSJim CromieYou can view the currently configured behaviour in the *prdbg* catalog::
38ace7c4bbSJim Cromie
39ace7c4bbSJim Cromie  :#> head -n7 /proc/dynamic_debug/control
40ace7c4bbSJim Cromie  # filename:lineno [module]function flags format
41ace7c4bbSJim Cromie  init/main.c:1179 [main]initcall_blacklist =_ "blacklisting initcall %s\012
42ace7c4bbSJim Cromie  init/main.c:1218 [main]initcall_blacklisted =_ "initcall %s blacklisted\012"
43ace7c4bbSJim Cromie  init/main.c:1424 [main]run_init_process =_ "  with arguments:\012"
44ace7c4bbSJim Cromie  init/main.c:1426 [main]run_init_process =_ "    %s\012"
45ace7c4bbSJim Cromie  init/main.c:1427 [main]run_init_process =_ "  with environment:\012"
46ace7c4bbSJim Cromie  init/main.c:1429 [main]run_init_process =_ "    %s\012"
47ace7c4bbSJim Cromie
48ace7c4bbSJim CromieThe 3rd space-delimited column shows the current flags, preceded by
49ace7c4bbSJim Cromiea ``=`` for easy use with grep/cut. ``=p`` shows enabled callsites.
509d85025bSMauro Carvalho Chehab
519d85025bSMauro Carvalho ChehabControlling dynamic debug Behaviour
529d85025bSMauro Carvalho Chehab===================================
539d85025bSMauro Carvalho Chehab
54ace7c4bbSJim CromieThe behaviour of *prdbg* sites are controlled by writing
55ace7c4bbSJim Cromiequery/commands to the control file.  Example::
569d85025bSMauro Carvalho Chehab
57ace7c4bbSJim Cromie  # grease the interface
58ace7c4bbSJim Cromie  :#> alias ddcmd='echo $* > /proc/dynamic_debug/control'
599d85025bSMauro Carvalho Chehab
60ace7c4bbSJim Cromie  :#> ddcmd '-p; module main func run* +p'
61ace7c4bbSJim Cromie  :#> grep =p /proc/dynamic_debug/control
62ace7c4bbSJim Cromie  init/main.c:1424 [main]run_init_process =p "  with arguments:\012"
63ace7c4bbSJim Cromie  init/main.c:1426 [main]run_init_process =p "    %s\012"
64ace7c4bbSJim Cromie  init/main.c:1427 [main]run_init_process =p "  with environment:\012"
65ace7c4bbSJim Cromie  init/main.c:1429 [main]run_init_process =p "    %s\012"
669d85025bSMauro Carvalho Chehab
67ace7c4bbSJim CromieError messages go to console/syslog::
689d85025bSMauro Carvalho Chehab
69ace7c4bbSJim Cromie  :#> ddcmd mode foo +p
70ace7c4bbSJim Cromie  dyndbg: unknown keyword "mode"
71ace7c4bbSJim Cromie  dyndbg: query parse failed
72ace7c4bbSJim Cromie  bash: echo: write error: Invalid argument
73239a5791SGreg Kroah-Hartman
74ace7c4bbSJim CromieIf debugfs is also enabled and mounted, ``dynamic_debug/control`` is
75ace7c4bbSJim Cromiealso under the mount-dir, typically ``/sys/kernel/debug/``.
769d85025bSMauro Carvalho Chehab
779d85025bSMauro Carvalho ChehabCommand Language Reference
789d85025bSMauro Carvalho Chehab==========================
799d85025bSMauro Carvalho Chehab
80ace7c4bbSJim CromieAt the basic lexical level, a command is a sequence of words separated
819d85025bSMauro Carvalho Chehabby spaces or tabs.  So these are all equivalent::
829d85025bSMauro Carvalho Chehab
83ace7c4bbSJim Cromie  :#> ddcmd file svcsock.c line 1603 +p
84ace7c4bbSJim Cromie  :#> ddcmd "file svcsock.c line 1603 +p"
85ace7c4bbSJim Cromie  :#> ddcmd '  file   svcsock.c     line  1603 +p  '
869d85025bSMauro Carvalho Chehab
879d85025bSMauro Carvalho ChehabCommand submissions are bounded by a write() system call.
889d85025bSMauro Carvalho ChehabMultiple commands can be written together, separated by ``;`` or ``\n``::
899d85025bSMauro Carvalho Chehab
90ace7c4bbSJim Cromie  :#> ddcmd "func pnpacpi_get_resources +p; func pnp_assign_mem +p"
91ace7c4bbSJim Cromie  :#> ddcmd <<"EOC"
92ace7c4bbSJim Cromie  func pnpacpi_get_resources +p
93ace7c4bbSJim Cromie  func pnp_assign_mem +p
94ace7c4bbSJim Cromie  EOC
95ace7c4bbSJim Cromie  :#> cat query-batch-file > /proc/dynamic_debug/control
969d85025bSMauro Carvalho Chehab
97ace7c4bbSJim CromieYou can also use wildcards in each query term. The match rule supports
98ace7c4bbSJim Cromie``*`` (matches zero or more characters) and ``?`` (matches exactly one
99ace7c4bbSJim Cromiecharacter). For example, you can match all usb drivers::
1009d85025bSMauro Carvalho Chehab
101ace7c4bbSJim Cromie  :#> ddcmd file "drivers/usb/*" +p	# "" to suppress shell expansion
1029d85025bSMauro Carvalho Chehab
103ace7c4bbSJim CromieSyntactically, a command is pairs of keyword values, followed by a
104ace7c4bbSJim Cromieflags change or setting::
1059d85025bSMauro Carvalho Chehab
1069d85025bSMauro Carvalho Chehab  command ::= match-spec* flags-spec
1079d85025bSMauro Carvalho Chehab
108ace7c4bbSJim CromieThe match-spec's select *prdbgs* from the catalog, upon which to apply
109ace7c4bbSJim Cromiethe flags-spec, all constraints are ANDed together.  An absent keyword
110ace7c4bbSJim Cromieis the same as keyword "*".
1119d85025bSMauro Carvalho Chehab
112ace7c4bbSJim Cromie
113ace7c4bbSJim CromieA match specification is a keyword, which selects the attribute of
114ace7c4bbSJim Cromiethe callsite to be compared, and a value to compare against.  Possible
115ace7c4bbSJim Cromiekeywords are:::
1169d85025bSMauro Carvalho Chehab
1179d85025bSMauro Carvalho Chehab  match-spec ::= 'func' string |
1189d85025bSMauro Carvalho Chehab		 'file' string |
1199d85025bSMauro Carvalho Chehab		 'module' string |
1209d85025bSMauro Carvalho Chehab		 'format' string |
121753914edSJim Cromie		 'class' string |
1229d85025bSMauro Carvalho Chehab		 'line' line-range
1239d85025bSMauro Carvalho Chehab
1249d85025bSMauro Carvalho Chehab  line-range ::= lineno |
1259d85025bSMauro Carvalho Chehab		 '-'lineno |
1269d85025bSMauro Carvalho Chehab		 lineno'-' |
1279d85025bSMauro Carvalho Chehab		 lineno'-'lineno
1289d85025bSMauro Carvalho Chehab
1299d85025bSMauro Carvalho Chehab  lineno ::= unsigned-int
1309d85025bSMauro Carvalho Chehab
1319d85025bSMauro Carvalho Chehab.. note::
1329d85025bSMauro Carvalho Chehab
1339d85025bSMauro Carvalho Chehab  ``line-range`` cannot contain space, e.g.
1349d85025bSMauro Carvalho Chehab  "1-30" is valid range but "1 - 30" is not.
1359d85025bSMauro Carvalho Chehab
1369d85025bSMauro Carvalho Chehab
1379d85025bSMauro Carvalho ChehabThe meanings of each keyword are:
1389d85025bSMauro Carvalho Chehab
1399d85025bSMauro Carvalho Chehabfunc
1409d85025bSMauro Carvalho Chehab    The given string is compared against the function name
1419d85025bSMauro Carvalho Chehab    of each callsite.  Example::
1429d85025bSMauro Carvalho Chehab
1439d85025bSMauro Carvalho Chehab	func svc_tcp_accept
144aaebe329SJim Cromie	func *recv*		# in rfcomm, bluetooth, ping, tcp
1459d85025bSMauro Carvalho Chehab
1469d85025bSMauro Carvalho Chehabfile
147e20e310cSJim Cromie    The given string is compared against either the src-root relative
148e20e310cSJim Cromie    pathname, or the basename of the source file of each callsite.
149e20e310cSJim Cromie    Examples::
1509d85025bSMauro Carvalho Chehab
1519d85025bSMauro Carvalho Chehab	file svcsock.c
152e20e310cSJim Cromie	file kernel/freezer.c	# ie column 1 of control file
153aaebe329SJim Cromie	file drivers/usb/*	# all callsites under it
154aaebe329SJim Cromie	file inode.c:start_*	# parse :tail as a func (above)
155aaebe329SJim Cromie	file inode.c:1-100	# parse :tail as a line-range (above)
1569d85025bSMauro Carvalho Chehab
1579d85025bSMauro Carvalho Chehabmodule
1589d85025bSMauro Carvalho Chehab    The given string is compared against the module name
1599d85025bSMauro Carvalho Chehab    of each callsite.  The module name is the string as
1609d85025bSMauro Carvalho Chehab    seen in ``lsmod``, i.e. without the directory or the ``.ko``
1619d85025bSMauro Carvalho Chehab    suffix and with ``-`` changed to ``_``.  Examples::
1629d85025bSMauro Carvalho Chehab
1639d85025bSMauro Carvalho Chehab	module sunrpc
1649d85025bSMauro Carvalho Chehab	module nfsd
165aaebe329SJim Cromie	module drm*	# both drm, drm_kms_helper
1669d85025bSMauro Carvalho Chehab
1679d85025bSMauro Carvalho Chehabformat
1689d85025bSMauro Carvalho Chehab    The given string is searched for in the dynamic debug format
1699d85025bSMauro Carvalho Chehab    string.  Note that the string does not need to match the
1709d85025bSMauro Carvalho Chehab    entire format, only some part.  Whitespace and other
1719d85025bSMauro Carvalho Chehab    special characters can be escaped using C octal character
1729d85025bSMauro Carvalho Chehab    escape ``\ooo`` notation, e.g. the space character is ``\040``.
1739d85025bSMauro Carvalho Chehab    Alternatively, the string can be enclosed in double quote
1749d85025bSMauro Carvalho Chehab    characters (``"``) or single quote characters (``'``).
1759d85025bSMauro Carvalho Chehab    Examples::
1769d85025bSMauro Carvalho Chehab
1779d85025bSMauro Carvalho Chehab	format svcrdma:         // many of the NFS/RDMA server pr_debugs
1789d85025bSMauro Carvalho Chehab	format readahead        // some pr_debugs in the readahead cache
1799d85025bSMauro Carvalho Chehab	format nfsd:\040SETATTR // one way to match a format with whitespace
1809d85025bSMauro Carvalho Chehab	format "nfsd: SETATTR"  // a neater way to match a format with whitespace
1819d85025bSMauro Carvalho Chehab	format 'nfsd: SETATTR'  // yet another way to match a format with whitespace
1829d85025bSMauro Carvalho Chehab
183753914edSJim Cromieclass
184753914edSJim Cromie    The given class_name is validated against each module, which may
185753914edSJim Cromie    have declared a list of known class_names.  If the class_name is
186753914edSJim Cromie    found for a module, callsite & class matching and adjustment
187753914edSJim Cromie    proceeds.  Examples::
188753914edSJim Cromie
189753914edSJim Cromie	class DRM_UT_KMS	# a DRM.debug category
190753914edSJim Cromie	class JUNK		# silent non-match
191ace7c4bbSJim Cromie	// class TLD_*		# NOTICE: no wildcard in class names
192753914edSJim Cromie
1939d85025bSMauro Carvalho Chehabline
1949d85025bSMauro Carvalho Chehab    The given line number or range of line numbers is compared
1959d85025bSMauro Carvalho Chehab    against the line number of each ``pr_debug()`` callsite.  A single
1969d85025bSMauro Carvalho Chehab    line number matches the callsite line number exactly.  A
1979d85025bSMauro Carvalho Chehab    range of line numbers matches any callsite between the first
1989d85025bSMauro Carvalho Chehab    and last line number inclusive.  An empty first number means
1998c188759SRandy Dunlap    the first line in the file, an empty last line number means the
2008c188759SRandy Dunlap    last line number in the file.  Examples::
2019d85025bSMauro Carvalho Chehab
2029d85025bSMauro Carvalho Chehab	line 1603           // exactly line 1603
2039d85025bSMauro Carvalho Chehab	line 1600-1605      // the six lines from line 1600 to line 1605
2049d85025bSMauro Carvalho Chehab	line -1605          // the 1605 lines from line 1 to line 1605
2059d85025bSMauro Carvalho Chehab	line 1600-          // all lines from line 1600 to the end of the file
2069d85025bSMauro Carvalho Chehab
2079d85025bSMauro Carvalho ChehabThe flags specification comprises a change operation followed
2089d85025bSMauro Carvalho Chehabby one or more flag characters.  The change operation is one
2099d85025bSMauro Carvalho Chehabof the characters::
2109d85025bSMauro Carvalho Chehab
2119d85025bSMauro Carvalho Chehab  -    remove the given flags
2129d85025bSMauro Carvalho Chehab  +    add the given flags
2139d85025bSMauro Carvalho Chehab  =    set the flags to the given flags
2149d85025bSMauro Carvalho Chehab
2159d85025bSMauro Carvalho ChehabThe flags are::
2169d85025bSMauro Carvalho Chehab
2179d85025bSMauro Carvalho Chehab  p    enables the pr_debug() callsite.
218ace7c4bbSJim Cromie  _    enables no flags.
2199d85025bSMauro Carvalho Chehab
220ace7c4bbSJim Cromie  Decorator flags add to the message-prefix, in order:
221ace7c4bbSJim Cromie  t    Include thread ID, or <intr>
222ace7c4bbSJim Cromie  m    Include module name
223ace7c4bbSJim Cromie  f    Include the function name
22431ed379bSThomas Weißschuh  s    Include the source file name
225ace7c4bbSJim Cromie  l    Include line number
2269d85025bSMauro Carvalho Chehab
227ace7c4bbSJim CromieFor ``print_hex_dump_debug()`` and ``print_hex_dump_bytes()``, only
228ace7c4bbSJim Cromiethe ``p`` flag has meaning, other flags are ignored.
2299d85025bSMauro Carvalho Chehab
23031ed379bSThomas WeißschuhNote the regexp ``^[-+=][fslmpt_]+$`` matches a flags specification.
23131ed379bSThomas WeißschuhTo clear all flags at once, use ``=_`` or ``-fslmpt``.
2329d85025bSMauro Carvalho Chehab
2339d85025bSMauro Carvalho Chehab
2349d85025bSMauro Carvalho ChehabDebug messages during Boot Process
2359d85025bSMauro Carvalho Chehab==================================
2369d85025bSMauro Carvalho Chehab
2379d85025bSMauro Carvalho ChehabTo activate debug messages for core code and built-in modules during
2389d85025bSMauro Carvalho Chehabthe boot process, even before userspace and debugfs exists, use
2399c40e1aaSAndrew Halaney``dyndbg="QUERY"`` or ``module.dyndbg="QUERY"``.  QUERY follows
2409d85025bSMauro Carvalho Chehabthe syntax described above, but must not exceed 1023 characters.  Your
2419d85025bSMauro Carvalho Chehabbootloader may impose lower limits.
2429d85025bSMauro Carvalho Chehab
2439d85025bSMauro Carvalho ChehabThese ``dyndbg`` params are processed just after the ddebug tables are
244fa080520SJim Cromieprocessed, as part of the early_initcall.  Thus you can enable debug
245fa080520SJim Cromiemessages in all code run after this early_initcall via this boot
2469d85025bSMauro Carvalho Chehabparameter.
2479d85025bSMauro Carvalho Chehab
2489d85025bSMauro Carvalho ChehabOn an x86 system for example ACPI enablement is a subsys_initcall and::
2499d85025bSMauro Carvalho Chehab
2509d85025bSMauro Carvalho Chehab   dyndbg="file ec.c +p"
2519d85025bSMauro Carvalho Chehab
2529d85025bSMauro Carvalho Chehabwill show early Embedded Controller transactions during ACPI setup if
2539d85025bSMauro Carvalho Chehabyour machine (typically a laptop) has an Embedded Controller.
2549d85025bSMauro Carvalho ChehabPCI (or other devices) initialization also is a hot candidate for using
2559d85025bSMauro Carvalho Chehabthis boot parameter for debugging purposes.
2569d85025bSMauro Carvalho Chehab
2579d85025bSMauro Carvalho ChehabIf ``foo`` module is not built-in, ``foo.dyndbg`` will still be processed at
2589d85025bSMauro Carvalho Chehabboot time, without effect, but will be reprocessed when module is
2599c40e1aaSAndrew Halaneyloaded later. Bare ``dyndbg=`` is only processed at boot.
2609d85025bSMauro Carvalho Chehab
2619d85025bSMauro Carvalho Chehab
2629d85025bSMauro Carvalho ChehabDebug Messages at Module Initialization Time
2639d85025bSMauro Carvalho Chehab============================================
2649d85025bSMauro Carvalho Chehab
2659d85025bSMauro Carvalho ChehabWhen ``modprobe foo`` is called, modprobe scans ``/proc/cmdline`` for
2669d85025bSMauro Carvalho Chehab``foo.params``, strips ``foo.``, and passes them to the kernel along with
267a10874e8SJade Lovelaceparams given in modprobe args or ``/etc/modprobe.d/*.conf`` files,
2689d85025bSMauro Carvalho Chehabin the following order:
2699d85025bSMauro Carvalho Chehab
2709d85025bSMauro Carvalho Chehab1. parameters given via ``/etc/modprobe.d/*.conf``::
2719d85025bSMauro Carvalho Chehab
2729d85025bSMauro Carvalho Chehab	options foo dyndbg=+pt
2739d85025bSMauro Carvalho Chehab	options foo dyndbg # defaults to +p
2749d85025bSMauro Carvalho Chehab
2759d85025bSMauro Carvalho Chehab2. ``foo.dyndbg`` as given in boot args, ``foo.`` is stripped and passed::
2769d85025bSMauro Carvalho Chehab
2779d85025bSMauro Carvalho Chehab	foo.dyndbg=" func bar +p; func buz +mp"
2789d85025bSMauro Carvalho Chehab
2799d85025bSMauro Carvalho Chehab3. args to modprobe::
2809d85025bSMauro Carvalho Chehab
2819d85025bSMauro Carvalho Chehab	modprobe foo dyndbg==pmf # override previous settings
2829d85025bSMauro Carvalho Chehab
2839d85025bSMauro Carvalho ChehabThese ``dyndbg`` queries are applied in order, with last having final say.
2849d85025bSMauro Carvalho ChehabThis allows boot args to override or modify those from ``/etc/modprobe.d``
2859d85025bSMauro Carvalho Chehab(sensible, since 1 is system wide, 2 is kernel or boot specific), and
2869d85025bSMauro Carvalho Chehabmodprobe args to override both.
2879d85025bSMauro Carvalho Chehab
2889d85025bSMauro Carvalho ChehabIn the ``foo.dyndbg="QUERY"`` form, the query must exclude ``module foo``.
2899d85025bSMauro Carvalho Chehab``foo`` is extracted from the param-name, and applied to each query in
2909d85025bSMauro Carvalho Chehab``QUERY``, and only 1 match-spec of each type is allowed.
2919d85025bSMauro Carvalho Chehab
2929d85025bSMauro Carvalho ChehabThe ``dyndbg`` option is a "fake" module parameter, which means:
2939d85025bSMauro Carvalho Chehab
2949d85025bSMauro Carvalho Chehab- modules do not need to define it explicitly
2959d85025bSMauro Carvalho Chehab- every module gets it tacitly, whether they use pr_debug or not
2969d85025bSMauro Carvalho Chehab- it doesn't appear in ``/sys/module/$module/parameters/``
2979d85025bSMauro Carvalho Chehab  To see it, grep the control file, or inspect ``/proc/cmdline.``
2989d85025bSMauro Carvalho Chehab
2999d85025bSMauro Carvalho ChehabFor ``CONFIG_DYNAMIC_DEBUG`` kernels, any settings given at boot-time (or
3009d85025bSMauro Carvalho Chehabenabled by ``-DDEBUG`` flag during compilation) can be disabled later via
301005ae6dfSRandy Dunlapthe debugfs interface if the debug messages are no longer needed::
3029d85025bSMauro Carvalho Chehab
303ace7c4bbSJim Cromie   echo "module module_name -p" > /proc/dynamic_debug/control
3049d85025bSMauro Carvalho Chehab
3059d85025bSMauro Carvalho ChehabExamples
3069d85025bSMauro Carvalho Chehab========
3079d85025bSMauro Carvalho Chehab
3089d85025bSMauro Carvalho Chehab::
3099d85025bSMauro Carvalho Chehab
3109d85025bSMauro Carvalho Chehab  // enable the message at line 1603 of file svcsock.c
311ace7c4bbSJim Cromie  :#> ddcmd 'file svcsock.c line 1603 +p'
3129d85025bSMauro Carvalho Chehab
3139d85025bSMauro Carvalho Chehab  // enable all the messages in file svcsock.c
314ace7c4bbSJim Cromie  :#> ddcmd 'file svcsock.c +p'
3159d85025bSMauro Carvalho Chehab
3169d85025bSMauro Carvalho Chehab  // enable all the messages in the NFS server module
317ace7c4bbSJim Cromie  :#> ddcmd 'module nfsd +p'
3189d85025bSMauro Carvalho Chehab
3199d85025bSMauro Carvalho Chehab  // enable all 12 messages in the function svc_process()
320ace7c4bbSJim Cromie  :#> ddcmd 'func svc_process +p'
3219d85025bSMauro Carvalho Chehab
3229d85025bSMauro Carvalho Chehab  // disable all 12 messages in the function svc_process()
323ace7c4bbSJim Cromie  :#> ddcmd 'func svc_process -p'
3249d85025bSMauro Carvalho Chehab
3259d85025bSMauro Carvalho Chehab  // enable messages for NFS calls READ, READLINK, READDIR and READDIR+.
326ace7c4bbSJim Cromie  :#> ddcmd 'format "nfsd: READ" +p'
3279d85025bSMauro Carvalho Chehab
3289d85025bSMauro Carvalho Chehab  // enable messages in files of which the paths include string "usb"
329121d0ba2SRex Nie  :#> ddcmd 'file *usb* +p'
3309d85025bSMauro Carvalho Chehab
3319d85025bSMauro Carvalho Chehab  // enable all messages
332121d0ba2SRex Nie  :#> ddcmd '+p'
3339d85025bSMauro Carvalho Chehab
3349d85025bSMauro Carvalho Chehab  // add module, function to all enabled messages
335121d0ba2SRex Nie  :#> ddcmd '+mf'
3369d85025bSMauro Carvalho Chehab
3379d85025bSMauro Carvalho Chehab  // boot-args example, with newlines and comments for readability
3389d85025bSMauro Carvalho Chehab  Kernel command line: ...
339dbeb56feSRandy Dunlap    // see what's going on in dyndbg=value processing
34009ee10ffSJim Cromie    dynamic_debug.verbose=3
3415879f1c9SAndrew Halaney    // enable pr_debugs in the btrfs module (can be builtin or loadable)
3425879f1c9SAndrew Halaney    btrfs.dyndbg="+p"
3435879f1c9SAndrew Halaney    // enable pr_debugs in all files under init/
3445879f1c9SAndrew Halaney    // and the function parse_one, #cmt is stripped
3455879f1c9SAndrew Halaney    dyndbg="file init/* +p #cmt ; func parse_one +p"
3469d85025bSMauro Carvalho Chehab    // enable pr_debugs in 2 functions in a module loaded later
3479d85025bSMauro Carvalho Chehab    pc87360.dyndbg="func pc87360_init_device +p; func pc87360_find +p"
348ace7c4bbSJim Cromie
349ace7c4bbSJim CromieKernel Configuration
350ace7c4bbSJim Cromie====================
351ace7c4bbSJim Cromie
352ace7c4bbSJim CromieDynamic Debug is enabled via kernel config items::
353ace7c4bbSJim Cromie
354ace7c4bbSJim Cromie  CONFIG_DYNAMIC_DEBUG=y	# build catalog, enables CORE
355ace7c4bbSJim Cromie  CONFIG_DYNAMIC_DEBUG_CORE=y	# enable mechanics only, skip catalog
356ace7c4bbSJim Cromie
357ace7c4bbSJim CromieIf you do not want to enable dynamic debug globally (i.e. in some embedded
358ace7c4bbSJim Cromiesystem), you may set ``CONFIG_DYNAMIC_DEBUG_CORE`` as basic support of dynamic
359ace7c4bbSJim Cromiedebug and add ``ccflags := -DDYNAMIC_DEBUG_MODULE`` into the Makefile of any
360ace7c4bbSJim Cromiemodules which you'd like to dynamically debug later.
361ace7c4bbSJim Cromie
362ace7c4bbSJim Cromie
363ace7c4bbSJim CromieKernel *prdbg* API
364ace7c4bbSJim Cromie==================
365ace7c4bbSJim Cromie
366ace7c4bbSJim CromieThe following functions are cataloged and controllable when dynamic
367ace7c4bbSJim Cromiedebug is enabled::
368ace7c4bbSJim Cromie
369ace7c4bbSJim Cromie  pr_debug()
370ace7c4bbSJim Cromie  dev_dbg()
371ace7c4bbSJim Cromie  print_hex_dump_debug()
372ace7c4bbSJim Cromie  print_hex_dump_bytes()
373ace7c4bbSJim Cromie
374ace7c4bbSJim CromieOtherwise, they are off by default; ``ccflags += -DDEBUG`` or
375ace7c4bbSJim Cromie``#define DEBUG`` in a source file will enable them appropriately.
376ace7c4bbSJim Cromie
377ace7c4bbSJim CromieIf ``CONFIG_DYNAMIC_DEBUG`` is not set, ``print_hex_dump_debug()`` is
378ace7c4bbSJim Cromiejust a shortcut for ``print_hex_dump(KERN_DEBUG)``.
379ace7c4bbSJim Cromie
380ace7c4bbSJim CromieFor ``print_hex_dump_debug()``/``print_hex_dump_bytes()``, format string is
381ace7c4bbSJim Cromieits ``prefix_str`` argument, if it is constant string; or ``hexdump``
382ace7c4bbSJim Cromiein case ``prefix_str`` is built dynamically.
383