After reading the tenth chapter of this book, I Learned:
1.PRINTK function: Run in kernel space, Linux driver can only use PRINTK to print kernel debugging information. Function prototype: Asmlikage int printk (const char *fmt). The first parameter represents a format string followed by a mutable parameter, with the first argument being kern_debug and kern_warning, with values of <7>, <4>, and a number representing the log level of the output, which defaults to kern_warning. The function can either write log information to a log file or write log information to the console. The output direction of the PRINTK file output log information.
Query log information: #dmesg or #cat/var/log/syslog or #cat/var/log/messages (low version) or #cat/proc/kmsg (Development board without syslog, messages file)
Log file Many filters display content: #dmesg | Gerp PRINTK or #cat/var/log/syslog | grep PRINTK or #tail–n 10/var/log/syslog
2. The extensive use of the PRINTK function affects Linux driver performance by using the C language to compile instructions (#if, #else, #endif) annotations.
3./proc virtual file system: is a memory mapping, the operation of the/proc is memory read and write, used for kernel space and user space for data interaction, and the device file system/dev similar, read and write faster than/dev.
View current system memory resources: #cat/proc/meminfo
/proc set the action handler function: Proc_dir_entry.read_proc, proc_dir_entry.read_write by function pointer
The Proc_dir_entry struct represents a virtual file or directory, Proc_mkdir,create_proc_entry, create_proc_read_entry,remove_proc_entry functions contain PROC_ Dir_entry the parameters of the struct body.
4.create_proc_read_entry is implemented internally by invoking the Create_proc_entry function, which sets the read and write properties of the file via the mode parameter, such as 0666, which is read-write, and 0444 is-r-r-r--only.
5. You need to delete the virtual directories in the virtual directory before deleting the virtual directory.
6. Debug the User space program with GDB:
Compilation: #gcc –static–g–o gdb_debug/root/drivers/debug/gdb_debug.c
Debug: GdB gdb_debug
Debug command:
List: Displays the 10 rows following the last call to the list command output. List-: Displays the 10 rows preceding the last call to the list command output. List N: Displays 10 rows near the nth row.
Break N: Sets the specified line as a breakpoint. Tbreak N: Sets the specified line as a breakpoint, the breakpoint is used only once, and automatic purge is used.
Clear N: Clears the breakpoint for the specified line.
Run: It can then be passed back to the program being debugged with command-line arguments.
Cont/contiunue: Skips the current breakpoint to continue execution.
Next: Skip this program and continue executing the following statement (step over). Nexti: Stepping through the statement and tracking inside the subroutine (step into).
Print Var_name: View variable values.
7. Remotely debug the user space program with Gdbserver:
① debugging on the Android emulator:
Upload the Gdb_debug to the Android emulator, enter the emulator terminal, enter the Data/local directory, execute: #gdbserver:(native port)./gdb_debug Listener
Then open another Linux terminal, execute #adb–s emulator-5554 forwardtcp: (port number) TCP: (port number forwards the external emulator ports packet to the emulator internal port.
In Linux terminal execution: #arm-none-linux-gnueabi-gdb gdb_debug into the GDB console connection to the Android Simulator: # (GDB) target remote localhost:(port number)
② debugging on the Development Board: (can be connected via port mapping--ip; serial connection)
One, IP connection:
On the Development Board side execution: #gdbserver localhost: (port number)./gbd_debug
On the Linux side GDB console executes: # (GDB) Target rremote (board IP address)./gdb_debug connecting the gdbserver of the Development Board
Second, serial connection:
In the Development Board execution: #gdbserver/dev/(device file for the serial port on the Development Board)./gdb_debug
Linux-side GDB console execution: # (GDB) target remote/dev/ttyusb0 connecting the gdbsserver of the Development Board
The 8.KGDB best kernel debugging tool provides a log output function similar to the PRINTK function, allowing developers to link target devices directly on the PC via GDB.
The 9.KGDB consists of two parts: the KGDB core and a set of connection interfaces. These interfaces currently support serial TTY device connections and Ethernet connections. Serial connection requires kernel parameter KGDBOC specifies the serial port TTY device to be connected, and the Ethernet connection specifies the IP and port number via the kernel parameter kgdboe. The KGDB supports a multi-processing architecture that implements the KGDB core separately for each supported processor architecture.
10.KGDB Remote Debugging Kernel program:
① Configuring the Linux kernel: #make menuconfig into the Linux configuration menu--"Kernel hacking"--"Kgdb:kernel debugger"
② Configuration Kernel Parameters: Enter the Uboot mode during the board boot process, set the Linux kernel boot parameters with the setenv command, and the final saveenv command to save the Reset command to restart the Linux kernel.
③ host Debug Linux kernel: #gdb./vmlinux
"Android Deep Exploration" Reading notes 10