← Documents Documentation/admin-guide/dynamic-debug-howto.rst GitHub 원문 ↗

Linux 6.18.37 · Administration / Debugging

Linux dynamic debug guide

Linux 동적 디버그 카탈로그, 질의 문법, 플래그, 부팅 및 모듈 초기화 설정을 실제 명령과 함께 설명합니다.

Source pathDocumentation/admin-guide/dynamic-debug-howto.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

카탈로그와 제어 인터페이스

dynamic-debug-howto.rst:1-75

`/proc/dynamic_debug/control`에서 모든 `pr_debug` 호출 지점을 조회하고 파일, 함수, 줄, 모듈, 형식, 클래스로 선택해 실행 중에 출력을 켜거나 끕니다.

질의 문법과 플래그

dynamic-debug-howto.rst:76-233

여러 일치 조건은 AND로 결합되며 와일드카드와 줄 범위를 지원합니다. `+`, `-`, `=` 연산과 `p`, `t`, `m`, `f`, `s`, `l`, `_` 플래그로 출력 및 접두사를 제어합니다.

부팅·모듈·커널 설정

dynamic-debug-howto.rst:234-382

`dyndbg` 부팅 인자와 modprobe 설정의 적용 순서, 전체 예제, `CONFIG_DYNAMIC_DEBUG` 설정과 제어 가능한 커널 API를 정리합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

동적 디버그 소개

1-32

동적 디버그(dynamic debug)는 커널의 디버그 출력 코드를 실행 중에 켜고 끌 수 있게 하여 추가 커널 정보를 얻도록 합니다.

`/proc/dynamic_debug/control`이 존재하면 해당 커널은 동적 디버그를 지원합니다. 이 기능을 사용하려면 루트 권한(`sudo su`)이 필요합니다.

동적 디버그는 다음 기능을 제공합니다.

  • 커널 안의 모든 `prdbg` 호출 지점에 대한 카탈로그. `cat /proc/dynamic_debug/control`로 확인합니다.
  • 아래 속성 가운데 각 속성을 0개 또는 1개씩 조합하여 `prdbg`를 선택하고 상태를 바꾸는 단순한 질의/명령 언어.
  • 소스 파일 이름, 함수 이름, 줄 번호 또는 줄 범위, 모듈 이름, 형식 문자열, 각 모듈이 알고 있거나 선언한 클래스 이름으로 선택할 수 있습니다.

디버그 출력이 실제 콘솔에 나타나게 하려면 커널 `loglevel=`을 조정하거나 `ignore_loglevel`을 사용해야 할 수 있습니다. 이 매개변수는 `Documentation/admin-guide/kernel-parameters.rst`를 참고하십시오.

현재 동작 상태 보기

33-50

현재 설정된 동작은 `prdbg` 카탈로그에서 볼 수 있습니다.

:#> head -n7 /proc/dynamic_debug/control
# filename:lineno [module]function flags format
init/main.c:1179 [main]initcall_blacklist =_ "blacklisting initcall %s\012
init/main.c:1218 [main]initcall_blacklisted =_ "initcall %s blacklisted\012"
init/main.c:1424 [main]run_init_process =_ "  with arguments:\012"
init/main.c:1426 [main]run_init_process =_ "    %s\012"
init/main.c:1427 [main]run_init_process =_ "  with environment:\012"
init/main.c:1429 [main]run_init_process =_ "    %s\012"

공백으로 구분한 세 번째 열은 현재 플래그를 보여 줍니다. 앞에 `=`가 붙어 있어 `grep`이나 `cut`에서 쉽게 사용할 수 있으며, `=p`는 해당 호출 지점이 활성화되었음을 뜻합니다.

동적 디버그 동작 제어

51-75

`prdbg` 지점의 동작은 control 파일에 질의/명령을 써서 제어합니다. 다음 예는 명령 입력을 편하게 하는 별칭을 만든 뒤 모든 `p` 플래그를 지우고, `main` 모듈에서 이름이 `run`으로 시작하는 함수만 다시 켭니다.

