Debug makefile and lint software quality software

Source: Internet
Author: User
make -dshould give you more than enough information to debug your makefile.Be warned: it will take some time and effort to analyze the output but loading the output into your favorite editor and doing searches will assist a lot.You can greatly reduce the amount of debugging output if you specify the specific target you‘re interested in. So if you‘re only interested in the dodgy target, instead of just make -d which may make a hundred different things, try:make cleanmake -d dodgy(assuming you have a clean target of course).The make --debug is identical to make -d but you can also specify:make --debug=FLAGSwhere flags can be:a for all debugging (same as make -d and make --debug).b for basic debugging.v for slightly more verbose basic debugging.i for implicit rules.j for invocation information.m for information during makefile remakes.It looks like make --debug=b is the best option for what you need, as shown in the following transcript:[email protected]> cat makefilec:a b    touch c[email protected]> touch a b ; maketouch c[email protected]> makemake: ‘c‘ is up to date.[email protected]> touch a ; make --debug=bGNU Make 3.81Copyright (C) 2006  Free Software Foundation, Inc. Blah, blah, blah.Reading makefiles...Updating goal targets.... Prerequisite ‘a‘ is newer than target ‘c‘.Must remake target ‘c‘.touch cSuccessfully remade target file ‘c‘.

 

Introduction to PC-Lint

Lint tool is a software quality assurance tool. Many large foreign professional software companies, such as Microsoft
Using it as a program check tool, you must ensure that the lint check is passed before the program is integrated into the trial version or delivered for testing.
They require software engineers to turn on all compilation switches when using lint. If you must turn off some switches,
We need to give a legitimate reason to disable these switches.

It can be imagined that if we use lint to check the program during the first compilation After encoding, and ensure that
Except for all lint alarms, we will not encounter so many alarms as we do today. Even today, if we can
It is easy to take some effort to eliminate the lint alarm in the program and maintain the non-alarm status in the future.
The improvement of program quality is self-evident.

PC-LINT is a product of gimpel software, where the content is very extensive and there are 30 options alone
More than 0, involving all aspects of program compilation and syntax usage. This training material aims to guide readers to get started and learn
The basic use of PC-LINT, play a role to attract others, let readers start from here continue to study how to skillfully
Using the various options of PC-LINT enables it to fully serve our development work.

1. Overview
If you want to define the next image point of the lint tool, it is a more rigorous compiler. It not only supports
Check for common syntax errors as in normal compilers, and check that, although fully compliant with syntax requirements,
But it is likely to be a potential and hard-to-find error. See the following example:
1:
2: char * Report (int m, int N, char * P)
3 :{
4: int result;
5: char * temp;
6: Long nm;
7: int I, K, KK;
8: Char name [11] = "Joe jakeson ";
9:
10: Nm = N * m;
11: temp = P = ""? "Null": P;
12: for (I = 0; I 13 :{
14: K ++;
15: Kk = I;
16 :}
17:
18: If (k = 1) Result = Nm;
19: else if (KK> 0) Result = 1;
20: else if (KK <0) Result =-1;
21:
22: If (M = Result) Return (temp );
23: else return (name );
24 :}
The above code is a piece of effective Code Compiled with the general compiler, but there will be a few instructions to compile with the PC-LINT
Alert. First, the NUL character is discarded when the first row assigns a value to the name array. The multiplication accuracy of the second row is inaccurate. The ratio of the second row is 8th.
If there is a problem, the K variable of row 14th is not initialized, The KK of row 15th May not be initialized, and the result of row 22nd is also
It may not be initialized. Row 23rd returns the address of a local object. This code is used in most compilers.
The program can be compiled smoothly. Manual debugging is required to continue searching for errors. If the program is large
Is a cumbersome job, no one can ensure that all of these problems can be identified, but PC-LINT only through a simple
Compilation can be done, obviously saving us a lot of development time.

Next let's take a look at how to install and use PC-lint.
2. How to install PC-LINT
PC-LINT software installation process is more complex, more options, the following according to the installation process, one by one to describe each step
.
0) if it is a zip file, expand the zip installation file to the directory c: \ lint. INS, Enter command prompt, first
Perform directory ing subst g: C: \ lint. INS, then go to G:, and run install. Other steps and the following
The installation of a floppy disk is the same.

