CC ++ Memory Question Terrier - Purify (4)

zhaozj2021-02-08  290

7. Purify exit code

Software under UNIX generally provides interfaces with other applications, like the generated text file above, is also a way to provide an interface to other applications. Here, what we have to tell is that the Purify exit code, we know that the program has an exit code to provide information to other programs or operating systems. Programs compiled by Purify, you can tell PURIFY to exit the exit code by specifying the -exit-status parameter, if this parameter value is YES, then use the Purify exit code, if the value is NO, indicating the usage program Exit code.

If we set this: -exit-status = yes, then the Purify exit code is defined:

Memory error type

Exit code (stand or)

Memory access error 0x40 memory leak 0x20 potential memory leak 0x10

With the top table, we can know that when the -exit-status parameter is opened, the exit code of the program is fully taken by the PURIFY. If there is a memory error in the program, the bit corresponding to the exit code will be set to 1, so We can use other programs to call the procedures compiled by Purify and processed according to their exit code.

Eight, purify and shell integration

You can use PURIFY's parameters and information in UNIX's shell environment, and Purify provides things for some wildcards for the shell, as long as you use the -Run-at-EXIT parameter. For example, you have a shell program to copy the files of Purify to other directories, or if you want to have a memory error in the Purify report.

There are two tables below, indicating some of the Purify and Shell interactions:

Information about memory:

Wild string

meaning

% z indicates whether there is a memory error or memory leak. The value is "true" or "false"% X program exit status (if 0, indicating that the program does not call the exit function)% E program number of memory access errors. The total number of errors in% e program. % l The number of bytes leaked in memory. % L The number of bytes of potential memory leaks.

Information about procedures running:

Wild string

meaning

The full path of the% V run program ("/" is replaced with the "_")% v programming of the name% P program for the ID program

In the use of the PURIFY process, there are two ways to pass the PURIFY parameters, one is indicated on the command line. The other is to set up a environment variable related to the PURIFY: PurifyOptions. Now, I will give an example through this environment variable to illustrate the case where the parameters in the above table are in use:

For example, if we do this environment variable: (in the c-shell)

SetENV PURIFYOPTIONS '-Run-At-EXIT = "IF% Z; THEN /

ECHO / "% V:% E ErrorS,% L % l bytes leaked./"; fi "

When we run the procedures compiled by Purify, the following results will appear:

Hello: 2 Errors, 1 10 bytes Leaked.

We can see that because the Hello program is wrong,% z is "true", so the purify executes the echo command, where% V represents the program name (Hello),% e expressed the number of errors (2),% l Represents the number of bytes (1) (1),% L indicating that there is a potential number of memory disconnect by the program (12). Let's take another two examples:

Example 1:

Specifies the parameters of PURIFY: -log-file =. /% V.plog

Example 2:

Specifies the parameters of the PURIFY: -View-file = / home / hchen /% v.pv

Here, these "%" variables are PURIFY supplies to the operating system shell for use by Shell programming.

Nine, filtering the report of PURIFY

If your program is relatively large, the module is also more, sometimes the information is very much, you like a certain code in your program, there is a number of memory errors, so we can use the Purify filter to let Purify only Show a certain type of information, so that we can find problems and troubleshoot problems.

1. Set the information filtering in the purify X-WINDOW, click on the menu "Options" in the graphical interface, "Suppress" dialog box appears, as shown below:

We can see that in the above dialog box, if you filter the PURIFY report information. When we click "Where to support" as long, we will see five options as follows:

L in call chain: Indicates information in a function calling chain.

l in file: Indicates only the information in a file.

l in library: Indicates that only the information is reported in a lib file.

l in class: This is C , indicating that the information reports a certain class.

l Everywhere: Represents information within all ranges.

However, in the graphical interface, PURIFY does not give us a dialog box for selecting a file or lib or class, we can only describe it through its text syntax, let us take a look, filter the text syntax of the Purify report information.

2, we can use the Purify filtering syntax to request PURIFY filter information. And save it in the .purify file, so when we load this file after our Purify starts, you can achieve the purpose of filtering information. Setting the filter information is more powerful than the graphical industry. Let's take a look at the syntax of Suppress:

grammar:

Suppress unsuppress

Among them, keywords in Suppress and unsuppress represent filtration or not filtered separately. indicates the message to be operated, you can use "*" to do a wildcard, represents the call chain of the function, and the function chain of the call is separated, which can also use "*" to do wildcard You can also use "..." to express anything in the middle.

Let's take a few examples:

1) Suppress AB * indicates that the ABR and ABW errors are filtered. 2) Suppress * W indicates that the filtered ABW, FMW, IPW, NPW, SBW, WPW, and ZPW errors.

3) Suppress ABR "libc *" indicates filtering ABR information in all LIB files headed by libc.

4) Suppress ABR SortFunction; sort *; qsort; "libc *" It is indicated that the ABR error is filtered. The filtering range is in the sortfunction and is in a library file at the beginning of libc, its call chain is QSort -> sort * -> sortfunction. In other words, as long as the function in the "libc *" file calls QSort, and QSort calls the function that starts to sort *, and these functions call SortFunction, then in this function chain, the ABR error message is not displayed.

5) Suppress umr tzsetwall; ...; main indicates that the URM information is filtered in the TzSetwall function, as long as the TZSetwall function is indirectly called by the main function, UMR information is not displayed no matter how far.

6) Suppress Fn Test:: Test This is the syntax used in C , indicating that FNH information is filtered in all constructor in class TEST. If you want to specify a specific function, add its parameter type, such as Suppress Fn Test :: Test (const char *).

Note that "..." syntax indicates how far the call chain is. Of course, if you set the parameters "-chain-length = 6", then "..." can only be called, and the 7th floor will don't care.

When starting the PURIFY, we can read the .purify file like this:

% purify -suppression-file-names = ". Purify, .purify.sunos4, /

$ Home / purify_suppressions

PURIFY will find this file in the directory below:

/. purify

/. purify.sunos4

$ Homen / .purify

$ Home / .purify.sunos4

/. purify

/. purify.sunos4

$ Homen / purify_suppresss

<- Previous Next->

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

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

New Post(0)