# grease the interface
:#> alias ddcmd='echo $* > /proc/dynamic_debug/control'

:#> ddcmd '-p; module main func run* +p'
:#> grep =p /proc/dynamic_debug/control
init/main.c:1424 [main]run_init_process =p "  with arguments:\012"
init/main.c:1426 [main]run_init_process =p "    %s\012"
init/main.c:1427 [main]run_init_process =p "  with environment:\012"
init/main.c:1429 [main]run_init_process =p "    %s\012"

오류 메시지는 콘솔 또는 syslog로 전달됩니다.

:#> ddcmd mode foo +p
dyndbg: unknown keyword "mode"
dyndbg: query parse failed
bash: echo: write error: Invalid argument

debugfs도 활성화되어 마운트되어 있다면 `dynamic_debug/control`은 그 마운트 디렉터리 아래에도 있습니다. 일반적인 전체 경로는 `/sys/kernel/debug/dynamic_debug/control`입니다.

명령 언어의 어휘와 제출 단위

76-110

기본 어휘 수준에서 명령은 공백이나 탭으로 나뉜 단어의 연속입니다. 따라서 아래 세 명령은 모두 같습니다.

:#> ddcmd file svcsock.c line 1603 +p
:#> ddcmd "file svcsock.c line 1603 +p"
:#> ddcmd '  file   svcsock.c     line  1603 +p  '

명령 제출 단위는 한 번의 `write()` 시스템 호출로 정해집니다. 여러 명령은 `;` 또는 `\n`으로 구분하여 한 번에 쓸 수 있습니다.

:#> ddcmd "func pnpacpi_get_resources +p; func pnp_assign_mem +p"
:#> ddcmd <<"EOC"
func pnpacpi_get_resources +p
func pnp_assign_mem +p
EOC
:#> cat query-batch-file > /proc/dynamic_debug/control

각 질의 항에는 와일드카드를 사용할 수 있습니다. `*`는 0개 이상의 문자와, `?`는 정확히 한 문자와 일치합니다. 예를 들어 다음 명령은 모든 USB 드라이버를 선택합니다. 큰따옴표는 셸의 와일드카드 확장을 막습니다.

:#> ddcmd file "drivers/usb/*" +p	# "" to suppress shell expansion

문법적으로 명령은 키워드와 값의 쌍이 0개 이상 나온 뒤 플래그 변경 또는 설정이 이어지는 형태입니다.

command ::= match-spec* flags-spec

`match-spec`들은 카탈로그에서 `prdbg`를 선택하고, 그 결과에 `flags-spec`을 적용합니다. 모든 제약은 논리 AND로 결합됩니다. 어떤 키워드를 쓰지 않는 것은 그 키워드에 `*`를 지정한 것과 같습니다.

일치 조건 문법

111-136

일치 명세는 비교할 호출 지점 속성을 고르는 키워드와 그 속성에 비교할 값으로 이루어집니다. 사용할 수 있는 문법은 다음과 같습니다.

match-spec ::= 'func' string |
		 'file' string |
		 'module' string |
		 'format' string |
		 'class' string |
		 'line' line-range

line-range ::= lineno |
		 '-'lineno |
		 lineno'-' |
		 lineno'-'lineno

lineno ::= unsigned-int

`line-range`에는 공백을 넣을 수 없습니다. 예를 들어 `1-30`은 유효한 범위지만 `1 - 30`은 유효하지 않습니다.

함수·파일·모듈·형식 키워드

137-182

`func`는 주어진 문자열을 각 호출 지점의 함수 이름과 비교합니다.

func svc_tcp_accept
func *recv*		# in rfcomm, bluetooth, ping, tcp

`file`은 주어진 문자열을 각 호출 지점 소스 파일의 소스 루트 기준 상대 경로 또는 basename과 비교합니다. `:` 뒤 꼬리는 앞에서 설명한 함수나 줄 범위로 해석할 수도 있습니다.

