"Android Deep Exploration" (Vol. 1) Hal and Driver development

Source: Internet
Author: User

The 10th chapter: the Debugging technology of embedded Linux

For complex Linux drivers and libraries such as HAL, you need to debug them using a variety of methods. For example, setting breakpoints, stepping through code, outputting debugging information, and so on.

First, print kernel debug information: PRINTK

The PRINTK function has been used many times in the previous chapters. The function is similar to the printf function, except that the PRINTK function runs in kernel space and the printf function runs in user space. In other words, Linux kernel programs like Linux drivers can only use the PRINTK function to output the test information.

Second, prevent PRINTK function to reduce Linux drive performance

Although you can easily write messages to a log file or console using the PRINTK function. However, the heavy use of the PRINTK function to frequently manipulate log files or console device files (/dev/console) can severely affect the performance of Linux drivers (because the speed of writing disks is much faster than reading and writing memory), so This requires the Linux driver to use the PRINTK function to output messages only during the development phase, and to remove the PRINTK function that might affect performance when the official friend Linux driver is driven. Of course, the easiest way to think about it is to delete the PRINTK function, or annotate the PRINTK function. But it is troublesome to do so, and it is equally troublesome to add the PRINTK function later. In order to make the output of the PRRINTK function, and it is very convenient to implement, the best way is undoubtedly to use the C language compiler instructions (#if, #else, #endif等).

Iii. 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. All read-write/proc such as operations are read and write to memory. Therefore, reading and writing the/proc file system is much faster than reading/writing the/dev file system. As a result, the/proc file system can also serve as a tool for Linux to interact with user-space programs.

There is a lot of system information that is provided to the outside world through the/proc file system by the kernel space program. For example, the current system's memory resources are taken from the/proc/meminfo file, you can use the following command to view the contents of the/proc/meminfo file.

Several functions are commonly used:

Proc_mkdir

Create_poce_entry

Create_poce_read_entry

Remove_proc_entry

Four, Debugging Tools

The debugging method described earlier is to output the appropriate debug messages, and the developer can then use these messages to determine where the error is. But this way needs to constantly modify the program, constantly output a variety of messages, more trouble. A class of tools is available in Linux systems. These tools allow you to trace the code of the program line-by-row, just as if the visual development tool is step into and step over. These tools contain the GDB, Gdbserver, and debug kernel space programs that are used to debug the user-space program kgdb.

    1. Debugging a user-space program with GDB
    2. Remote debugging of user space programs with Gdbserver
    3. debugging kernel programs remotely with KGDB

Linux kernel debugging has been considered by many people to be very difficult. Most people prefer to use the PRINTK function directly to output debugging information and not to use various commands. (GDB, Gdbserver, KGDB, etc.) for debugging. Because doing so does not necessarily make for more benefits.

Although many debugging techniques are introduced in this chapter, the flexibility to use them is fundamental to debugging. These experiences and techniques need to be constantly understood in practice.

http://www.cnblogs.com/Mr-zsj/

"Android Deep Exploration" (Vol. 1) Hal and Driver development

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.