1) insert the PC-LINT installation disk in A: Drive, enter a: \> install command, enter the start installation column, press any key to continue,
Go to the PC-LINT introduction bar and press any key to continue.
2) enter the environment selection column, which has three options:
Windows NT/Windows 95
The MS-DOS (DOS extended)
OS/2 (32bit)
If Win95, win97, Win98, or WINNT is installed on your computer, select Windows NT/Windows 95. If
Select dos for only dos.
3) enter the installation directory selection bar. c: \> Lint is recommended. If you do not want to install it in this directory, enter your own
The directory to be installed, and press enter to confirm that if the directory to be installed does not exist, it will prompt you to create this directory
. Here we select c: \> lint
4) Select the disk drive where the installation disk is located. Here, select:
5) determine whether to select multiple compiler or compilation library configurations.

Int, select Yes; otherwise, select No. Then press enter to confirm.
6) A compiler list is displayed. Select your own compiler from this table.
You can select the General compiler: Generic compilers. Press enter to confirm. This option will be reflected in co-
Xxx. LNT file.
7) the installation program will allow you to select a memory model, which can be selected based on the actual size of your program and data zone.
Select an appropriate memory model. If the CPU is a 32-bit 68k series, select 32-bit flat module.
The options of the memory model are reflected in the STD. LNT file.
8) After selecting the memory model, you will see a list of database types. Here, select one or more libraries used for compilation.
This option is reflected in the LIB-xxx.LNT file.
9) then let the author you choose to propose important suggestions for using C ++ programming. After selecting an author
The recommended options will be enabled. The options related to the author selection are reflected in the AU-xxx.LNT file.
10) the next step is to set the directory containing files. There are two options. The first one is to use the environment variable include and environment variable.
In the batch file, set the environment variables separated by semicolons (;). For example, you can set "include = c: \ MRI \ m
Cc68k; D: \ lap \ SRC \ Inc ". The second option is to use the-I option, and the-I option is reflected in the STD. LNT file
The directory is guided by-I and separated by spaces. For example, you can set it to "-ic: \ MRI \ mcc68k-ID: \ lap \ SRC \ Inc ".
". If you select the-I option, the installer will then ask you to enter the directory containing the file.
11) If you have selected multiple compiling environments, you will be asked whether to select more compiling environments.
Yes. The repeat will be performed in step 1. If no is selected, the compiler selection is terminated.
12) Next, an option file options. LNT will be generated to reflect the global compilation information display.
There are two ways to generate parts. One is that the installer will explain several core options one by one and ask if you want to cancel this option.
If you choose to cancel, it will be reflected in the options. LNT file. The specific embodiment is to add
-E, later 13th ~ Step 18 is the process of selecting core options one by one. If you select the second method, the installation file will first
Generate an empty options. LNT file, and add the necessary options when you use it in the future.
13) Whether to disable the Boolean test alarm when assigning values, such as: if (a = f ()){...
14) Whether to disable the mismatch alarm between the signed and unsigned values during the assignment. Normally, this assignment will not
If you choose to disable the alarm information, you can perform the hybrid operation between other types of signed and unsigned volumes.
The police are still open.
15) When an integer is assigned a value shorter than it, the latter will lose its precision. For example, assign an int value
Returns a char. This step allows you to choose whether to disable this type of alarm.
16) whether to turn off the alarm with the left shifting symbol volume. Usually the PC-LINT generates an alarm for all movement with a signed amount, but right
Generally, the shift is determined by the CPU to determine whether to move the symbol bit to the left shift.
To disable the alarm.
17) calling a C function before it is defined or declared does not always produce errors. You can choose whether to disable it here.
This alarm option. This option does not work for C ++ programs.
18) Whether to disable the alarm of "calling a nonexistent function prototype. Some programmers do not want to strictly follow the original function definition.
Convention, but the PC-LINT generates an alarm when calling an undefined function prototype, where you can choose to close
This alarm.
19) after confirming the format of the options. LNT file through the above steps, select the compiling environment. PC-LINT supply
Functions integrated into a variety of development environments, for example, can be integrated in VC, BC, source insight. Assume that I
Select source insight here. After selecting this option, the installer will continue to ask if you want to select other environments.
Select one or more development environments based on your actual application conditions. The selection of development environments is documented in env-xxx.ln
T file.
20) the installer will generate a Lin. BAT file, which is a batch file that runs the PC-LINT to make
The installation program can run in any path. The installation program provides two methods for you to choose from. The first method is to let you choose
N. Bat copy to any path directory. Lin. bat will be copied
The directory you specified. The second method is to generate an lset. BAT file and run it before each use of the PC-LINT
Path, or copy the content of the lset. BAT file to the autoexec. BAT file.
21) after the installation program is executed, the first thing is to execute the lcopy. BAT file in your installation directory. It will
Copy and copy some files to the installation directory, and set the parameters in the file according to your selection during the installation process.

