CN104407858A - CFG (Context Free Grammar)-based abnormal information establishing method - Google Patents

CFG (Context Free Grammar)-based abnormal information establishing method Download PDF

Info

Publication number
CN104407858A
CN104407858A CN201410658922.1A CN201410658922A CN104407858A CN 104407858 A CN104407858 A CN 104407858A CN 201410658922 A CN201410658922 A CN 201410658922A CN 104407858 A CN104407858 A CN 104407858A
Authority
CN
China
Prior art keywords
list
try
node
catch
code
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.)
Granted
Application number
CN201410658922.1A
Other languages
Chinese (zh)
Other versions
CN104407858B (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.)
Suzhou Big Housekeeper Information Technology Co.,Ltd.
Original Assignee
HEFEI COMJAY INFORMATION 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 HEFEI COMJAY INFORMATION TECHNOLOGY Co Ltd filed Critical HEFEI COMJAY INFORMATION TECHNOLOGY Co Ltd
Priority to CN201410658922.1A priority Critical patent/CN104407858B/en
Publication of CN104407858A publication Critical patent/CN104407858A/en
Application granted granted Critical
Publication of CN104407858B publication Critical patent/CN104407858B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention discloses a CFG (Context Free Grammar)-based abnormal information establishing method. The method is applied to a C++ abnormal handling code, and the abnormal handling code comprises a try block and one or more corresponding catch handling blocks. The method is characterized in that initial abnormity information is acquired through a plug-in function provided by a GCC (Gnu C Compiler) in combination with the instrumentation technology of source codes, so that complete abnormity information is obtained. Static analysis is supplemented at one time, and existing abnormal information of programs is identified and constructed, so that preparation is made for static source code analysis.

Description

