요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
질의 문법과 플래그
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 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
Dynamic debug
+++++++++++++
Introduction
============
Dynamic debug allows you to dynamically enable/disable kernel
debug-print code to obtain additional kernel information.
If ``/proc/dynamic_debug/control`` exists, your kernel has dynamic
debug. You'll need root access (sudo su) to use this.
Dynamic debug provides:
* a Catalog of all *prdbgs* in your kernel.
``cat /proc/dynamic_debug/control`` to see them.
* a Simple query/command language to alter *prdbgs* by selecting on
any combination of 0 or 1 of:
- source filename
- function name
- line number (including ranges of line numbers)
- module name
- format string
- class name (as known/declared by each module)
NOTE: To actually get the debug-print output on the console, you may
need to adjust the kernel ``loglevel=``, or use ``ignore_loglevel``.
Read about these kernel parameters in
Documentation/admin-guide/kernel-parameters.rst.
Viewing Dynamic Debug Behaviour
===============================
You can view the currently configured behaviour in the *prdbg* catalog::
:#> 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"
The 3rd space-delimited column shows the current flags, preceded by
a ``=`` for easy use with grep/cut. ``=p`` shows enabled callsites.
Controlling dynamic debug Behaviour
===================================
The behaviour of *prdbg* sites are controlled by writing
query/commands to the control file. Example::
# 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"
Error messages go to console/syslog::
:#> ddcmd mode foo +p
dyndbg: unknown keyword "mode"
dyndbg: query parse failed
bash: echo: write error: Invalid argument
If debugfs is also enabled and mounted, ``dynamic_debug/control`` is
also under the mount-dir, typically ``/sys/kernel/debug/``.
Command Language Reference
==========================
At the basic lexical level, a command is a sequence of words separated
by spaces or tabs. So these are all equivalent::
:#> ddcmd file svcsock.c line 1603 +p
:#> ddcmd "file svcsock.c line 1603 +p"
:#> ddcmd ' file svcsock.c line 1603 +p '
Command submissions are bounded by a write() system call.
Multiple commands can be written together, separated by ``;`` or ``\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
You can also use wildcards in each query term. The match rule supports
``*`` (matches zero or more characters) and ``?`` (matches exactly one
character). For example, you can match all usb drivers::
:#> ddcmd file "drivers/usb/*" +p # "" to suppress shell expansion
Syntactically, a command is pairs of keyword values, followed by a
flags change or setting::
command ::= match-spec* flags-spec
The match-spec's select *prdbgs* from the catalog, upon which to apply
the flags-spec, all constraints are ANDed together. An absent keyword
is the same as keyword "*".
A match specification is a keyword, which selects the attribute of
the callsite to be compared, and a value to compare against. Possible
keywords are:::
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
.. note::
``line-range`` cannot contain space, e.g.
"1-30" is valid range but "1 - 30" is not.
The meanings of each keyword are:
func
The given string is compared against the function name
of each callsite. Example::
func svc_tcp_accept
func *recv* # in rfcomm, bluetooth, ping, tcp
file
The given string is compared against either the src-root relative
pathname, or the basename of the source file of each callsite.
Examples::
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
The given string is compared against the module name
of each callsite. The module name is the string as
seen in ``lsmod``, i.e. without the directory or the ``.ko``
suffix and with ``-`` changed to ``_``. Examples::
module sunrpc
module nfsd
module drm* # both drm, drm_kms_helper
format
The given string is searched for in the dynamic debug format
string. Note that the string does not need to match the
entire format, only some part. Whitespace and other
special characters can be escaped using C octal character
escape ``\ooo`` notation, e.g. the space character is ``\040``.
Alternatively, the string can be enclosed in double quote
characters (``"``) or single quote characters (``'``).
Examples::
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
class
The given class_name is validated against each module, which may
have declared a list of known class_names. If the class_name is
found for a module, callsite & class matching and adjustment
proceeds. Examples::
class DRM_UT_KMS # a DRM.debug category
class JUNK # silent non-match
// class TLD_* # NOTICE: no wildcard in class names
line
The given line number or range of line numbers is compared
against the line number of each ``pr_debug()`` callsite. A single
line number matches the callsite line number exactly. A
range of line numbers matches any callsite between the first
and last line number inclusive. An empty first number means
the first line in the file, an empty last line number means the
last line number in the file. Examples::
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
The flags specification comprises a change operation followed
by one or more flag characters. The change operation is one
of the characters::
- remove the given flags
+ add the given flags
= set the flags to the given flags
The flags are::
p enables the pr_debug() callsite.
_ enables no flags.
Decorator flags add to the message-prefix, in order:
t Include thread ID, or <intr>
m Include module name
f Include the function name
s Include the source file name
l Include line number
For ``print_hex_dump_debug()`` and ``print_hex_dump_bytes()``, only
the ``p`` flag has meaning, other flags are ignored.
Note the regexp ``^[-+=][fslmpt_]+$`` matches a flags specification.
To clear all flags at once, use ``=_`` or ``-fslmpt``.
Debug messages during Boot Process
==================================
To activate debug messages for core code and built-in modules during
the boot process, even before userspace and debugfs exists, use
``dyndbg="QUERY"`` or ``module.dyndbg="QUERY"``. QUERY follows
the syntax described above, but must not exceed 1023 characters. Your
bootloader may impose lower limits.
These ``dyndbg`` params are processed just after the ddebug tables are
processed, as part of the early_initcall. Thus you can enable debug
messages in all code run after this early_initcall via this boot
parameter.
On an x86 system for example ACPI enablement is a subsys_initcall and::
dyndbg="file ec.c +p"
will show early Embedded Controller transactions during ACPI setup if
your machine (typically a laptop) has an Embedded Controller.
PCI (or other devices) initialization also is a hot candidate for using
this boot parameter for debugging purposes.
If ``foo`` module is not built-in, ``foo.dyndbg`` will still be processed at
boot time, without effect, but will be reprocessed when module is
loaded later. Bare ``dyndbg=`` is only processed at boot.
Debug Messages at Module Initialization Time
============================================
When ``modprobe foo`` is called, modprobe scans ``/proc/cmdline`` for
``foo.params``, strips ``foo.``, and passes them to the kernel along with
params given in modprobe args or ``/etc/modprobe.d/*.conf`` files,
in the following order:
1. parameters given via ``/etc/modprobe.d/*.conf``::
options foo dyndbg=+pt
options foo dyndbg # defaults to +p
2. ``foo.dyndbg`` as given in boot args, ``foo.`` is stripped and passed::
foo.dyndbg=" func bar +p; func buz +mp"
3. args to modprobe::
modprobe foo dyndbg==pmf # override previous settings
These ``dyndbg`` queries are applied in order, with last having final say.
This allows boot args to override or modify those from ``/etc/modprobe.d``
(sensible, since 1 is system wide, 2 is kernel or boot specific), and
modprobe args to override both.
In the ``foo.dyndbg="QUERY"`` form, the query must exclude ``module foo``.
``foo`` is extracted from the param-name, and applied to each query in
``QUERY``, and only 1 match-spec of each type is allowed.
The ``dyndbg`` option is a "fake" module parameter, which means:
- modules do not need to define it explicitly
- every module gets it tacitly, whether they use pr_debug or not
- it doesn't appear in ``/sys/module/$module/parameters/``
To see it, grep the control file, or inspect ``/proc/cmdline.``
For ``CONFIG_DYNAMIC_DEBUG`` kernels, any settings given at boot-time (or
enabled by ``-DDEBUG`` flag during compilation) can be disabled later via
the debugfs interface if the debug messages are no longer needed::
echo "module module_name -p" > /proc/dynamic_debug/control
Examples
========
::
// 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'
// boot-args example, with newlines and comments for readability
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"
Kernel Configuration
====================
Dynamic Debug is enabled via kernel config items::
CONFIG_DYNAMIC_DEBUG=y # build catalog, enables CORE
CONFIG_DYNAMIC_DEBUG_CORE=y # enable mechanics only, skip catalog
If you do not want to enable dynamic debug globally (i.e. in some embedded
system), you may set ``CONFIG_DYNAMIC_DEBUG_CORE`` as basic support of dynamic
debug and add ``ccflags := -DDYNAMIC_DEBUG_MODULE`` into the Makefile of any
modules which you'd like to dynamically debug later.
Kernel *prdbg* API
==================
The following functions are cataloged and controllable when dynamic
debug is enabled::
pr_debug()
dev_dbg()
print_hex_dump_debug()
print_hex_dump_bytes()
Otherwise, they are off by default; ``ccflags += -DDEBUG`` or
``#define DEBUG`` in a source file will enable them appropriately.
If ``CONFIG_DYNAMIC_DEBUG`` is not set, ``print_hex_dump_debug()`` is
just a shortcut for ``print_hex_dump(KERN_DEBUG)``.
For ``print_hex_dump_debug()``/``print_hex_dump_bytes()``, format string is
its ``prefix_str`` argument, if it is constant string; or ``hexdump``
in case ``prefix_str`` is built dynamically.
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`입니다.
카탈로그와 제어 인터페이스
dynamic-debug-howto.rst:1-75`/proc/dynamic_debug/control`에서 모든 `pr_debug` 호출 지점을 조회하고 파일, 함수, 줄, 모듈, 형식, 클래스로 선택해 실행 중에 출력을 켜거나 끕니다.