3. Lint a c file
3.1 Use the command line method for lint
If you use the Lin. bat batch processing file for lint, you should first check the content in the batch processing file before lint.
Contains LINT-NT commands and command options that can be modified, increased or decreased as required. We can see that
A std. LNT file is nested in the STD. LNT file, and CO. LNT, options. LNT, and l are nested in the STD. LNT file.
Ib-stl.lnt files, in principle *. LNT files can be unrestricted nesting, such files are generally lint Option
You can modify these files to modify the lint options. The options are executed from left to right. Execute the following:
Command line:
C: \ ABC \ SRC> Lin Alpha. C Beta. C gamma. c
Generally, for a program composed of multiple C modules, it is best to perform a lint check on each C Module unit first, and perform a unit Li
NT can be run as follows:
C: \ ABS \ SRC> Lin-u Alpha. c
Here, "-U" is the unit option. After "-U" is used, you can disable some alarms generated when multiple modules are checked. For example, "the function is not
Use "or" function not defined.
You can also directly use the lint command instead of using Lin. BAT to process files in batches. In dos, the lint command is lint. E.
XE, LINT-NT.EXE in Windows95/NT environment, LINT-OS2.EXE in os2 environment. Use lint directly
Note that you need to set the path of the lint directory before using the command. The best way is to add this path
In the autoexec. BAT file. Other methods are the same as those for batch files. For example:
C: \ ABS \ SRC> lint-NT-ic: \ lint \ STD. LNT-OS (_ lint. tmp) *. c
3.2 use the development environment for lint
You can also use the development environment to execute lint operations. Generally, the development environment supports running executable files, but not necessarily
Run the batch file. The following uses source insight, ultra edit, and msvc 6.0 to illustrate how
Lint in the development environment.
3.2.1 integration in source insight
If you select to use a development environment during the installation process, the installer will generate an en
A file for the v-xxx.lnt, for example, a env-si.lnt file is available when source insight is selected. Open in Editor
This file, in the comments started with this file, explains how to integrate PC-LINT functionality into a development environment, integrated into sou
The process in RCE insight is as follows:
1) Select the "m commands" command item from the Options menu.
2) Enter "PC-Lint" in the name column. In principle, this name can be used as long as you can understand its meaning.
You can.
3) In the run column, enter "C: \ lint-NT-u-ic: \ lint STD env-Si % F", where C: \ Lint is your P
The installation directory of the C-LINT.
4) Select "iconic window" and "Capture output" in the output column ".
5) Select "save files first" in the control column ".
6) in the source links in output column, select "parse links in output", "file, then Lin
E ".
7) in the pattern column, enter "^ \ ([^] * \) \ ([0-9] + \)".
8) Click Add to add the command. For example:
9) in use, open the file for lint under source insight, and open "Custom com" in the Options menu.
In the "command" column, select the "PC-Lint unit check" command to run.
I noticed that the parameters in the "run" column are different from the above prompts. In fact, all my other weird parameters are placed in c: \ lint \ s.
TD. LNT in progress. Please note that no matter how you configure the parameters, do not forget to include the si-env.lnt in your configuration
File. Otherwise, the error information cannot be automatically matched with the program.
For ease of use, you can also configure the menu button to add it to the System Menu 0. This is a general
The source insight application is not described here.
Second, when I use source insight in NT, it seems that the integration fails. The reason is unknown. In the example above
The test is successful under Win 95.
If you want to modify the lint option, you can directly modify it in the run column, or you can edit a *. LNT file in the C: \ lint object
Directory, and add the file name to the run column, which is the same as the command line method.
3.2.2 integration in Ultra Editor
Select menu | advanced | tool configuration..., as shown in:
1) Click "insert ",
2) Enter c: \ lint-nt c: \ lint \ STD. LNT % F in command line :.
3) Fill in: PC-LINT in menu item
4) In command output, select (x) output to list box and (x) Capture output.
5) Click "OK"
The configuration is successfully tested under ue6.0/NT 4.0.
3.2.3 integration in msvc 6.0

