- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2020-11-12T10:00:23+09:00","default:honma","honma")
#author("2021-08-27T10:17:01+09:00","default:honma","honma")
* デバッグ出力 [#cfe76e7a]
Documentation/process/coding-style.rst からの抜粋。
13) Printing kernel messages
----------------------------
Kernel developers like to be seen as literate. Do mind the spelling
of kernel messages to make a good impression. Do not use crippled
words like ``dont``; use ``do not`` or ``don't`` instead. Make the messages
concise, clear, and unambiguous.
カーネル開発者は、読み書きができると見なされることを好みます。
良い印象を与えるために、カーネルメッセージのスペルに注意してください。
`` dont``のような不自由な言葉を使用しないでください;代わりに``do not``または``don't``を使用してください。
メッセージを簡潔、明らか、明確にします。
Kernel messages do not have to be terminated with a period.
カーネルメッセージはピリオドで終了する必要はありません。
Printing numbers in parentheses (%d) adds no value and should be avoided.
括弧(%d)で数字を印刷しても価値はないため、避ける必要があります。
There are a number of driver model diagnostic macros in <linux/device.h>
which you should use to make sure messages are matched to the right device
and driver, and are tagged with the right level: dev_err(), dev_warn(),
dev_info(), and so forth. For messages that aren't associated with a
particular device, <linux/printk.h> defines pr_notice(), pr_info(),
pr_warn(), pr_err(), etc.
<linux/device.h>には、メッセージが適切なデバイスとドライバーに一致し、適切なレベルでタグ付けされていることを確認するために使用する必要のあるドライバーモデル診断マクロがいくつかあります:dev_err()、dev_warn()、 dev_info()など。
~<linux/device.h>には、メッセージが適切なデバイスとドライバーに一致し、適切なレベルでタグ付けされていることを確認するために使用する必要のあるドライバーモデル診断マクロがいくつかあります:dev_err()、dev_warn()、 dev_info()など。
特定のデバイスに関連付けられていないメッセージの場合、<linux/printk.h>はpr_notice()、pr_info()、pr_warn()、pr_err() など。
Coming up with good debugging messages can be quite a challenge; and once
you have them, they can be a huge help for remote troubleshooting. However
debug message printing is handled differently than printing other non-debug
messages. While the other pr_XXX() functions print unconditionally,
pr_debug() does not; it is compiled out by default, unless either DEBUG is
defined or CONFIG_DYNAMIC_DEBUG is set. That is true for dev_dbg() also,
and a related convention uses VERBOSE_DEBUG to add dev_vdbg() messages to
the ones already enabled by DEBUG.
優れたデバッグメッセージを思い付くのは非常に難しい場合があります。それらを入手したら、リモートトラブルシューティングに非常に役立ちます。
ただし、デバッグメッセージの出力は、他の非デバッグメッセージの出力とは異なる方法で処理されます。
他のpr_XXX()関数は無条件に出力しますが、pr_debug()は出力しません。 DEBUGが定義されているか、CONFIG_DYNAMIC_DEBUGが設定されていない限り、デフォルトでコンパイルされます。
これはdev_dbg()にも当てはまり、関連する規則ではVERBOSE_DEBUGを使用して、DEBUGによって既に有効になっているメッセージにdev_vdbg()メッセージを追加します。
他のpr_XXX()関数は無条件に出力しますが、pr_debug()は出力しません。 DEBUGが定義されているか、CONFIG_DYNAMIC_DEBUGが設定されていない限り、デフォルトでコンパイルされます。
これはdev_dbg()にも当てはまり、関連する規則ではVERBOSE_DEBUGを使用して、DEBUGによって既に有効になっているメッセージにdev_vdbg()メッセージを追加します。
Many subsystems have Kconfig debug options to turn on -DDEBUG in the
corresponding Makefile; in other cases specific files #define DEBUG. And
when a debug message should be unconditionally printed, such as if it is
already inside a debug-related #ifdef section, printk(KERN_DEBUG ...) can be
used.
多くのサブシステムには、対応するMakefileで-DDEBUGをオンにするKconfigデバッグオプションがあります。その他の場合、特定のファイル#define DEBUG です。
また、デバッグ関連の#ifdefセクション内に既にある場合など、デバッグメッセージを無条件に出力する必要がある場合は、printk(KERN_DEBUG ...)を使用できます。
また、デバッグ関連の#ifdefセクション内に既にある場合など、デバッグメッセージを無条件に出力する必要がある場合は、printk(KERN_DEBUG ...)を使用できます。
** pr_XXX の使い方 [#ua2fd0ac]
include/linux/printk.h に定義されている
|pr_emerg |KERN_EMERG|
|pr_alert |KERN_ALERT|
|pr_crit |KERN_CRIT|
|pr_err |KERN_ERR|
|pr_warning |KERN_WARNING|
|pr_warn |~|
|pr_notice |KERN_NOTICE|
|pr_info |KERN_INFO|
|pr_cont |KERN_CONT|
|pr_devel |KERN_DEBUG|
|pr_debug |~|
** KERN_XXX の定義 [#z3de96a3]
include/linux/kern_levels.h に定義されている。
#highlight(c){{
#define KERN_SOH "\001" /* ASCII Start Of Header */
#define KERN_SOH_ASCII '\001'
#define KERN_EMERG KERN_SOH "0" /* system is unusable */
#define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
#define KERN_CRIT KERN_SOH "2" /* critical conditions */
#define KERN_ERR KERN_SOH "3" /* error conditions */
#define KERN_WARNING KERN_SOH "4" /* warning conditions */
#define KERN_NOTICE KERN_SOH "5" /* normal but significant condition */
#define KERN_INFO KERN_SOH "6" /* informational */
#define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
#define KERN_DEFAULT KERN_SOH "d" /* the default kernel loglevel */
/*
* Annotation for a "continued" line of log printout (only done after a
* line that had no enclosing \n). Only to be used by core/arch code
* during early bootup (a continued line is not SMP-safe otherwise).
*/
#define KERN_CONT KERN_SOH "c"
}}
#highlight(end)
#htmlinsert(amazon_pc.html);