CN105094939B - A kind of software source file Static Analysis Method realized based on the automatic techniques of compiling of Makefile - Google Patents

A kind of software source file Static Analysis Method realized based on the automatic techniques of compiling of Makefile Download PDF

Info

Publication number
CN105094939B
CN105094939B CN201510418857.XA CN201510418857A CN105094939B CN 105094939 B CN105094939 B CN 105094939B CN 201510418857 A CN201510418857 A CN 201510418857A CN 105094939 B CN105094939 B CN 105094939B
Authority
CN
China
Prior art keywords
static analysis
compiling
compiler
source file
compiler directive
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CN201510418857.XA
Other languages
Chinese (zh)
Other versions
CN105094939A (en
Inventor
蔡志旻
沈峰
朱敏杰
姚幸涛
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nanjing Fujitsu Nanda Software Technology Co Ltd
Original Assignee
Nanjing Fujitsu Nanda Software Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nanjing Fujitsu Nanda Software Technology Co Ltd filed Critical Nanjing Fujitsu Nanda Software Technology Co Ltd
Priority to CN201510418857.XA priority Critical patent/CN105094939B/en
Publication of CN105094939A publication Critical patent/CN105094939A/en
Application granted granted Critical
Publication of CN105094939B publication Critical patent/CN105094939B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Stored Programmes (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention discloses a kind of method for the static analysis automation that a large amount of source files in whole software are realized using the automatic technique of compiling of Makefile, the treating method comprises:Parsed by the make orders Makefile project file used to automation compiling;Generate the compiler directive of each source file;The command information of generation is parsed, generates the static analysis order corresponding to current file;Static analysis is carried out to current file, and preserves analysis result;Make command process is returned, compiler directive is performed and compiles current source file.The present invention supports two platforms of WINDOWS and LINUX, the static analysis that engineering source file based on a variety of compilers can be automated, extra study is carried out to static compilation instrument without user, a simple resolve command (LINUX platforms) or one key operation of mouse (WINDOWS platform) only need to be performed, can completion code static analysis work, greatly improve work efficiency the usability with static analysis tools.

Description

A kind of software source file static analysis realized based on the automatic techniques of compiling of Makefile Method
Technical field
The present invention relates to computer realm, more particularly to a kind of static analysis based on the automatic Compilation Methods of Makefile The method of automation.Background technology
In software development, in order to ensure the quality of software, various ways can be generally taken to carry out ensuring for Software Quality: Compiler is analyzed, static analysis, unit testing, functional test, system testing etc..It is well known that problem finds more early, amendment The cost solved the problems, such as is lower.Static analysis is exactly a kind of early period in soft project, what coding can just be implemented after completing Effective means.
The technology of static analysis can generally include:Pretreatment module, Lexical Analysis Module, syntax Analysis Module, control stream There is very big similitude in analysis module and data-flow analysis module, the technology and technique of compiling of these used modules.Source document The parameter used when part is compiled, and the parameter information used is needed during static analysis, it is largely identical.Static analysis Instrument is in order to checking more morphology mistakes, the mistake of grammatical and semantic, it is necessary to obtain each source file it is more more Compiling parameter in detail, to build the more complete model of morphology/syntactic information.
Increasing with the scale of soft project, source file is also more and more;And when each source file compiles Different compiling parameters is had, causes engineering to become increasingly complex.In this case, huge to source file number and parameter is complicated Engineering carries out static analysis, it is necessary to spends very big manpower to carry out information extraction one by one to each source file, carries out one by one static Analysis.
The content of the invention
It is huge the technical problem to be solved in the present invention is existing soft project source file static analysis workload, it is necessary to Spend very big manpower to carry out information extraction one by one to each source file, carry out static analysis one by one, analytic process is complicated, to based on The engineering source file of a variety of compilers can not realize the static analysis of automation.In order to solve the above technical problems, the present invention uses Technical solution be:A kind of software source file Static Analysis Method realized based on the automatic techniques of compiling of Makefile, including Following steps:Step 1:The Makefile project file contents for calling Make instruments used to automation compiling solve Analysis, obtains the compiler directive row of source file to be compiled, intercepts and captures the compiler directive row, and suspend the right of execution of make;Step Two:By the compiler directive formatting lines of intercepting and capturing, compiler directive row is separated into compiler directive and compiling option;Pass through compiler directive It is compiled device matching;Compiler can be matched, parses compiler directive row, obtains static analysis order line;It cannot match Compiler, jump procedure four;Step 3:Right of execution is given to the static analysis order line got, by static analysis Order line performs the static analysis work of compiling source file;After the completion of static analysis, analysis result is output to log files In, and give back Make by authority is performed;Step 4:After Make instruments regain execution authority, continue to execute current Compiler directive row;Step 5:When Make instruments get next compiler directive row, then step 1 is jumped to;Otherwise, jump Go to step 6;Step 6:Staticaanalysis results file format is melted into CSV forms;According to analysis result, there will be problem Parsing item be inserted into the correspondence position of corresponding source file;Source file list of problems during output static analysis.
Present Software Industry mostly manages the engineering of oneself using Makefile, and source file information and compiling information are all It is recorded in Makefile, then using make command tools, just can be automatically compiled.In this case, it is static Analysis tool can obtain the required compiling parameter of static analysis by the parsing to Makefile information;Make works The implementation procedure of tool is parsing Makefile, all source files of management is compiled one by one in a designated order, this mistake Journey carries out automatically;Static analysis tools is also required to analyze each source file one by one, the method for the present invention by using Make instruments and static analysis tools intersect the mode for obtaining right of execution, in make instruments sequentially for each source document While part generates a compiler directive and performs one by one, the work of static analysis is completed.This method is substituted for compiler directive Static analysis order, removes unwanted parameter, while adds the parameter of static analysis needs;Then held one by one by make The order line that row was replaced, static compilation instrument is carried out extra study without user, need to only perform a simple parsing Order(LINUX platforms)Or one key operation of mouse(WINDOWS platforms), you can the static analysis work of completion code, significantly Improve work efficiency the usability with static analysis tools.
Embodiment
The invention discloses one kind to be based on Make orders, realizes that PGRelief static analysis software works are called in automation The method of journey source file.The method of the present invention the treating method comprises:Used to automation compiling by make orders Makefile project files are parsed;Generate the compiler directive of each source file;The command information of generation is parsed, Generate the static analysis order corresponding to current file;Static analysis is carried out to current file, and preserves analysis result;Return Make command process, performs compiler directive and compiles current source file.
The present invention supports two platforms of WINDOWS and LINUX, can be to the engineering source document based on a variety of compilers The static analysis that part is automated, carries out static compilation instrument extra study without user, need to only perform one simply Resolve command(LINUX platforms)Or one key operation of mouse(WINDOWS platforms), you can the static analysis work of completion code Make, greatly improve work efficiency the usability with static analysis tools.The present embodiment is compiled using Linux platforms GCC Device, and by taking 32 Linux systems ppc-linux-gcc as an example:
In the root of C project files, automatic parser tool pgr_make.rb is first carried out, initializes automatic solution The environmental variance needed during analysis;
Then make parsings Makefile is called;
Then, the compiler directive row generation pgr5_ppc-linux-gcc parsing lives parsed are intercepted and captured from make Order row;
Then, pgr5_ppc-linux-gcc order lines are performed, the pgr5 that generation is directed to the compiler directive row is static Analyze order line;
Then, the pgr5 static analysis order lines of generation are performed;
Then, Make instruments are returned, complete the execution of compiler directive row, Make instruments continue to parse Makefile simultaneously repeats to work above, until completing static analysis processing to the source file of whole C engineerings.
After the completion of static analysis is carried out to the source file of whole C engineerings, pgr_make.rb is by analysis result form CSV forms are melted into, facilitate user to check, specific process flow is to carry out as follows:
A C project file to be resolved is selected, compiler ppc-linux-gcc, enters the root of engineering Perform pgr_make.rb;
Pgr_make.rb before static analysis is performed, can initialize one as the entrance to whole engineering static analysis Serial environmental variance, after the completion of environmental variance initialization, starts to perform static analysis work, static analysis flow is as follows:
Step 1, call Make instruments parsing Makefile, obtains the compiler directive row of compiling source file;In Make After instrument has parsed a pending compiler directive row, before this compiler directive row is performed, intercept and capture this and compile life Order row, and the self-defining operation in compilerControl.rb is performed, it can give right of execution to Make after the completion of operation Instrument, is allowed to continue to perform this compiler directive row;Intercept job.c of the Operation Definition in Make instruments of compiler directive row In job_next_command () function in.
Compiler directive row in the Makefile that step 1.1, interception Make instruments have parsed.
Step 1.2, call system () function, performs compilerControl.rb, calling form is system (" compilerControl.rb compiler directives row ");After calling system () function, Make instruments are given authority is performed compilerControl.rb。
Step 2, parsing compiler directive row, obtain PGRelief static analysis order lines.
After step 2.1, compilerControl.rb obtain execution authority, by the compiler directive traveling row format of intercepting and capturing Change;The compiler directive of the primarily discrete compiler directive row of purpose of formatting and compiling option.
Step 2.2, extract compiler directive from formatted compiler directive row, is compiled device matching.If match Ppc-linux-gcc compilers, then continue to perform downwards;If do not match(The compiler be not ppc-linux-gcc or this Order line is not compiler directive row)Then jump to step 4.
The compiler directive ppc-linux-gcc selection pgr_fake script files that step 2.3, basis match.
The entitled pgr5_ppc-linux-gcc of file.
Step 2.4, use the compiler directive ppc- in the former compiler directive row of pgr5_ppc-linux-gcc replacements linux-gcc;Replaced compiler directive is about to as the entrance that static analysis is carried out to compiling source file.
Step 2.5, call system () function to perform the replaced compiler directive row in step 2.4;
After system () function performs, authority will be performed and give pgr5_ppc-linux-gcc.
Step 3, perform PGRelief static analysis order lines
After pgr5_ppc-linux-gcc obtains execution authority, start to perform the static analysis work of compiling source file.
Step 3.1, obtain system macrodefinition.
The method that compiler ppc-linux-gcc obtains system macrodefinition is " ppc-linux-gcc-dM-E Emtpy.c ", wherein empty.c are an empty files;After performing the order, the system macrodefinition of acquisition is saved in static point Analyse in option.
Step 3.2, obtain system header file path.
The method that compiler ppc-linux-gcc obtains system header file path be " ppc-linux-gcc- Vempty.c ", wherein empty.c are an empty files;After performing the order, the system header file path of acquisition is saved in In static analysis option.
Step 3.3, parsing compiling option, filter out what static analysis was not supported, it is not necessary to option, compiler is special Fixed compiling option is equally converted into the identifiable options of PGRelief;Compiling option after parsing is added to static point Analyse in option;The processing of this process depends on existing PGRelief instruments.
Static analysis order is arranged to pgr5 by step 3.4, pgr5_ppc-linux-gcc, and calls itself Exec () function performs static analysis;After the completion of static analysis, analysis result is output in log files, and by right of execution Limit gives back Make instruments.
Step 4, perform compiler directive row.
After Make instruments regain execution authority, continued to execute from job_next_command () function, perform and work as Preceding compiler directive row.
Step 5, after the completion of this compiler task, Make instruments continue parse Makefile files.
When Make instruments get next compiler directive row, then jump to step 1 and continue to execute;Otherwise, jump Step 6 is gone to continue to execute.
Step 6, the analysis of PGRelief staticaanalysis results.
After compiler directive operation all in Makefile, the static analysis of corresponding source file works also Through completing, following pgr_make.rb can be handled staticaanalysis results, to facilitate user to check.
Step 6.1, by staticaanalysis results file format be melted into CSV forms.
Step 6.2, according to analysis result, the parsing item there will be problem is inserted into the correspondence position of corresponding source file.
Source file list of problems during step 6.3, output static analysis.

Claims (4)

  1. A kind of 1. software source file Static Analysis Method realized based on the automatic techniques of compiling of Makefile, it is characterised in that bag Include following steps:
    Step 1:The Makefile project file contents for calling Make instruments used to automation compiling parse, and are treated The compiler directive row of the source file of compiling, intercepts and captures the compiler directive row, and suspends the right of execution of make;
    Step 2:By the compiler directive formatting lines of intercepting and capturing, compiler directive row is separated into compiler directive and compiling option;Pass through Compiler directive is compiled device matching;Compiler can be matched, parses compiler directive row, obtains static analysis order line;No Compiler, jump procedure four can be matched;
    Step 3:Right of execution is given to the static analysis order line got, compiling source file is performed by static analysis order line Static analysis work;After the completion of static analysis, analysis result is output in log files, and is given back authority is performed Make;
    Step 4:After Make instruments regain execution authority, current compiler directive row is continued to execute;
    Step 5:When Make instruments get next compiler directive row, then step 1 is jumped to;Otherwise, step is jumped to Six;
    Step 6:Staticaanalysis results file format is melted into CSV forms;According to analysis result, there will be the parsing item of problem It is inserted into the correspondence position of corresponding source file;Source file list of problems during output static analysis.
  2. A kind of 2. software source file static analysis realized based on the automatic techniques of compiling of Makefile according to claim 1 Method, it is characterised in that the step 1 is further comprising the steps of:
    In the job_next_command () function of step 1.1) in the job.c of Make instruments, interception Make instruments are
    Compiler directive row in the Makefile of parsing;
    Step 1.2) calls system () function, performs compilerControl.rb, calling form is system (" compilerControl.rb compiler directives row ");After calling system () function, Make instruments are given authority is performed compilerControl.rb。
  3. A kind of 3. software source file static state realized based on the automatic techniques of compiling of Makefile according to claim 1 or 2 Analysis method, it is characterised in that the step 2 is further comprising the steps of:
    After step 2.1) compilerControl.rb obtains right of execution, by the compiler directive traveling formatting lines of intercepting and capturing;
    Step 2.2) extracts compiler directive from formatted compiler directive row, is compiled device matching;If match corresponding Compiler, then continue downwards perform;If not matching, step 4 is jumped to;
    Step 2.3):Corresponding pgr_fake script files, the form of the script file are selected according to the compiler directive matched For pgr5_xxx;
    Step 2.4):Compiler directive in compiler directive row is substituted for corresponding pgr_fake scripts;Replace front and rear compiling Order line is as follows:Before replacement:" compiler directive compiling option compiling source file ";After replacement:" pgr5_xxx compiling option compilings source File ";
    Step 2.5):System () function is called to perform the replaced compiler directive row in step 2.4;After the function performs, Right of execution gives pgr5_xxx execution.
  4. A kind of 4. software source file static state realized based on the automatic techniques of compiling of Makefile according to claim 1 or 2 Analysis method, it is characterised in that the step 3 is further comprising the steps of:
    Step 3.1):Obtain system macrodefinition;The mode of system macrodefinition is obtained according to every kind of compiler, obtains corresponding system Macrodefinition, and add it in static analysis option;
    Step 3.2):Acquisition system header file path;The mode in system header file path is obtained according to every kind of compiler, obtains system System header file path, and add it in static analysis option;
    Step 3.3):Parsing compiling option, filter out what static analysis was not supported, it is not necessary to option, compiler is specific Compiling option is equally converted into the static analysis test identifiable option of system, and the compiling option after parsing is added to static state In analysis option;
    Step 3.4):Static analysis order is set as pgr5, and is spliced with acquired static analysis option, creates one A subprocess performs spliced static analysis order line;After the static analysis work of current source file, the log of parsing is defeated Go out to specified file, and right of execution is returned into make instruments.