file svcsock.c
file kernel/freezer.c	# ie column 1 of control file
file drivers/usb/*	# all callsites under it
file inode.c:start_*	# parse :tail as a func (above)
file inode.c:1-100	# parse :tail as a line-range (above)

`module`은 주어진 문자열을 각 호출 지점의 모듈 이름과 비교합니다. 이 이름은 `lsmod`에 보이는 문자열이며, 디렉터리나 `.ko` 접미사는 없고 `-`는 `_`로 바뀐 형태입니다.

module sunrpc
module nfsd
module drm*	# both drm, drm_kms_helper

`format`은 동적 디버그 형식 문자열 안에서 주어진 문자열을 검색합니다. 전체 형식과 일치할 필요 없이 일부만 일치해도 됩니다. 공백과 특수 문자는 C 8진 문자 이스케이프 `\ooo`로 표현할 수 있으며 공백은 `\040`입니다. 또는 문자열을 큰따옴표나 작은따옴표로 감쌀 수 있습니다.

format svcrdma:         // many of the NFS/RDMA server pr_debugs
format readahead        // some pr_debugs in the readahead cache
format nfsd:\040SETATTR // one way to match a format with whitespace
format "nfsd: SETATTR"  // a neater way to match a format with whitespace
format 'nfsd: SETATTR'  // yet another way to match a format with whitespace

클래스와 줄 범위 키워드

183-206

`class`는 주어진 `class_name`을 모듈마다 검증합니다. 모듈은 자신이 아는 클래스 이름 목록을 선언할 수 있습니다. 해당 모듈에서 클래스 이름을 찾으면 호출 지점과 클래스 일치 여부를 검사하고 설정을 조정합니다. 클래스 이름에는 와일드카드를 사용할 수 없습니다.

class DRM_UT_KMS	# a DRM.debug category
class JUNK		# silent non-match
// class TLD_*		# NOTICE: no wildcard in class names

`line`은 주어진 줄 번호 또는 줄 범위를 각 `pr_debug()` 호출 지점의 줄 번호와 비교합니다. 단일 번호는 정확히 그 줄만 선택하고, 범위는 처음과 마지막 줄을 모두 포함합니다. 첫 번호를 생략하면 파일의 첫 줄부터, 마지막 번호를 생략하면 파일 끝까지를 뜻합니다.

line 1603           // exactly line 1603
line 1600-1605      // the six lines from line 1600 to line 1605
line -1605          // the 1605 lines from line 1 to line 1605
line 1600-          // all lines from line 1600 to the end of the file

플래그 명세

207-233

플래그 명세는 변경 연산자 하나와 하나 이상의 플래그 문자로 이루어집니다.

연산자의미
-지정한 플래그를 제거
+지정한 플래그를 추가
=현재 플래그를 지정한 플래그 집합으로 설정

`p`는 `pr_debug()` 호출 지점을 활성화하고, `_`는 아무 플래그도 활성화하지 않습니다. 장식자 플래그는 아래 순서대로 메시지 접두사에 정보를 더합니다.

플래그메시지 접두사에 추가하는 정보
t스레드 ID 또는 `<intr>`
m모듈 이름
f함수 이름
s소스 파일 이름
l줄 번호

`print_hex_dump_debug()`와 `print_hex_dump_bytes()`에서는 `p` 플래그만 의미가 있고 다른 플래그는 무시됩니다.

정규식 `^[-+=][fslmpt_]+$`는 플래그 명세와 일치합니다. 모든 플래그를 한꺼번에 지우려면 `=_` 또는 `-fslmpt`를 사용합니다.

부팅 과정의 디버그 메시지

234-261

사용자 공간과 debugfs가 생기기 전을 포함하여 부팅 과정의 코어 코드와 내장 모듈 디버그 메시지를 활성화하려면 `dyndbg="QUERY"` 또는 `module.dyndbg="QUERY"`를 사용합니다. `QUERY`는 앞에서 설명한 문법을 따르며 1,023자를 넘을 수 없습니다. 부트로더가 더 낮은 제한을 둘 수도 있습니다.

이 `dyndbg` 매개변수는 ddebug 테이블을 처리한 직후 `early_initcall`의 일부로 처리됩니다. 따라서 이 부팅 매개변수로 해당 `early_initcall` 뒤에 실행되는 모든 코드의 디버그 메시지를 켤 수 있습니다.

예를 들어 x86 시스템에서 ACPI 활성화는 `subsys_initcall`이므로 다음 설정은 장비에 Embedded Controller가 있는 경우 ACPI 설정 중 초기 Embedded Controller 트랜잭션을 보여 줍니다.

dyndbg="file ec.c +p"

PCI 또는 다른 장치의 초기화도 이 부팅 매개변수로 디버깅하기 좋은 대상입니다.

`foo` 모듈이 내장 모듈이 아니어도 `foo.dyndbg`는 부팅 때 일단 처리되며 그 시점에는 효과가 없습니다. 이후 모듈이 로드될 때 다시 처리됩니다. 접두사 없는 `dyndbg=`는 부팅 때만 처리됩니다.

모듈 초기화 시 디버그 메시지

262-304

`modprobe foo`를 호출하면 modprobe는 `/proc/cmdline`에서 `foo.params`를 찾고 `foo.`를 제거한 뒤, modprobe 인자나 `/etc/modprobe.d/*.conf` 파일의 매개변수와 함께 다음 순서로 커널에 전달합니다.

1. `/etc/modprobe.d/*.conf`에서 지정한 매개변수

options foo dyndbg=+pt
options foo dyndbg # defaults to +p

2. 부팅 인자에 지정된 `foo.dyndbg`. `foo.`를 제거한 뒤 전달합니다.

foo.dyndbg=" func bar +p; func buz +mp"

3. `modprobe` 명령에 직접 준 인자

modprobe foo dyndbg==pmf # override previous settings

이 `dyndbg` 질의는 위 순서로 적용되므로 마지막 설정이 최종 결과를 결정합니다. 따라서 시스템 전체 설정인 `/etc/modprobe.d`의 값을 커널 또는 부팅별 부팅 인자가 덮어쓰거나 수정할 수 있고, modprobe 인자는 앞의 두 설정을 모두 덮어쓸 수 있습니다.

`foo.dyndbg="QUERY"` 형식에서는 질의에 `module foo`를 넣지 않아야 합니다. `foo`는 매개변수 이름에서 추출되어 `QUERY`의 각 질의에 적용되며, 각 종류의 `match-spec`은 하나만 허용됩니다.

`dyndbg` 옵션은 다음 의미에서 가짜 모듈 매개변수입니다.

  • 모듈이 이 매개변수를 명시적으로 정의할 필요가 없습니다.
  • `pr_debug`를 사용하든 사용하지 않든 모든 모듈에 암묵적으로 주어집니다.
  • `/sys/module/$module/parameters/`에는 나타나지 않습니다. 확인하려면 control 파일을 grep하거나 `/proc/cmdline`을 살펴보십시오.

`CONFIG_DYNAMIC_DEBUG` 커널에서는 부팅 때 지정했거나 컴파일 시 `-DDEBUG` 플래그로 활성화한 설정도 메시지가 더 이상 필요하지 않을 때 debugfs 인터페이스를 통해 끌 수 있습니다.

echo "module module_name -p" > /proc/dynamic_debug/control

명령 예제

305-348

다음은 특정 줄, 파일, 모듈, 함수, 형식 문자열과 경로 패턴을 선택하는 예, 전체 메시지를 켜는 예, 접두사 장식자를 추가하는 예입니다.

// enable the message at line 1603 of file svcsock.c
:#> ddcmd 'file svcsock.c line 1603 +p'

// enable all the messages in file svcsock.c
:#> ddcmd 'file svcsock.c +p'

// enable all the messages in the NFS server module
:#> ddcmd 'module nfsd +p'

// enable all 12 messages in the function svc_process()
:#> ddcmd 'func svc_process +p'

// disable all 12 messages in the function svc_process()
:#> ddcmd 'func svc_process -p'

// enable messages for NFS calls READ, READLINK, READDIR and READDIR+.
:#> ddcmd 'format "nfsd: READ" +p'

// enable messages in files of which the paths include string "usb"
:#> ddcmd 'file *usb* +p'

// enable all messages
:#> ddcmd '+p'

// add module, function to all enabled messages
:#> ddcmd '+mf'
  • `file svcsock.c line 1603 +p`는 `svcsock.c` 1603줄의 메시지만 켭니다.
  • `file svcsock.c +p`는 그 파일의 모든 메시지를 켭니다.
  • `module nfsd +p`는 NFS 서버 모듈의 모든 메시지를 켭니다.
  • `func svc_process +p`와 `-p`는 해당 함수의 12개 메시지를 각각 켜고 끕니다.
  • `format "nfsd: READ" +p`는 READ, READLINK, READDIR, READDIR+ NFS 호출 메시지를 선택합니다.
  • `file *usb* +p`는 경로에 `usb`가 들어간 파일의 메시지를 켭니다.
  • `+p`는 모든 메시지를 켜고 `+mf`는 켜진 모든 메시지에 모듈 이름과 함수 이름을 추가합니다.

다음 부팅 인자 예는 읽기 쉽도록 줄바꿈과 주석을 넣은 것입니다. `dynamic_debug.verbose=3`으로 처리 과정을 보고, 내장 또는 로드 가능 btrfs 모듈, `init/` 아래 파일과 `parse_one`, 나중에 로드되는 `pc87360` 모듈의 두 함수를 각각 활성화합니다. `#cmt` 주석은 제거됩니다.

Kernel command line: ...
  // see what's going on in dyndbg=value processing
  dynamic_debug.verbose=3
  // enable pr_debugs in the btrfs module (can be builtin or loadable)
  btrfs.dyndbg="+p"
  // enable pr_debugs in all files under init/
  // and the function parse_one, #cmt is stripped
  dyndbg="file init/* +p #cmt ; func parse_one +p"
  // enable pr_debugs in 2 functions in a module loaded later
  pc87360.dyndbg="func pc87360_init_device +p; func pc87360_find +p"

커널 설정

349-362

동적 디버그는 다음 커널 설정 항목으로 활성화합니다.

CONFIG_DYNAMIC_DEBUG=y	# build catalog, enables CORE
CONFIG_DYNAMIC_DEBUG_CORE=y	# enable mechanics only, skip catalog

동적 디버그를 시스템 전체에서 활성화하고 싶지 않은 임베디드 시스템 등에서는 `CONFIG_DYNAMIC_DEBUG_CORE`만 기본 지원으로 설정할 수 있습니다. 이후 동적으로 디버그하려는 모듈의 Makefile에 `ccflags := -DDYNAMIC_DEBUG_MODULE`을 추가합니다.

커널 prdbg API

363-382

동적 디버그를 활성화하면 다음 함수가 카탈로그에 기록되고 제어할 수 있게 됩니다.

pr_debug()
dev_dbg()
print_hex_dump_debug()
print_hex_dump_bytes()

그렇지 않으면 이 함수들은 기본적으로 꺼져 있습니다. 컴파일 옵션에 `ccflags += -DDEBUG`를 넣거나 소스 파일에서 `#define DEBUG`를 정의하면 알맞게 활성화됩니다.

`CONFIG_DYNAMIC_DEBUG`가 설정되지 않았다면 `print_hex_dump_debug()`는 단순히 `print_hex_dump(KERN_DEBUG)`를 호출하는 축약형입니다.

`print_hex_dump_debug()`와 `print_hex_dump_bytes()`의 형식 문자열은 `prefix_str` 인자가 상수 문자열일 때 그 인자입니다. `prefix_str`을 동적으로 만들면 형식 문자열은 `hexdump`입니다.