CC ++ Memory Question Terrible - Purify (1)

zhaozj2021-02-08  299

C / C Memory Question Terrier - Purify

Chen Hao

I. Introduction

We all know that software testing (called QA-Quality assessment in product-based software) accounts for 30% -50% of the entire software project, but there is such a statement, even the best test expert designed Test cases cannot be thoroughly detected.

The team developed using C / C must have experienced experienced by its memory, and the memory problem has always been the pain of C / C developers. In particular, when the program is increasing, the inheritance of the class is increasing, and the memory problem is more and more. Many times, the developer has brought memory problems when they accidentally. This is a difficult thing to avoid in the C / C world, even if there is more than 10 years of old hands, it is difficult to avoid or eliminate memory issues.

Moreover, the problem of memory is a very difficult, especially for the first Memory Leak, where the memory problem is ranked, the Memory Leak in tens of thousands of lines is almost 100%, and the general means is It is difficult to detect this program error. It is not as easy to expose as "wild pointer" or "array crosses" (these will make the program abnormally exit, and Memory Leak will not). When you find your server-side program, every other month (or a longer time) is exhausted when the memory on the server is exhausted, letting the server will be regularly a few months, then you The program may be Memory Leak, and you will find that this Memory Leak is looking for this MEMORY Leak in hundreds of thousands of lines.

So, as described in the "Hacker II", when your program is getting bigger and more complicated, you will find that the program is increasingly not controlled by your control, there are some problems that make you memory. And even the variables that make your application crash, they survive in the edge of the system, how do you find it, in which case there is no other way in addition to program test programs. For the Memory Leak in the C / C memory problem, it is difficult for the most cattle programmers to add the most cattle system architects. In this regard, we only rely on programs and use procedures. Look for this system's bug. Let us happen to happen.

While we seek to solve memory problems, when we feel lucky, there are many small software for us to choose, such as Mallocdebug, Valgrind, Kcachegrind, Dmalloc, Numega, Boundscheck, Parasoft, Insure , etc. Here, I want to introduce you to the punify (huh, it should be IBM), this is the most professional and most powerful memory detection tool.

The operating system supported by PURIFY has Windows 2000 / XP Professional / NT, Sun Solaris, HP-UX, SGI-IRIX. I don't know if I don't support Linux, but I didn't see such information on my website, but I heard someone to say he supported, so I didn't dare to assert it here. I don't support it. I want to do unix. Can software do not support Linux? Maybe few.

Below, it is the version of the Purify and the operating system running the Purify:

> Purify -VersionVersion 2003.06.00 Solaris 2

> uname -a

Sunos hostname 5.8 generic_108528-11 Sun4u sparc sunw, ULTRA-60

I will introduce you to Purify power based on this version.

Second, PURIFY Introduction

In C / C software development, no tool allows your application to avoid introducing memory issues, but we can use tools such as Purify to check the programs that have been done. Purify's power is to find a comprehensive memory problem in the application and can be used with debuggers such as GDB / DBX to make you a mistake to your memory.

Purify is a Run-Time tool, that is, if only in the program running, check whether the program has memory under certain run conditions according to the operation of the program, it can find in a very complex program. Memory errors, including that multi-process or multi-threaded program, which can also be tested.

PURIFY detects each memory operation in the program and has an error variable and statement that exactly reports memory to provide an analysis of the cause of error. Purify mainly detects the following memory error:

The L array memory is off / written.

l Whether to use unmelted memory.

l Whether to read / write the released memory.

l Whether to read / write the empty pointer.

l Memory vulnerability.

In software engineering, in my experience, it is best to use the PURIFY detection within the coding phase, which is transferred to the test personnel. Please believe me, even in a large C / C software product, even if the memory problem is detected, there is still a certain distance from really solving it, so in order to make this "distance" is not too far, it is best to function. The module is completed when the PURIFY memory detection is performed.

In general, in software testing, the primary is the functional test of the software, and then the reverse case test, and then the pressure test. As far as I personally experience, the phase of using memory detection should be the coding phase, after the module merge, and after the program logic test is complete, it is necessary to do a memory test until the product is released.

To use the PURIFY tool very simple, first you will see two shell scripts on your installed purify: purifyplus_setup.csh (corresponding to c-shell) PurifyPlus_setup.sh (corresponding to standard shell). You first execute these two scripts so that Purify sets some environmental parameters, such as:

> Source PurifyPlus_Setup.csh

For your program, you need to use this:

> purify cc -g -o myprogram myprogram.c

> purify cc -g -c-co mylib.o mylib.c

It's so simple, then you just run your program, Purify will submit a list of memory issues to you for your analysis. Purify uses an OCI (Object Code Insertion technology, which inserts some of its own functions in your target program, which is mainly memory detected statements, which will be placed in all procedures, memory operation Once the memory problem is found during the program, these statements inserted will report to you. In general, all memory detection tools are working like this.

When the program compiled by the PURIFY, the Purify pops up a graphical interface to report the memory problem to you. As follows:

Click on the triangular symbol and will appear more detailed information:

PURIFY When reporting the memory problem, you can point out in which place in the source program has a memory problem. It does not point out how memory leaks occur. This is more reasonable, so even if you know that the memory has leaked, you don't necessarily find when you happen. Of course, if you let Purify use together with GDB, you have to find the root cause of this problem, nor is it difficult.

Next->

(All rights reserved, please indicate the author and the source when reproduced)

转载请注明原文地址:https://www.9cbs.com/read-1158.html

New Post(0)