CN201510418857.XA 2015-07-16 2015-07-16 A kind of software source file Static Analysis Method realized based on the automatic techniques of compiling of Makefile Expired - Fee Related CN105094939B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510418857.XA CN105094939B (en) 2015-07-16 2015-07-16 A kind of software source file Static Analysis Method realized based on the automatic techniques of compiling of Makefile

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510418857.XA CN105094939B (en) 2015-07-16 2015-07-16 A kind of software source file Static Analysis Method realized based on the automatic techniques of compiling of Makefile

Publications (2)

Publication Number Publication Date
CN105094939A CN105094939A (en) 2015-11-25
CN105094939B true CN105094939B (en) 2018-05-01

Family

ID=54575448

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510418857.XA Expired - Fee Related CN105094939B (en) 2015-07-16 2015-07-16 A kind of software source file Static Analysis Method realized based on the automatic techniques of compiling of Makefile

Country Status (1)

Country Link
CN (1) CN105094939B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107015841B (en) * 2017-03-31 2021-01-08 腾讯科技(深圳)有限公司 Preprocessing method for program compiling and program compiling device
CN107832059B (en) * 2017-11-21 2021-02-09 广州视源电子科技股份有限公司 Code static analysis method and device based on Makefile
CN108776569B (en) * 2018-04-20 2021-10-15 贵阳朗玛信息技术股份有限公司 Method and device for modifying compiling option control file
CN111309308A (en) * 2020-02-27 2020-06-19 思客云(北京)软件技术有限公司 Method, device and computer readable storage medium for adding shell to C and C + + compiler
CN111988219B (en) * 2020-08-29 2021-05-25 西南交通大学 Multi-interface multi-protocol wireless gateway system based on 5G and communication method
CN112363729B (en) * 2020-11-23 2024-05-14 北京轩宇信息技术有限公司 Monitoring method and device for mixed compiling of multiple compilers for static analysis
WO2023060525A1 (en) * 2021-10-15 2023-04-20 Huawei Technologies Co.,Ltd. Methods and systems for generating verifiable software releases

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101833500A (en) * 2010-04-07 2010-09-15 南京航空航天大学 Embedded software intelligent testing method based on Agent
CN104484266A (en) * 2014-11-07 2015-04-01 上海交通大学 Lock usage mode automatic static analysis system

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2010231478A (en) * 2009-03-27 2010-10-14 Toshiba Corp Compile method, compile program and semiconductor integrated circuit manufacturing method

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101833500A (en) * 2010-04-07 2010-09-15 南京航空航天大学 Embedded software intelligent testing method based on Agent
CN104484266A (en) * 2014-11-07 2015-04-01 上海交通大学 Lock usage mode automatic static analysis system

