Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 1 | Dynamic debug |
| 2 | +++++++++++++ |
| 3 | |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 4 | |
| 5 | Introduction |
| 6 | ============ |
| 7 | |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 8 | This document describes how to use the dynamic debug (dyndbg) feature. |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 9 | |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 10 | Dynamic debug is designed to allow you to dynamically enable/disable |
| 11 | kernel code to obtain additional kernel information. Currently, if |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 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 |
Vladimir Kondratiev | 7a55561 | 2012-12-05 16:48:27 -0500 | [diff] [blame] | 14 | enabled per-callsite. |
| 15 | |
Orson Zhai | ceabef7 | 2020-06-07 21:40:14 -0700 | [diff] [blame] | 16 | If you do not want to enable dynamic debug globally (i.e. in some embedded |
| 17 | system), you may set ``CONFIG_DYNAMIC_DEBUG_CORE`` as basic support of dynamic |
| 18 | debug and add ``ccflags := -DDYNAMIC_DEBUG_MODULE`` into the Makefile of any |
| 19 | modules which you'd like to dynamically debug later. |
| 20 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 21 | If ``CONFIG_DYNAMIC_DEBUG`` is not set, ``print_hex_dump_debug()`` is just |
| 22 | shortcut for ``print_hex_dump(KERN_DEBUG)``. |
Vladimir Kondratiev | 7a55561 | 2012-12-05 16:48:27 -0500 | [diff] [blame] | 23 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 24 | For ``print_hex_dump_debug()``/``print_hex_dump_bytes()``, format string is |
| 25 | its ``prefix_str`` argument, if it is constant string; or ``hexdump`` |
Randy Dunlap | 8c18875 | 2017-11-17 15:27:39 -0800 | [diff] [blame] | 26 | in case ``prefix_str`` is built dynamically. |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 27 | |
| 28 | Dynamic debug has even more useful features: |
| 29 | |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 30 | * Simple query language allows turning on and off debugging |
| 31 | statements by matching any combination of 0 or 1 of: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 32 | |
| 33 | - source filename |
| 34 | - function name |
| 35 | - line number (including ranges of line numbers) |
| 36 | - module name |
| 37 | - format string |
| 38 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 39 | * Provides a debugfs control file: ``<debugfs>/dynamic_debug/control`` |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 40 | which can be read to display the complete list of known debug |
| 41 | statements, to help guide you |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 42 | |
| 43 | Controlling dynamic debug Behaviour |
Thomas Renninger | a648ec0 | 2010-08-06 16:11:02 +0200 | [diff] [blame] | 44 | =================================== |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 45 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 46 | The behaviour of ``pr_debug()``/``dev_dbg()`` are controlled via writing to a |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 47 | control file in the 'debugfs' filesystem. Thus, you must first mount |
| 48 | the debugfs filesystem, in order to make use of this feature. |
| 49 | Subsequently, we refer to the control file as: |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 50 | ``<debugfs>/dynamic_debug/control``. For example, if you want to enable |
| 51 | printing from source file ``svcsock.c``, line 1603 you simply do:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 52 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 53 | nullarbor:~ # echo 'file svcsock.c line 1603 +p' > |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 54 | <debugfs>/dynamic_debug/control |
| 55 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 56 | If you make a mistake with the syntax, the write will fail thus:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 57 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 58 | nullarbor:~ # echo 'file svcsock.c wtf 1 +p' > |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 59 | <debugfs>/dynamic_debug/control |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 60 | -bash: echo: write error: Invalid argument |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 61 | |
Greg Kroah-Hartman | 239a579 | 2020-02-10 13:11:42 -0800 | [diff] [blame] | 62 | Note, for systems without 'debugfs' enabled, the control file can be |
| 63 | found in ``/proc/dynamic_debug/control``. |
| 64 | |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 65 | Viewing Dynamic Debug Behaviour |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 66 | =============================== |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 67 | |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 68 | You can view the currently configured behaviour of all the debug |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 69 | statements via:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 70 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 71 | nullarbor:~ # cat <debugfs>/dynamic_debug/control |
| 72 | # filename:lineno [module]function flags format |
Jim Cromie | e20e310 | 2020-07-19 17:10:41 -0600 | [diff] [blame] | 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" |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 77 | ... |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 78 | |
| 79 | |
| 80 | You can also apply standard Unix text manipulation filters to this |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 81 | data, e.g.:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 82 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 83 | nullarbor:~ # grep -i rdma <debugfs>/dynamic_debug/control | wc -l |
| 84 | 62 |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 85 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 86 | nullarbor:~ # grep -i tcp <debugfs>/dynamic_debug/control | wc -l |
| 87 | 42 |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 88 | |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 89 | The third column shows the currently enabled flags for each debug |
| 90 | statement callsite (see below for definitions of the flags). The |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 91 | default value, with no flags enabled, is ``=_``. So you can view all |
| 92 | the debug statement callsites with any non-default flags:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 93 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 94 | nullarbor:~ # awk '$3 != "=_"' <debugfs>/dynamic_debug/control |
| 95 | # filename:lineno [module]function flags format |
Jim Cromie | e20e310 | 2020-07-19 17:10:41 -0600 | [diff] [blame] | 96 | net/sunrpc/svcsock.c:1603 [sunrpc]svc_send p "svc_process: st_sendto returned %d\012" |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 97 | |
| 98 | Command Language Reference |
| 99 | ========================== |
| 100 | |
| 101 | At the lexical level, a command comprises a sequence of words separated |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 102 | by spaces or tabs. So these are all equivalent:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 103 | |
Steven Price | 31fc93d | 2017-01-17 13:38:49 +0000 | [diff] [blame] | 104 | nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' > |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 105 | <debugfs>/dynamic_debug/control |
Steven Price | 31fc93d | 2017-01-17 13:38:49 +0000 | [diff] [blame] | 106 | nullarbor:~ # echo -n ' file svcsock.c line 1603 +p ' > |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 107 | <debugfs>/dynamic_debug/control |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 108 | nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' > |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 109 | <debugfs>/dynamic_debug/control |
| 110 | |
Jim Cromie | 85f7f6c | 2011-12-19 17:13:21 -0500 | [diff] [blame] | 111 | Command submissions are bounded by a write() system call. |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 112 | Multiple commands can be written together, separated by ``;`` or ``\n``:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 113 | |
Jim Cromie | 85f7f6c | 2011-12-19 17:13:21 -0500 | [diff] [blame] | 114 | ~# echo "func pnpacpi_get_resources +p; func pnp_assign_mem +p" \ |
| 115 | > <debugfs>/dynamic_debug/control |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 116 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 117 | If your query set is big, you can batch them too:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 118 | |
Jim Cromie | 85f7f6c | 2011-12-19 17:13:21 -0500 | [diff] [blame] | 119 | ~# cat query-batch-file > <debugfs>/dynamic_debug/control |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 120 | |
Randy Dunlap | 1afc5fb | 2018-10-19 18:10:58 -0700 | [diff] [blame] | 121 | Another way is to use wildcards. The match rule supports ``*`` (matches |
| 122 | zero or more characters) and ``?`` (matches exactly one character). For |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 123 | example, you can match all usb drivers:: |
Du, Changbin | 8f073bd | 2014-01-23 15:54:15 -0800 | [diff] [blame] | 124 | |
| 125 | ~# echo "file drivers/usb/* +p" > <debugfs>/dynamic_debug/control |
| 126 | |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 127 | At the syntactical level, a command comprises a sequence of match |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 128 | specifications, followed by a flags change specification:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 129 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 130 | command ::= match-spec* flags-spec |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 131 | |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 132 | The match-spec's are used to choose a subset of the known pr_debug() |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 133 | callsites to which to apply the flags-spec. Think of them as a query |
| 134 | with implicit ANDs between each pair. Note that an empty list of |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 135 | match-specs will select all debug statement callsites. |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 136 | |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 137 | A match specification comprises a keyword, which controls the |
| 138 | attribute of the callsite to be compared, and a value to compare |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 139 | against. Possible keywords are::: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 140 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 141 | match-spec ::= 'func' string | |
| 142 | 'file' string | |
| 143 | 'module' string | |
| 144 | 'format' string | |
| 145 | 'line' line-range |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 146 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 147 | line-range ::= lineno | |
| 148 | '-'lineno | |
| 149 | lineno'-' | |
| 150 | lineno'-'lineno |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 151 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 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 | |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 159 | |
| 160 | The meanings of each keyword are: |
| 161 | |
| 162 | func |
| 163 | The given string is compared against the function name |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 164 | of each callsite. Example:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 165 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 166 | func svc_tcp_accept |
Jim Cromie | aaebe32 | 2020-07-19 17:10:53 -0600 | [diff] [blame] | 167 | func *recv* # in rfcomm, bluetooth, ping, tcp |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 168 | |
| 169 | file |
Jim Cromie | e20e310 | 2020-07-19 17:10:41 -0600 | [diff] [blame] | 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:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 173 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 174 | file svcsock.c |
Jim Cromie | e20e310 | 2020-07-19 17:10:41 -0600 | [diff] [blame] | 175 | file kernel/freezer.c # ie column 1 of control file |
Jim Cromie | aaebe32 | 2020-07-19 17:10:53 -0600 | [diff] [blame] | 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) |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 179 | |
| 180 | module |
| 181 | The given string is compared against the module name |
| 182 | of each callsite. The module name is the string as |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 183 | seen in ``lsmod``, i.e. without the directory or the ``.ko`` |
| 184 | suffix and with ``-`` changed to ``_``. Examples:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 185 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 186 | module sunrpc |
| 187 | module nfsd |
Jim Cromie | aaebe32 | 2020-07-19 17:10:53 -0600 | [diff] [blame] | 188 | module drm* # both drm, drm_kms_helper |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 189 | |
| 190 | format |
| 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 |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 195 | escape ``\ooo`` notation, e.g. the space character is ``\040``. |
Greg Banks | 9898abb | 2009-02-06 12:54:26 +1100 | [diff] [blame] | 196 | Alternatively, the string can be enclosed in double quote |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 197 | characters (``"``) or single quote characters (``'``). |
| 198 | Examples:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 199 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 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 |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 205 | |
| 206 | line |
| 207 | The given line number or range of line numbers is compared |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 208 | against the line number of each ``pr_debug()`` callsite. A single |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 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 |
Randy Dunlap | 8c18875 | 2017-11-17 15:27:39 -0800 | [diff] [blame] | 212 | the first line in the file, an empty last line number means the |
| 213 | last line number in the file. Examples:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 214 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 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 |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 219 | |
| 220 | The flags specification comprises a change operation followed |
| 221 | by one or more flag characters. The change operation is one |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 222 | of the characters:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 223 | |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 224 | - remove the given flags |
| 225 | + add the given flags |
| 226 | = set the flags to the given flags |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 227 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 228 | The flags are:: |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 229 | |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 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) |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 236 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 237 | For ``print_hex_dump_debug()`` and ``print_hex_dump_bytes()``, only ``p`` flag |
Vladimir Kondratiev | 7a55561 | 2012-12-05 16:48:27 -0500 | [diff] [blame] | 238 | have meaning, other flags ignored. |
| 239 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 240 | For display, the flags are preceded by ``=`` |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 241 | (mnemonic: what the flags are currently equal to). |
| 242 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 243 | Note the regexp ``^[-+=][flmpt_]+$`` matches a flags specification. |
| 244 | To clear all flags at once, use ``=_`` or ``-flmpt``. |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 245 | |
Thomas Renninger | a648ec0 | 2010-08-06 16:11:02 +0200 | [diff] [blame] | 246 | |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 247 | Debug messages during Boot Process |
Thomas Renninger | a648ec0 | 2010-08-06 16:11:02 +0200 | [diff] [blame] | 248 | ================================== |
| 249 | |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 250 | To activate debug messages for core code and built-in modules during |
| 251 | the boot process, even before userspace and debugfs exists, use |
Andrew Halaney | 9c40e1a | 2021-10-13 11:40:21 -0400 | [diff] [blame] | 252 | ``dyndbg="QUERY"`` or ``module.dyndbg="QUERY"``. QUERY follows |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 253 | the syntax described above, but must not exceed 1023 characters. Your |
| 254 | bootloader may impose lower limits. |
Thomas Renninger | a648ec0 | 2010-08-06 16:11:02 +0200 | [diff] [blame] | 255 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 256 | These ``dyndbg`` params are processed just after the ddebug tables are |
Jim Cromie | fa08052 | 2020-07-19 17:10:42 -0600 | [diff] [blame] | 257 | processed, as part of the early_initcall. Thus you can enable debug |
| 258 | messages in all code run after this early_initcall via this boot |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 259 | parameter. |
| 260 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 261 | On an x86 system for example ACPI enablement is a subsys_initcall and:: |
| 262 | |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 263 | dyndbg="file ec.c +p" |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 264 | |
Thomas Renninger | a648ec0 | 2010-08-06 16:11:02 +0200 | [diff] [blame] | 265 | will show early Embedded Controller transactions during ACPI setup if |
| 266 | your machine (typically a laptop) has an Embedded Controller. |
| 267 | PCI (or other devices) initialization also is a hot candidate for using |
| 268 | this boot parameter for debugging purposes. |
| 269 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 270 | If ``foo`` module is not built-in, ``foo.dyndbg`` will still be processed at |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 271 | boot time, without effect, but will be reprocessed when module is |
Andrew Halaney | 9c40e1a | 2021-10-13 11:40:21 -0400 | [diff] [blame] | 272 | loaded later. Bare ``dyndbg=`` is only processed at boot. |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 273 | |
| 274 | |
| 275 | Debug Messages at Module Initialization Time |
| 276 | ============================================ |
| 277 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 278 | When ``modprobe foo`` is called, modprobe scans ``/proc/cmdline`` for |
| 279 | ``foo.params``, strips ``foo.``, and passes them to the kernel along with |
| 280 | params given in modprobe args or ``/etc/modprob.d/*.conf`` files, |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 281 | in the following order: |
| 282 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 283 | 1. parameters given via ``/etc/modprobe.d/*.conf``:: |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 284 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 285 | options foo dyndbg=+pt |
| 286 | options foo dyndbg # defaults to +p |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 287 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 288 | 2. ``foo.dyndbg`` as given in boot args, ``foo.`` is stripped and passed:: |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 289 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 290 | foo.dyndbg=" func bar +p; func buz +mp" |
| 291 | |
| 292 | 3. args to modprobe:: |
| 293 | |
| 294 | modprobe foo dyndbg==pmf # override previous settings |
| 295 | |
| 296 | These ``dyndbg`` queries are applied in order, with last having final say. |
| 297 | This allows boot args to override or modify those from ``/etc/modprobe.d`` |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 298 | (sensible, since 1 is system wide, 2 is kernel or boot specific), and |
| 299 | modprobe args to override both. |
| 300 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 301 | In the ``foo.dyndbg="QUERY"`` form, the query must exclude ``module foo``. |
| 302 | ``foo`` is extracted from the param-name, and applied to each query in |
| 303 | ``QUERY``, and only 1 match-spec of each type is allowed. |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 304 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 305 | The ``dyndbg`` option is a "fake" module parameter, which means: |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 306 | |
| 307 | - modules do not need to define it explicitly |
| 308 | - every module gets it tacitly, whether they use pr_debug or not |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 309 | - it doesn't appear in ``/sys/module/$module/parameters/`` |
| 310 | To see it, grep the control file, or inspect ``/proc/cmdline.`` |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 311 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 312 | For ``CONFIG_DYNAMIC_DEBUG`` kernels, any settings given at boot-time (or |
| 313 | enabled by ``-DDEBUG`` flag during compilation) can be disabled later via |
Randy Dunlap | 005ae6d | 2018-10-19 16:55:34 -0700 | [diff] [blame] | 314 | the debugfs interface if the debug messages are no longer needed:: |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 315 | |
| 316 | echo "module module_name -p" > <debugfs>/dynamic_debug/control |
Thomas Renninger | a648ec0 | 2010-08-06 16:11:02 +0200 | [diff] [blame] | 317 | |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 318 | Examples |
| 319 | ======== |
| 320 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 321 | :: |
| 322 | |
| 323 | // enable the message at line 1603 of file svcsock.c |
| 324 | nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' > |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 325 | <debugfs>/dynamic_debug/control |
| 326 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 327 | // enable all the messages in file svcsock.c |
| 328 | nullarbor:~ # echo -n 'file svcsock.c +p' > |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 329 | <debugfs>/dynamic_debug/control |
| 330 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 331 | // enable all the messages in the NFS server module |
| 332 | nullarbor:~ # echo -n 'module nfsd +p' > |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 333 | <debugfs>/dynamic_debug/control |
| 334 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 335 | // enable all 12 messages in the function svc_process() |
| 336 | nullarbor:~ # echo -n 'func svc_process +p' > |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 337 | <debugfs>/dynamic_debug/control |
| 338 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 339 | // disable all 12 messages in the function svc_process() |
| 340 | nullarbor:~ # echo -n 'func svc_process -p' > |
Jason Baron | 86151fd | 2009-02-05 11:53:15 -0500 | [diff] [blame] | 341 | <debugfs>/dynamic_debug/control |
Greg Banks | 9898abb | 2009-02-06 12:54:26 +1100 | [diff] [blame] | 342 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 343 | // enable messages for NFS calls READ, READLINK, READDIR and READDIR+. |
| 344 | nullarbor:~ # echo -n 'format "nfsd: READ" +p' > |
Greg Banks | 9898abb | 2009-02-06 12:54:26 +1100 | [diff] [blame] | 345 | <debugfs>/dynamic_debug/control |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 346 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 347 | // enable messages in files of which the paths include string "usb" |
Martin Kepplinger | e85d92b | 2021-03-03 10:16:46 +0100 | [diff] [blame] | 348 | nullarbor:~ # echo -n 'file *usb* +p' > <debugfs>/dynamic_debug/control |
Du, Changbin | 8f073bd | 2014-01-23 15:54:15 -0800 | [diff] [blame] | 349 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 350 | // enable all messages |
| 351 | nullarbor:~ # echo -n '+p' > <debugfs>/dynamic_debug/control |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 352 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 353 | // add module, function to all enabled messages |
| 354 | nullarbor:~ # echo -n '+mf' > <debugfs>/dynamic_debug/control |
Jim Cromie | 29e36c9 | 2012-04-27 14:30:41 -0600 | [diff] [blame] | 355 | |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 356 | // boot-args example, with newlines and comments for readability |
| 357 | Kernel command line: ... |
| 358 | // see whats going on in dyndbg=value processing |
Jim Cromie | 09ee10f | 2021-10-19 15:07:46 -0600 | [diff] [blame] | 359 | dynamic_debug.verbose=3 |
Andrew Halaney | 5879f1c | 2021-10-13 11:40:22 -0400 | [diff] [blame] | 360 | // enable pr_debugs in the btrfs module (can be builtin or loadable) |
| 361 | btrfs.dyndbg="+p" |
| 362 | // enable pr_debugs in all files under init/ |
| 363 | // and the function parse_one, #cmt is stripped |
| 364 | dyndbg="file init/* +p #cmt ; func parse_one +p" |
Mauro Carvalho Chehab | 7d4e351 | 2016-09-21 16:32:00 -0300 | [diff] [blame] | 365 | // enable pr_debugs in 2 functions in a module loaded later |
| 366 | pc87360.dyndbg="func pc87360_init_device +p; func pc87360_find +p" |