A kind of abnormal information method for building up based on CFG
Technical field
The invention belongs to C++ static father code analysis field, specifically identify and build the abnormal information of C++ source code, for static father code analysis is prepared.
Background technology
Abnormal mechanism is the very useful characteristic of C++; it relates to a large amount of bottom operation; it is the part comparing indigestibility and grasp in C++ mechanism; the best means of current understanding language itself are compilers; the semantic information that compiler internal maintenance language pack contains; but compiler is in order to the intermediate representation of unified different language, the intermediate code by oneself a set of language definition.CFG is called for short controlling stream graph, the data structure comprising bb fundamental block generated by compiler; As the basis of Compiler Optimization, it presses close to the semanteme of true language (C/C++), and maintain the accessible process flow diagram information of bottom machine, comprise some information of C++ abnormal mechanism, is the basis of source code static semantic analysis.
Because the abnormal information of CFG internal maintenance is not directly perceived, single CFG corresponding from function, do not know the relation between try code block and corresponding catch process code block in the abnormal information of this CFG, the pin function that can not provide simply by GCC compiler in addition obtains complete abnormal information, therefore manual construction based on CFG figure and source code is needed to reduce abnormal information, to prepare for static father code analysis.
The current static father code analysis about C++ abnormal mechanism comprises business tool PC-Lint and coverity, PC-lint provide potential exception error possibility from source code angle, and comprise inconsistent declaration of exception symbol, catch parameter is not situation about quoting; Coverity claims and can find untreated exception in source code abnormal information; The local problem of source code abnormal information just analyzed by these two instruments, but all do not provide how intactly to learn abnormal information, learns that abnormal informations all in program brings difficulty to developer.
Summary of the invention
The present invention is the weak point overcoming prior art existence, a kind of abnormal information method for building up based on CFG is proposed, to the deficiency of compiler pin function can be supplemented, and point out the nest relation in abnormal information between try-catch code block, thus the abnormal information in C++ program must be obtained quickly and accurately.
The present invention is that technical solution problem adopts following technical scheme:
A kind of abnormal information method for building up based on CFG of the present invention is applied in the exception handling code of C++, comprises try block and corresponding one or more catch processing blocks in described exception handling code; Be characterized in, described abnormal information method for building up carries out as follows:
Step 1, to be marked by the starting position of pile pitching method all try blocks in described exception handling code, thus obtain the pitching pile code comprising label information;
Step 2, described pitching pile code to be compiled, obtain the intermediate code represented with CFG, according to described label information in described intermediate code, extract the starting position of all try blocks, thus form the chained list of the try agllutination point composition only comprising described starting position, and be set to the initial chained list of TRY_LIST;
All catch processing blocks in code between step 3, traversal are described, extract according to the starting position of each catch processing block self and end position, thus form the chained list of the catch processing block node composition comprising starting position and end position, and be set to CATCH_LIST chained list;
Step 4, travel through described CATCH_LIST chained list, the numbering subsidiary according to the starting position of catch agllutination point each in described CATCH_LIST chained list, extract all catch processing block nodes with identical numbering and be organized into a child list, thus generating the list of catch processing block, each list node in the list of described catch processing block points to the child list separately with identical numbering;
Step 5, using the numbering in the list of described catch processing block as key word, each list node to be sorted by order from small to large, form the catch processing block list after sequence;
Step 6, each list node in the catch processing block list after described sequence is carried out corresponding with each try agllutination point in the initial chained list of described TRY_LIST successively, make an a list node only corresponding try agllutination point, thus obtain the catch processing block list after correspondence;
Step 7, travel through the catch processing block list after described correspondence, judge the jump information whether having the end position of a catch processing block node to comprise self in described child list, if have, then obtain the end position of the try agllutination point corresponding with described list node according to described jump information; Otherwise, self end position of the try block corresponding with described list node is labeled as mark ∞; Thus obtain all TRY_LIST chained lists comprising starting position and end position, the preliminary abnormal information of try-catch is set up by the catch processing block list after described correspondence and described TRY_LIST chained list;
Step 8, suppose to include n try node in described TRY_LIST chained list, be designated as X={x 1, x 2..., x i..., x n, x irepresent arbitrary try node, 1≤i≤n; By described arbitrary try node x istarting position and end position be designated as respectively with
Step 9, travel through each try node of described TRY_LIST chained list, judge the try node x of current traversal iwhether be empty; If so, then represent that the set membership in described TRY_LIST chained list between try node has been set up, thus make described preliminary abnormal information generate complete abnormal information, and perform step 11; Otherwise, perform step 10;
Step 10, judge try node x jwhether be empty, i+1≤j≤n; If it is empty, then the value of i+1 is assigned to i, and performs step 9; Otherwise, judge try node x iend position whether sign of inclusion ∞, if comprise, is then assigned to i by the value of i+1, and performs step 9; Otherwise, judge try node x jend position whether sign of inclusion ∞, if comprise, is then assigned to j by the value of j+1, and performs step 10; Otherwise, by try node x istarting position and end position respectively with try node x i+1starting position and end position compare successively, if and then by try node x ias try node x jfather node, if and then by try node x jas try node x ifather node; The value of j+1 is assigned to j, and performs step 10;
Step 11, using described complete abnormal information as abnormal information corresponding to described abnormality code.
Compared with prior art, beneficial effect of the present invention is:
The present invention by source code pitching pile, solves the problem can not locating try starting position in the intermediate code represented with CFG; By compiler technologies, maintain the semanteme that source program is complete, maintain an abnormal information accurately; By simple sort algorithm, maintain the relation of top-down try-catch process code in source program; By the relation between different interval starting position and end position, solve the nest relation between try-catch process code; After tested, employing the inventive method can maintain all abnormal informations in C++ program fast and accurately.
Accompanying drawing explanation
Fig. 1 is the exemplary plot of anomaly source code in C++ program of the present invention;
Fig. 2 is the example code figure that the present invention is generated by compiler;
Fig. 3 is the initialized TRY_LIST chained list of the present invention;
Fig. 4 is CATCH_LIST chained list of the present invention;
Fig. 5 is the catch processing block list after the present invention sorts;
Fig. 6 is the final complete abnormal information schematic diagram of the present invention.
Embodiment
The present invention is based on based on the intermediate code that represents by CFG, the abnormality processing portion generated by CFG, reduction generates the abnormality processing data structure of each function, so that execute exception process code section; The pin function provided by GCC compiler obtains preliminary abnormal information, in conjunction with the pitching pile technology of source code, explores abnormal information identification and the method for building up of complete set, to obtain complete abnormal information; Core code is comprised to the acquisition of corresponding relation between try code block and catch code process block in abnormal information, and the nest relation between try-catch code block.The present invention is once supplementing very well static analysis, by identifying and the existing abnormal information of construction procedures, thus obtains possible abnormal generating process, for static father code analysis is prepared before program is run.
Particularly, a kind of abnormal information method for building up based on CFG carries out according to the following procedure:
Step 1, to be marked by the starting position of pile pitching method all try blocks in described exception handling code, thus obtain the pitching pile code comprising label information;
Step 2, described pitching pile code to be compiled, obtain the intermediate code represented with CFG, according to described label information in described intermediate code, extract the starting position of all try blocks, thus form the chained list of the try agllutination point composition only comprising described starting position, and be set to the initial chained list of TRY_LIST;
All catch processing blocks in code between step 3, traversal are described, extract according to the starting position of each catch processing block self and end position, thus form the chained list of the catch processing block node composition comprising starting position and end position, and be set to CATCH_LIST chained list;
Step 4, travel through described CATCH_LIST chained list, the numbering subsidiary according to the starting position of catch agllutination point each in described CATCH_LIST chained list, extract all catch processing block nodes with identical numbering and be organized into a child list, thus generating the list of catch processing block, each list node in the list of described catch processing block points to the child list separately with identical numbering;
Step 5, using the numbering in the list of described catch processing block as key word, each list node to be sorted by order from small to large, form the catch processing block list after sequence;
Step 6, each list node in the catch processing block list after described sequence is carried out corresponding with each try agllutination point in the initial chained list of described TRY_LIST successively, make an a list node only corresponding try agllutination point, thus obtain the catch processing block list after correspondence;
Step 7, travel through the catch processing block list after described correspondence, judge the jump information whether having the end position of a catch processing block node to comprise self in described child list, if have, then obtain the end position of the try agllutination point corresponding with described list node according to described jump information; Otherwise, self end position of the try block corresponding with described list node is labeled as mark ∞; Thus obtain all TRY_LIST chained lists comprising starting position and end position, the preliminary abnormal information of try-catch is set up by the catch processing block list after described correspondence and described TRY_LIST chained list;
Step 8, suppose to include n try node in described TRY_LIST chained list, be designated as X={x 1, x 2..., x i..., x n, x irepresent arbitrary try node, 1≤i≤n; By described arbitrary try node x istarting position and end position be designated as respectively with
Step 9, travel through each try node of described TRY_LIST chained list, judge the try node x of current traversal iwhether be empty; If so, then represent that the set membership in described TRY_LIST chained list between try node has been set up, thus make described preliminary abnormal information generate complete abnormal information, and perform step 11; Otherwise, perform step 10;
Step 10, judge try node x jwhether be empty, i+1≤j≤n; If it is empty, then the value of i+1 is assigned to i, and performs step 9; Otherwise, judge try node x iend position whether sign of inclusion ∞, if comprise, is then assigned to i by the value of i+1, and performs step 9; Otherwise, judge try node x jend position whether sign of inclusion ∞, if comprise, is then assigned to j by the value of j+1, and performs step 10; Otherwise, by try node x istarting position and end position respectively with try node x i+1starting position and end position compare successively, if and then by try node x ias try node x jfather node, if and then by try node x jas try node x ifather node; The value of j+1 is assigned to j, and performs step 10;
Step 11, using described complete abnormal information as abnormal information corresponding to described abnormality code.
In the present embodiment, conveniently set forth, with anomaly source code in simple C++ program for such as shown in Fig. 1; Wherein, line number is shown in a leftmost list; Comprise nested try-catch code block in Fig. 1 structure, in first try code block, comprise second try code block, corresponding two the catch processing blocks of each try code block.
The code of Fig. 1 is the code as do not added italicized item in Fig. 2 by the intermediate code schematic configuration represented with CFG that compiler generates, two parts are divided in fact in this result, top is divided into the normal code block comprising try, and bottom is divided into all catch process code blocks.
First our pack processing contains the normal code block of try, the result that the known compiling of code not adding italicized item from Fig. 2 generates afterwards is without the try key word in source code, therefore pitching pile code in source code is needed, namely by step 1, before (1), (2) position of Fig. 1, following code is inserted: { cout<< " try begin "; , the starting position of this coded representation try, the intermediate code represented with CFG that such Fig. 2 generates after being pitching pile.From Fig. 2, the code of italicized item can identify the starting position of try, and form initialization TRY_LIST chained list, as shown in Figure 3, Fig. 3 is the operating result of step 2.
In Fig. 3 initialization TRY_LIST chained list each node in the numeral number of starting position pitching pile code corresponding place bb block replace (during as occurred " <bb 2> " in fig. 2, the numeral number of expression bb block is 2), prepare for step 10 like this.
Connect catch process code blocks all in lower process Fig. 2, according to step 3, by starting position and the end position of each catch processing block, form the CATCH_LIST chained list as Fig. 4, each node in this chained list attached in starting position numbering (as in fig. 2 the 12nd row occur " _ _ builtin_eh_pointer (2) ", represent subsidiary and be numbered 2), jump information has been attached (if yes at end position, as " goto<bb 5> " that the 17th row in Fig. 2 occurs, represent and jump to the 5th bb block, represent with numeral 5).
Traversal CATCH_LIST chained list, according to step 4 and step 5, with the starting position of node each in CATCH_LIST chained list subsidiary be numbered key word, according to from small to large order, form the catch processing block list after sequence, each node as the list of Fig. 5, catch processing block contains the numbering of band numeral and points to catch processing block child list.
According to step 6, to obtain in fact in Fig. 5 and Fig. 3 one_to_one corresponding between each node.
According to step 7, the end position of each node in initialized TRY_LIST chained list can be determined, and finally define the TRY_LIST chained list comprising starting position and end position.The preliminary abnormal information of try-catch can be defined, as do not added the part of dotted line in Fig. 6 by step 6 and step 7.
According to the formalized description of step 8, step 9 and step 10, relation between the lane place judging try 1 node and try 2 node, due to 3>2 and 55, therefore the father node of try 2 node points to try 1 node, as the dotted portion added in Fig. 6, indicating try 2 node is be nested in try 1 inter-node.
The try code that can be obtained in each try code block corresponding diagram 2 by the starting position of node each in TRY_LIST chained list and end position in Fig. 6 distributes, and the nest relation between try code block; Obtain catch code in each catch process code block corresponding diagram 2 by the list of catch processing block to distribute, result in formation of the finally complete abnormal information that code in Fig. 1 is corresponding.
For C++ code more complicated in actual items, the intermediate code represented with CFG generated after compiler compiling is similar with the result of Fig. 2 in essence on framework.Therefore, comprehensive use is of the present invention based on after the abnormal information method for building up of CFG, after tested, for the engineering code that any C++ develops, can maintain all abnormal informations in C++ program fast and accurately.

Claims (1)

1. based on an abnormal information method for building up of CFG, be applied in the exception handling code of C++, in described exception handling code, comprise try block and corresponding one or more catch processing blocks; It is characterized in that, described abnormal information method for building up carries out as follows:
Step 1, to be marked by the starting position of pile pitching method all try blocks in described exception handling code, thus obtain the pitching pile code comprising label information;
Step 2, described pitching pile code to be compiled, obtain the intermediate code represented with CFG, according to described label information in described intermediate code, extract the starting position of all try blocks, thus form the chained list of the try agllutination point composition only comprising described starting position, and be set to the initial chained list of TRY_LIST;
All catch processing blocks in code between step 3, traversal are described, extract according to the starting position of each catch processing block self and end position, thus form the chained list of the catch processing block node composition comprising starting position and end position, and be set to CATCH_LIST chained list;
Step 4, travel through described CATCH_LIST chained list, the numbering subsidiary according to the starting position of catch agllutination point each in described CATCH_LIST chained list, extract all catch processing block nodes with identical numbering and be organized into a child list, thus generating the list of catch processing block, each list node in the list of described catch processing block points to the child list separately with identical numbering;
Step 5, using the numbering in the list of described catch processing block as key word, each list node to be sorted by order from small to large, form the catch processing block list after sequence;
Step 6, each list node in the catch processing block list after described sequence is carried out corresponding with each try agllutination point in the initial chained list of described TRY_LIST successively, make an a list node only corresponding try agllutination point, thus obtain the catch processing block list after correspondence;
Step 7, travel through the catch processing block list after described correspondence, judge the jump information whether having the end position of a catch processing block node to comprise self in described child list, if have, then obtain the end position of the try agllutination point corresponding with described list node according to described jump information; Otherwise, self end position of the try block corresponding with described list node is labeled as mark ∞; Thus obtain all TRY_LIST chained lists comprising starting position and end position, the preliminary abnormal information of try-catch is set up by the catch processing block list after described correspondence and described TRY_LIST chained list;
Step 8, suppose to include n try node in described TRY_LIST chained list, be designated as X={x 1, x 2..., x i..., x n, x irepresent arbitrary try node, 1≤i≤n; By described arbitrary try node x istarting position and end position be designated as respectively with
Step 9, travel through each try node of described TRY_LIST chained list, judge the try node x of current traversal iwhether be empty; If so, then represent that the set membership in described TRY_LIST chained list between try node has been set up, thus make described preliminary abnormal information generate complete abnormal information, and perform step 11; Otherwise, perform step 10;
Step 10, judge try node x jwhether be empty, i+1≤j≤n; If it is empty, then the value of i+1 is assigned to i, and performs step 9; Otherwise, judge try node x iend position whether sign of inclusion ∞, if comprise, is then assigned to i by the value of i+1, and performs step 9; Otherwise, judge try node x jend position whether sign of inclusion ∞, if comprise, is then assigned to j by the value of j+1, and performs step 10; Otherwise, by try node x istarting position and end position respectively with try node x i+1starting position and end position compare successively, if and then by try node x ias try node x jfather node, if and then by try node x jas try node x ifather node; The value of j+1 is assigned to j, and performs step 10;
Step 11, using described complete abnormal information as abnormal information corresponding to described abnormality code.
CN201410658922.1A 2014-11-18 2014-11-18 A kind of abnormal information method for building up based on CFG Active CN104407858B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410658922.1A CN104407858B (en) 2014-11-18 2014-11-18 A kind of abnormal information method for building up based on CFG

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410658922.1A CN104407858B (en) 2014-11-18 2014-11-18 A kind of abnormal information method for building up based on CFG

Publications (2)

Publication Number Publication Date
CN104407858A true CN104407858A (en) 2015-03-11
CN104407858B CN104407858B (en) 2017-07-11

Family

ID=52645491

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410658922.1A Active CN104407858B (en) 2014-11-18 2014-11-18 A kind of abnormal information method for building up based on CFG

Country Status (1)

Country Link
CN (1) CN104407858B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6412109B1 (en) * 1999-01-29 2002-06-25 Sun Microsystems, Inc. Method for optimizing java bytecodes in the presence of try-catch blocks
CN101063944A (en) * 2006-12-27 2007-10-31 北京大学 Method for recognizing composite conditional branch structure

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6412109B1 (en) * 1999-01-29 2002-06-25 Sun Microsystems, Inc. Method for optimizing java bytecodes in the presence of try-catch blocks
CN101063944A (en) * 2006-12-27 2007-10-31 北京大学 Method for recognizing composite conditional branch structure

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
JANG-WU JOBYEONG-MO CHANG: ""Constructing Control Flow Graph for Java by Decoupling Exception Flow from Normal Flow"", 《COMPUTATIONAL SCIENCE AND ITS APPLICATIONS》 *

Also Published As

Publication number Publication date
CN104407858B (en) 2017-07-11

Similar Documents

Publication Publication Date Title
CN103678118B (en) The compliance detection method of a kind of Java source code and device
Plump The design of GP 2
Antonopoulos et al. Foundations for decision problems in separation logic with general inductive predicates
Meyers et al. ProMoBox: a framework for generating domain-specific property languages
CN107193745B (en) Automated construction method of the PLC program to NuSMV input model
CN105868116A (en) Semantic mutation operator based test case generation and optimization method
Jadon Code clones detection using machine learning technique: Support vector machine
CN103150200A (en) Computer language transformation system and transformation method from C language to MSVL (Modeling, Simulation and Verification Language)
CN105044653A (en) Software conformance detection method for smart electric meters
CN110515838A (en) Method and system for detecting software defects based on topic model
CN108763064A (en) A kind of code tester generation method and device based on black box function and machine learning
Kumar et al. Source code metrics for programmable logic controller (PLC) ladder diagram (LD) visual programming language
Letsholo et al. TRAM: A tool for transforming textual requirements into analysis models
CN104461906A (en) MC/DC coverage rule software testing data generation method based on code conversion
Szárnyas et al. The TTC 2015 Train Benchmark Case for Incremental Model Validation.
CN105224455B (en) A kind of method for automatically generating character string type test case
CN104317711A (en) Path-based method and system for verifying software implementation and design uniformity
Gammaitoni et al. Verifying modelling languages using lightning: a case study
Aubert et al. Unification and logarithmic space
CN109240903A (en) A kind of method and apparatus assessed automatically
CN104407858A (en) CFG (Context Free Grammar)-based abnormal information establishing method
Liu et al. Automatic transformation from formal specifications to functional scenario forms for automatic test case generation
Gransden et al. Mining state-based models from proof corpora
Li et al. Efficient metric vector-based code clone detection using function-calling tree
CN109710538A (en) A kind of static detection method for state related defects in large scale system

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
TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20230605

Address after: 215000 Units 2001, 2008 and 2009, Building 1, Xinneng Business Plaza, No. 99 Si'an Street, Suzhou Industrial Park, Suzhou, China (Jiangsu) Pilot Free Trade Zone

Patentee after: Suzhou Big Housekeeper Information Technology Co.,Ltd.

Address before: 230000 Comprehensive Building A526, Advanced Technology Research Institute, University of Science and Technology of China, at the intersection of Wangjiang West Road and Chuangxin Avenue, Hefei City, Anhui Province

Patentee before: HEFEI COMJAY INFORMATION TECHNOLOGY Co.,Ltd.