// This is easy to use
The basic principles are the same:
1) Select menu | tools | customize .....
2) Select the Tools tab:
3) Click the dotted box above the main dialog box to create a tool item.
4) input name: PC-LINT
(5) input command: C: \ lint \ lint-nt.exe
6) Input arguments: C: \ lint \ STD. LNT $ (filepath) // Note: For STD. LNT is LNT \ env-vc6.lnt
7) Select (x) Use Output Window
8) Close
After that, there is a PC-LINT option under the Tools menu.
The following figure shows the tool configuration in the case of vc6/Win NT 4.0:
3.3lint options
Lint options can be placed in comments, for example:

// Lint option1 option2... optional commentary
The options must be separated by spaces, and the lint command must be in lowercase, followed by (X)/O)
Many lint options include over 300, which can be divided into the following categories:
1) Options for disabling error messages
This option is used to prohibit generation of certain types of error information. The most common options are-E and + e, and-E is to prohibit generation of certain types of errors.
Error message. + E is used to generate a type of error message. You can run msg.exeunder the lintdirectory to get the msg.txt file,
This 5000-row-long file contains all error message numbers and explanations.
-W is not displayed for all alarms greater than the level.
-Wlib () does not display any warning information about the number of library functions that is greater than the level. We can use-wlib (0) to screen
Alert information of all library functions.-wlib (1) only displays syntax errors in library functions.
-Esym (#,) can block an alarm message for a specific symbol.
2) variable type and size options
The size of variable types (such as short integer and integer) varies with the target machine and compilation system,
This option is used to set the variable type size for the target machine. Because the default settings match most compilers
These special settings are usually not needed and are only used in special target machine structures. For example, an m680
00 target machine, whose int and pointer types are usually 32bit, you should use the option:-Si4
-SP4. The current value of these size parameters can be obtained through the help screen. For example, you can enter the following command line:
Lin-Si4-SP4?
3) lengthy information options
Lengthy information refers to some information generated in the lint process related to the compilation process, rather than the real alarm information,
Error information. Whether to generate the information can be determined by the-V and + V Options. + V is to generate this information, and-V is
Close this information. In this set of options, all other options except + V can disable the + V option.
4) Tag options
The options starting with + F, ++ F,-F, and -- F are tag options. Their logical meanings are as follows:
+ F...: Set the flag to 1 and set it to on
-F...: Set the flag to 0 and off.
+ + F...: the flag is increased by 1.
-- F...: Mark minus 1
The next two are used when you want to set a flag to on locally without affecting global settings. For example, you can
Usage:

Int printf ();

