"Linux Kernel Design and Implementation" reading notes-debugging

printk()

printk() can be called "anytime and anywhere", except some places before terminal initialization.

There is also early_printk(), which can be used earlier than printk().

one example:

printk(KERN_INFO "Warp POST OK\n");

The KERN_INFO in front here is the printing level, according to the value of kdbg to determine whether to output.

The printing levels are as follows:

The kernel message output by printk() is stored in a ring buffer, the size is LOG_BUF_LEN.

The user space daemon klogd can obtain kernel messages from the buffer and save them in the system log file through the syslogd daemon.

 

oops

Oops indicates that a serious error occurred in the kernel.

The kernel releases oops, including outputting error information to the terminal, outputting the information stored in the register, and outputting traceback clues for tracking.

After sending oops, the kernel will be in an unstable state.

If oops occurs in the idle process (PID is 0) or init process (PID is 1), the kernel will fall into chaos; if it is another process, the kernel will kill the process and try to continue running.

 

Kernel debugging options configuration

The kernel compilation configuration options have many debugging-related features that can be turned on to assist in problem debugging, such as:

CONFIG_PREEMPT=y
CONFIG_DEBUG_KERNEL=y
CONFIG_KALLSYMS=y
CONFIG_DEBUG_SPINLOCK_SLEEP=y

 

SysRq

SysRq is a standard key on the keyboard.

When the kernel has enabled the SysRq function, you can communicate with the kernel through the SysRq button and complete some debugging work, provided that the kernel is still alive.

SysRq operation:

 

Kernel call

The kernel provides some functions to directly output debugging information, such as (include\asm-generic\bug.h):

#ifndef HAVE_ARCH_BUG
#define BUG() do {} while(0)
#endif
#ifndef HAVE_ARCH_BUG_ON
#define BUG_ON(condition) do { if (condition) ; } while(0)
#endif

and also:

NORET_TYPE void panic(const char * fmt, ...)
void dump_stack(void)

Wait.

 

Guess you like

Origin blog.csdn.net/jiangwei0512/article/details/106153200