Also Published As

Publication number Publication date
CN105094939A (en) 2015-11-25

Similar Documents

Publication Publication Date Title
CN105094939B (en) A kind of software source file Static Analysis Method realized based on the automatic techniques of compiling of Makefile
Binkley et al. ORBS: Language-independent program slicing
CN103577324B (en) Static detection method for privacy information disclosure in mobile applications
Iwamoto et al. Refactoring aspect-oriented programs
CN106503563B (en) Batch leak detection method based on general framework
CN102591777B (en) A kind of unit test code generation method and device
CN106919612B (en) Processing method and device for online structured query language script
US9223570B2 (en) Migration assistance using compiler metadata
CN103150200B (en) A kind of C language is to the conversion method of MSVL language
CN101727316B (en) Parallel program integrated development system suitable for clustering system as well as application implementation method thereof
Ferrari et al. Automating the mutation testing of aspect-oriented Java programs
CN109857641A (en) The method and device of defects detection is carried out to program source file
Baker et al. Automatic generation of conformance tests from message sequence charts
CN104134039A (en) Virus checking and killing method, virus checking and killing client, virus checking and killing server and virus checking and killing system
CN106628250B (en) JL9 aircraft function modularization comprehensive automatic detection system
CN101458633B (en) Method for accessing host program by script program, and system and apparatus thereof
CN106529304B (en) A kind of Android applies concurrent leakage location
CN104572231B (en) Engineering transplantation method between different operation platform and device
CN109542444B (en) JAVA application monitoring method, device, server and storage medium
CN101344855A (en) Control method and apparatus based on specific object in compiled tracing code
CN109857637A (en) A kind of Java language method coverage rate and method input and output statistical method and device based on note
CN114036072B (en) Method and system supporting automatic detection of program defects
CN102968372A (en) Program debugging system with program analysis function
CN104375932B (en) Method and device for analyzing code coverage rate of Java card
CN108897678B (en) Static code detection method, static code detection system and storage device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20180501

Termination date: 20200716

CF01 Termination of patent right due to non-payment of annual fee