There are many types of tag options. The basic meaning is to enable or disable certain types of syntaxes. For example, you can use abbreviations.
Struct name, which allows the use of an unknown consortium. All modules are compiled as C ++.
5) message display options
The message display option defines the message output format. The options include message height, message width, and Message format.
.
6) Other Options
There are many other options, and there are great differences between different types. I will not introduce them here. I suggest you take a look 《
The fifth chapter of PC-Lint provides a detailed description of each option. Lint itself also has some descriptive information, lint-n
T 2> lint.txt and press enter to generate a description file of the lint option.
4. Lint multiple C files under a project
4.1 why lint multiple C files
In the initial stage of program coding, we may only care about the Syntax problems in a single C Module. After the programming stage
A program composed of multiple C modules. We want to know whether multiple modules exist after they are connected.
Syntax problems. At this time, although the compiler can give some warnings, but the PC-LINT connection can give more warnings. And when
We can ensure that several of the modules are relatively stable, while the other modules are still faulty.
Block compilation is connected to a target file. After each modification, the file is compiled separately and then connected to the total target file.
.
4.2 How To lint multiple C files under a project
Like the compilation tool we usually use, the PC-LINT will first compile each c file when compiling and connecting multiple C files
Generate the target file *. lob in the middle, and then connect all the lob files together. Lob is lint object mod
The abbreviation of ule. This file contains all the external information of a C or C ++ module. There are three options for generating lob files
Note: The first is-u. To generate a lob file using lint, you must add the-u option. The second is-zero or
-Zero (500) option. To ensure that the lob file can be generated when a module error exists, you must add this option.
Item; the third type is-oo [(filename)], and filename is the name of the generated lob file. After-oo, add or
If not, the lob file name is the same as the name of the original C Module. For example:
Lint-u Alpha. C-Oo (A1)
The generated lob file name is a1.lob.
Lint-u Alpha. C-oo
The generated lob file name is Alpha. lob.
Lint multiple C modules in a project. Three files are generally required under the user's source program Directory: one option File
(*. LNT), a batch file (*. BAT), and a MAKEFILE file (*. Mak ). The following describes how
Create these files.
1) Option file (*. LNT)
The option file has been mentioned earlier. You can list all the public options you use in each lint C file in this article.
The order in which the options take effect is from left to right and from top to bottom. This type of files can be nested and nested
There is no limit on the number of layers. For example, make. LNT file:
-Ic: \ lint
STD. LNT
+ OS (temp)
-E46
+ VM
-Zero
2) batch file (*. BAT)
Make sure to call the tcmake. EXE and makefile files in the batch file, such as lintma.
Ke. Mak file:
@ Echo lint making 'makelap ':
Tcmake-flintmake. Mak
@ Echo end of making
3) makefile (*. Mak)
The tcmake syntax used by makefile is the same as the syntax format of the MAKEFILE file used for development and compilation.
For example, the following lintmake. Mak file:
Mccpath = c: \ mcc68k
Option =-u make. LNT-oo
Globle = OS. h l2lap. h
Mail_depend = $ (Globle) q931.h mail. h
Lapmain_depend = $ (Globle) l1pubdef. h q931.h mail. h
Lapos_depend = $ (Globle)
Fhdlc1_depend = $ (Globle) cpuhdlc. h bd_prar.h q931.h
OBJ = Mail. lob lapmain. lob lapos. lob fhdlc1.lob
Project. lob: $ (OBJ)
Lint-nt make. LNT-e768-e769 *. lob
Mail. lob: mail. C $ (mail_depend)
Lint-NT $ (option) mail. c
Lapmain. lob: lapmain. C $ (lapmain_depend)
Lint-NT $ (option) lapmain. c
Lapos. lob: lapos. C $ (lapos_depend)
Lint-NT $ (option) lapos. c
Fhdlc1.lob: fhdlc1.c $ (fhdlc1_depend)
Lint-NT $ (option) fhdlc1.c
4.3 simple lint multiple files
Assuming that our project is not complex, we can afford the overhead of lint all the files every time, or
Do not use the above Regular usage. In practice, I found that all *. c files are placed in a lint command
Can complete the purpose of the entire lint project.
For example:
Lint-nt c: \ lint \ STD. LNT allmysource. LNT
Include all the source files in your project in allmysource. LNT:
A1.c
A2.c
A3.c
Note that the-u option is not required in the STD. LNT file. Because we have provided all the information


Wdy9927
Posting time: 18:56:49



Download link

Http://amine.nease.net/down/pclint.zip

Http://xyzboard.com/xyz_soft/PC.Lint.v8.00e.zip

Original: http://harrisonhuanglin.spaces.live.com/blog/cns! 6eeda08e2a9c506d! 158. Entry

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.