Introduction to CPU in Software Debugging

Source: Internet
Author: User

 

2nd of software debugging is supported by CPU debugging, from 2nd ~ Chapter 7 consists of 136 pages, which is the first core part of the book. The main objectives of writing and reading this article are as follows:

    1. Describes the CPU basics that most software engineers need to supplement.
    2. CPU supports core software debugging functions.
    3. The CPU supports the software debugging Extension function.
    4. The CPU is used to debug system faults and problems.
    5. The hardware debugging solution used by modern CPUs and integrated chips.

For the above objectives, Chapter 1 and Chapter 3 meet Objective 1, 4 ~ Chapter 7 meets the other four objectives in sequence. The following describes the key content of each part.

1. Introduce the basic knowledge of the CPU layer that a debugging master should possess. Chapter 2nd and Chapter 3rd specifically serve this purpose. Debugging is like medical practice. A patient is a computer system. To be able to understand the faults of this system and then treat it with treatment or surgery, you must understand the structure of its five-pronged organs and the path of blood circulation, mechanism of interest-bearing operation. To do this, it is important to have a deep understanding of the CPU, the core of the hardware in the computer system. Some people say that CPU is important, but do you need to write this in a software debugging book? Debugging experts still need the basics of mathematics and Chinese. Why don't I open two chapters? This challenge is not unreasonable. Therefore, the author carefully chooses the content to be discussed and strictly controls the length of the article. The selected content must meet three criteria: one is important, the other is common, and the other is closely related to debugging. Therefore, software debugging finally selects the following content:

Concept of instruction sets (section 1): There are several interviews for young peopleProgramEmployee"Which CPU architecture and instruction set are you familiar ?" More than once, some people cannot understand this problem. "Are there many types of CPU (Architecture ?" X86 is too successful! Instructions are the language of the CPU, and understanding the instruction set lays an indispensable foundation for building a software knowledge building.

IA-32 processor (2.2): This is also an important concept that has been misunderstood by Hu omitted. Some people say that they have entered the 64-bit era, but also learn what IA-32? Almost unknown, today most PCs use x64 architecture is only a new operating mode (e.g. IA-32e) in the original 32-bit architecture ). To understand x64, you must first understand the 32-bit situation. In other words, if there is a solid 32-bit foundation, it is easy to understand 64-bit, and it is difficult to pass through the opposite direction. Since more than thirty years of extensive application (from the launch of 80386 in 1985), the impact of IA-32 architecture on computers is too deep, even beyond the CPU, affecting the system bus and peripheralsDesign. Section 2.2 takes a 4-and-a-half page view of each generation of IA-32 CPUs that have been launched, from 386 to today's Core 2 series.

CPU operation mode (section 2.3): Important Concepts frequently encountered.

Register (Section 2.4): All the registers of the ia cpu are divided into five categories: general registers, sign registers, MSR registers, control registers, and other registers. In addition to introducing concepts, this section also aims to be used as a "debugging manual". During debugging, I often turn to these pages to check register bit definitions.

Protection mode (section 2.5-2.7): This is almost a concept I have to ask during my interview. Only by deeply understanding this concept can we deeply understand how today's computer system solves a permanent topic in the computer field-multi-task. Data protection is a major task in the protection mode. virtual memory is the main method to implement this task. The page mechanism is a mechanism that all commercial operating systems depend on today. Understanding the virtual memory and page mechanism is also important for software debugging. If you cannot understand these concepts, they will be confused by the concepts of virtual addresses, linear addresses, physical addresses, and Io addresses. It is also difficult to establish the concept of space in the computer world-memory space, process space, and so on.

Interruptions and exceptions (Chapter 1): These two concepts are related and different. Sometimes it is mixed, so many programmers are ambiguous about it. IA-32 architecture divides exceptions into three types, which are even more unknown. I remember a strange young man wrote an email to me, saying on page 76 of software debugging, "when the CPU encounters an exception, the program pointer is directed to the next instruction that causes the exception. "question:
 
"When a CPU exception occurs, isn't the program pointer pointing to the original command ?"

