This chapter mainly discusses the debugging technology of Embedded Linux.
(a) Print kernel debug information: PRINTK
The PRINTK function is similar to the printf function, except that the PRINTK function runs in kernel space, and the printf function runs in user space and the PRINTK function is implemented in the Printk.c file.
The PRINTK function is prototyped as follows: Asmlinkage int printk (const char *fmt,...)
The 1th parameter represents a format string followed by a mutable parameter. The first parameter value preceded by an angle bracket contains a number representing the log level of the output, a total of 8 levels, defined in the Linux/kernel.h header file.
Regardless of the message level, all messages sent through the PRINTK function are output to the log file (even if some messages are output to the console, they are also output to the log file).
(ii) Prevent PRINTK functions from reducing Linux drive performance
Although you can easily write messages to a log file or console using the PRINTK function. However, a large number of PRINTK functions are frequently used to log on to the Q or console device files, which can severely affect the performance of Linux drivers. Therefore, this requires the Linux driver to use the PRINTK function to output messages only during the development phase, removing the PRINTK function that may affect performance when the Linux driver is formally released. The best approach is undoubtedly to take advantage of the compiler directives in C. (#if, #else, #endif等). If you do not want to use the PRINTK output message, you will not use the PRINTK output message as long as 1 in # if is changed to 0.
(iii) Data interaction through a virtual file system (/pron)
/pron is used as a tool for data interaction between the kernel space and the user space, and its file system behaves like a device file system (/dev),/pron is a virtual file system, is a memory map, and all read and write/pron are manipulated to read and write memory, so It can also be used as a tool for Linux to interact with user-space programs.
The/pron file system uses Proc_dir_entry.read_proc and Proc_dir_entry.read_write function pointers to set the action handler function of the virtual file in the read-write/pron directory, proc_dir_ Entry struct represents a virtual directory or file
(iv) Commissioning tools
Linux systems provide a class of tools that line up the code of the program, which includes GDB, Gdbserver, and debug kernel space programs for debugging user-space Programs kgdb
GDB Debug User space program
GDB can track programs that debug user space and can only be tested on a PC
2.gdbserver Remote Debugging User space program
Use Gdbserver to test programs that run on boards, phones, or Android emulators. Gdbserver is a service-side program that can run on the arm architecture, office2010, using Gdbserver on the board to open the program to be tested, and then debug on the PC via a serial, wired or wireless network
3.KGDB Remote Debugging Kernel program
The best kernel debugging tool. Provides copy-output functionality similar to the PRINTK function, allowing developers to link target devices directly on the PC via GDB
Android Deep explore HAL and Driver Development-—— 10th Chapter