[Memory leakage] purify tool Introduction

Source: Internet
Author: User

C/C ++ powerful tool for checking memory problems -- Purify

I. Introduction

We all know that software testing (QA-quality assessment, a product-oriented software company) accounts for 30%-50% of the entire software project, but there is such a saying, even the test cases designed by the best test experts cannot thoroughly detect memory problems.

The C/C ++ development team must have experience suffering from memory problems. The memory problems have always been a pain point for C/C ++ developers. Especially when there are more and more programs and classes are inherited and associated, there are more and more memory problems. In many cases, developers may inadvertently introduce memory problems. This is something that is hard to avoid in the C/C ++ world. Even a veteran with more than 10 years of development experience, it is difficult to avoid or eliminate memory problems.

In addition, memory problems are hard to detect. Especially for the memory leak, which ranks first in the memory issue, the probability of Memory Leak appearing in tens of thousands of lines of code is almost 100%, in addition, it is difficult to detect such program errors by General means. It is not as easy to expose as "Wild Pointer" or "array out-of-bounds" (these will cause the program to exit unexpectedly, and memory
No ). When you find that your server programs consume all the memory on the server every other month (or longer, let the server act as a machine regularly every few months, so your program may be in memory leak. At the same time, you will find that you are searching for such memory in 100,000 lines of code.
Leak is no different from a haystack.

So, as described in matrix II, when your program grows bigger and more complex, you will find that the program becomes increasingly out of your control, there are some variables that cause your memory problems and even cause your application to crash. They survive on the edge of the system and you cannot find them. In this case, apart from program testing, there is no other method. Memory in C/C ++ memory problems
Leak, a top killer, is hard to find out the best programmers and the best System Architect. In this regard, we only rely on programs to find such system bugs. This allows us to get twice the result with half the effort.

When we are seeking to solve the memory problem while we are lucky, there are already many small software available for us to choose from, such as mallocdebug, valgrind, kcachegrind, dmalloc, numbench, boundscheck, parasoft, insure ++, etc. Here, I would like to introduce you to purify of rational (huh, it should be IBM), which is the most professional I think, it is also the most powerful memory detection tool.

Purify supports Windows 2000/XP Professional/NT, Sun Solaris, HP-UX, and SGI-IRIX. I don't know if it does not support Linux, but on its website, I didn't see such information, but I heard others say that it supports it, so here I dare not assert that it does not support it. Do you want to say that the software in UNIX does not support Linux? It may be rare.

Below are the purify version I used and the operating system running purify:

> Purify-version

Version 2003.06.00 Solaris 2

> Uname-

SunOS hostname 5.8 Generic_108528-11 sun4u iSCSI sunw, ultra-60

Based on this version, I will introduce you to the powerful features of purify.

II,Purify Introduction

In C/C ++ software development, there is no tool for your applications to avoid the introduction of memory problems, however, we can use tools such as purify to check the memory problems of the programs that have been completed. The strength of purify is that it can locate all the memory problems in the application, and can be used with GDB, DBX, and other debuggers to make your memory errors clear at a glance.

Purify is a run-time tool. That is to say, you can only check whether the program has memory problems under certain running conditions based on the program running conditions, it can locate memory errors in a very complex program, including the multi-process or multi-thread program. It can also be tested.

Purify detects every memory operation in the program, and accurately reports variables and statements in the memory to provide analysis of the cause of the error. Purify mainly detects the following memory errors:

Whether the Array Memory is out-of-range read/write.

Whether the uninitialized memory is used.

Whether to read/write the released memory.

Whether to read or write null pointers.

L memory vulnerability.

In software engineering, in my experience, it is best to use purify during the coding phase to detect memory problems until it is handed over to the tester for testing. Believe me, in a large C/C ++ software product, even if a memory problem is detected, there is still a certain distance from solving it, so in order to make this "distance" not too far, it is best to perform the purify memory detection when the function module is complete.

In general, in software testing, the first thing is the functional testing of the software, then the negative case testing, and then the stress testing. In my personal experience, the use of memory detection tools should be the encoding phase, after the module is merged, and after the program logic test is completed, a memory test will be performed before the product is released.

The purify tool is easy to use. First, you will see two shell scripts: purifyplus_setup.csh (corresponding to C-shell) purifyplus_setup.sh (corresponding to the standard shell) in the purify directory you have installed ). Run these two scripts to set environment parameters for purify, for example:

> Source purifyplus_setup.csh

For your program, you need to use the following:

> Purify CC-g-o myprogram. c

> Purify CC-g-c-o mylib. O mylib. c


That's easy, and you just need to run your program. Purify will submit you a memory issue report list for your analysis. Purify uses OCI (Object
Code insertion) technology, it will insert some of its own functions in your target program, these functions are mainly memory detection statements, these statements will be placed in the program all, before memory operations, once a memory problem is found while the program is running, the statements inserted by purify will report to you. Generally, all memory detection tools work like this. When the program is run by purify compiled, purify will pop up a graphical interface window to report memory problems to you.

When reporting memory problems, purify can point out which part of the source program has a memory problem, but for Memory leakage, it can only point out which part of the problematic memory is, that is, to point out where the memory is allocated, rather than how the memory leakage occurs. This is reasonable, so even if you know that the memory has been leaked, you cannot find out when it happened. Of course, if you want purify to work with GDB, it is not difficult to find the root cause of the problem.

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.