I wrote back and explained, "the value of the program pointer is different when an exception occurs." He is more confused:

"I still cannot understand. Are there two exceptions ?"

I learned the root cause of his confusion and sent the "exception Classification" Table 3-1 to him. Now he knows it completely. Yes, such an important concept is that our university education (including graduate students in computer science) does not exist at all, nor can we blame individuals completely.

In addition, the "interrupt and exception priority" in section 3.4 is difficult for high-level readers.

Ii. CPU's fundamental support for core software debugging functions, namely Chapter 2. This is one of the core contents of the book. It introduces breakpoint commands, debugging registers, and traps Supporting single-step execution in depth. These three types of support are the three cornerstones of today's debugging technology. Many important debugging functions are built on these three foundations, including setting breakpoints, variable monitoring, various trace execution, debugging information output, and kernel debugging. This chapter consists of 32 pages. Readers should carefully read each page. The analysis of the real-mode Debugger in section 4.4 is also worth reading carefully. It is best to compile the compilation written by Mr. Tim Paterson.CodePrint it out and read it by comparison (link:Http://www.patersontech.com/dos/Docs/Mon_86_1.4a.pdf).LearningCompile and appreciate the Masters' handwriting ".

Iii. Hardware Support for the extended software debugging function provided by the CPU, namely Chapter 1. Chapter 1 introduces the basic support of things that have been shaped since 4th. Software continues to develop, and debugging support cannot keep up with the speed. Therefore, today's debugging technology is often very weak. The branch record and performance monitoring mechanism introduced in chapter 5th can be said to be the most important debugging Support introduced by the new generation processor starting from the Pentium. It is the infrastructure on which most of today's software analysis (profiling) and performance tuning (performance tune) Tools depend.

Iv. Machine check mechanism (Chapter 1 ). This is an error record and reporting mechanism introduced by the Pentium CPU to report hardware problems. This mechanism may be unfamiliar to many software engineers. To understand this mechanism, we can not only learn the basic knowledge of such a CPU layer, but also help to establish the idea of "debuggable", that is, what we will focus on in Article 5th.

V. hardware debugging solution (Chapter 1 ). Software problems are ever-changing. It can be said that it is difficult to find two responsible software problems that are exactly the same. Therefore, different debugging tools and debugging technologies have their applicability and are not omnipotent. For example, some problems are suitable for tracking with user-mode debugging sessions. For some problems, kernel debugging is suitable. For some problems, simply using a software debugger may not work at all. In this case, you need to use the hardware debugging tool to help. JTAG is widely used by CPUs and other large-scale integrated chips.TestAnd debugging scheme, widely used for debugging chip itself, system software, firmware and special complex software problems. To some extent, the hardware tool based on the JTAG technology only provides a "hardware-based" Communication Method for the debugger to access the debugging target. In most cases, you need to rely on software tools such as the software Debugger for various debugging. In other words, most of the time, this debugging method is unified into the software-only debugging solution architecture, so that the debugger can use the familiar debugging function for debugging. For example, Intel's apsaradb for redis tool provides services for windbg in the form of COM components, enabling windbg to debug the kernel using the apsaradb for redis tool. For details, see http://advdbg.com/blogs/advdbg_system/articles/903.

At last, I would like to mention section 2.8-system overview. This section uses one page to describe the hardware architecture of today's PC system, that is, Figure 2-13. It is helpful to understand computer systems to have such a picture in mind. This section describes a series of frequently used terms, such as nanqiao, beiqiao, bus, and chipset. CPU, beiqiao, and nanqiao are currently the three most important chips on the main board. The next-generation chipset to be introduced to the market will integrate the functions of beiqiao into the CPU and nanqiao, the so-called "dual-chip architecture", but this still does not affect the basic concept, for example, the memory controller still exists, but it is moved to the CPU.

In general, the content in Article 1 is quite understandable and the length is not very long. You can read it with a little perseverance. I hope that the readers will have a significant improvement in understanding the CPU and make their hardware more solid. Of course, the most important thing is debugging support. I will talk about it later ......

Download the software debugging ebook:Http://bv.csdn.net/resource/rjts.pdf

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.