Print kernel debug information: PRINTK
The PRINTK function is prototyped as follows:
asmlinkage int PRINTK (const char * fmt, ...)
The PRINTK file is a simple 4-digit text file that is the default for that file.
6 4 1 7
If you want to modify the contents of the PRINTK file, require that any information be output to the console, you can execute the following command on the Linux terminal.
#echo 8 >/PROC/SYS/KERNEL/PRINTK
The contents of the modified PRINTK file are as follows:
8 4 1 7
Execute a command like the following to compile and install the Printk_demo driver.
# sh build.sh
Prevent PRINTK functions from reducing Linux drive performance:
Modifies the Printk_demo driver code of the upper-section, defines a Pr_debug macro by compiling instructions, and controls whether the PRINTK function is invoked by modifying the conditional value of the compilation instruction.
Data interaction through a virtual file system (/PROC):
In Linux file systems,/proc is often used as a tool for data interaction between kernel space and user space. The/proc file system behaves in a similar manner to the device file system (/dev). /proc is a virtual file system, which means that/proc is not a real file system, but a memory map.
Debugging Tools:
Debug the user space program with GDB, remotely debug the user space program with Gdbserver, and debug the kernel program remotely with KGDB.
When you find that there are too many bugs in a piece of code, it is difficult to find out through the PRINTK function output information, consider using KGDB to locate the bug in step by step mode.
Read "Android Deep Exploration (Volume 1) HAL and drive development" some thoughts 10