CN104407858B - A kind of abnormal information method for building up based on CFG - Google Patents

A kind of abnormal information method for building up based on CFG Download PDF

Info

Publication number
CN104407858B
CN104407858B CN201410658922.1A CN201410658922A CN104407858B CN 104407858 B CN104407858 B CN 104407858B CN 201410658922 A CN201410658922 A CN 201410658922A CN 104407858 B CN104407858 B CN 104407858B
Authority
CN
China
Prior art keywords
try
list
catch
nodes
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.)
Active
Application number
CN201410658922.1A
Other languages
Chinese (zh)
Other versions
CN104407858A (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

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a kind of abnormal information method for building up based on CFG, it is applied in the exception handling code of C++, try blocks and corresponding one or more catch process blocks is included in the exception handling code;It is characterized in that:The pin function provided by GCC compilers obtains preliminary abnormal information, with reference to the pitching pile technology of source code, to obtain complete abnormal information.The present invention is once supplementing very well to static analysis, is that static source code analysis are prepared by identification and the existing abnormal information of construction procedures.

Description

A kind of abnormal information method for building up based on CFG
Technical field
The invention belongs to C++ static state source code analysis field, the abnormal letter of C++ source codes is specifically recognized and built Breath, is that static source code analysis is prepared.
Background technology
Abnormal mechanism is the highly useful characteristics of C++, and it is related to a large amount of bottom operations, is than more difficult in C++ mechanism With the part of grasp, it is currently understood that the best means of language in itself are compilers, the language that compiler internal maintenance language pack contains Adopted information, but compiler is in order to unify the intermediate representation of different language, the intermediate code with a set of language definition of oneself.CFG Abbreviation controlling stream graph, the data structure comprising bb basic blocks generated by compiler;Used as the basis of Compiler Optimization, it presses close to The semanteme of true language (C/C++), maintains the flow chart information that bottom machine is understood that, including C++ abnormal mechanisms some Information, is the basis of source code static semantic analysis.
It is single from the point of view of the corresponding CFG of function, it is unclear that the CFG's is different because the abnormal information of CFG internal maintenances is not directly perceived Relation in normal information between try code blocks and correspondence catch treatment code blocks, in addition can not be simply by GCC compilers The pin function of offer obtains complete abnormal information, it is therefore desirable to which manual construction reduction is different based on CFG figures and source code Normal information, to be prepared for static source code analysis.
The static source code analysis on C++ abnormal mechanisms includes business tool PC-Lint and coverity, PC- at present From the possible including inconsistent declaration of exception symbol of the source code angle potential exception error of offer, catch parameters are not references to lint Situation;Coverity claims to find untreated exception in source code abnormal information;The two instruments are analysis source generation The local problem of code abnormal information, but all do not provide how intactly to learn abnormal information, institute in program is learned to developer Some abnormal informations bring difficulty.
The content of the invention
The present invention is the weak point for overcoming prior art to exist, and proposes a kind of abnormal information method for building up based on CFG, To the deficiency of compiler pin function can be supplemented, and the nest relation in abnormal information between try-catch code blocks is pointed out, So as to must quickly and accurately obtain the abnormal information in C++ programs.
The present invention is adopted the following technical scheme that to solve technical problem:
A kind of abnormal information method for building up based on CFG of the present invention, is applied in C++ exception handling code, described Try blocks and corresponding one or more catch process blocks are included in exception handling code;It is characterized in, the abnormal information is built Cube method is to carry out as follows:
Step 1, by pile pitching method, the starting position of all try blocks is marked in the exception handling code, from And obtain the pitching pile code comprising label information;
Step 2, the pitching pile code is compiled, the intermediate code represented with CFG obtained, in the intermediate code According to the label information, the starting position of all try blocks is extracted, so as to form the try agllutinations for only including the starting position The chained list of point composition, and it is set to the initial chained lists of TRY_LIST;
All catch process blocks in code between step 3, traversal are described, according to the start bit of each catch process blocks itself Put and extracted with end position, so as to form the chain of the catch process blocks node composition comprising starting position and end position Table, and it is set to CATCH_LIST chained lists;
Step 4, the traversal CATCH_LIST chained lists, according to each catch agllutination points in the CATCH_LIST chained lists The subsidiary numbering in starting position, extract all catch process block nodes with identical numbering and be organized into a child list, So as to generate catch process block lists, each the list node in the catch process blocks list is all pointed to each with identical The child list of numbering;
Step 5, using the numbering in the catch process blocks list as keyword to each list node by from small to large Order be ranked up, formed sequence after catch process block lists;
It is step 6, each list node and the TRY_LIST in the catch process block lists after the sequence is initial Each try agllutinations point in chained list carries out correspondence successively so that a list node only corresponds to a try agllutinations point, so as to obtain Catch process block lists after must corresponding to;
Whether catch process block lists after step 7, the traversal correspondence, judge there is a catch in the child list The end position of process block node includes the jump information of itself, if so, then being obtained and the list according to the jump information The end position of the corresponding try agllutinations point of node;Otherwise, the end position of try blocks corresponding with the list node is marked For mark ∞;So as to obtain all TRY_LIST chained lists comprising starting position and end position, by the catch after the correspondence Process block list and the TRY_LIST chained lists set up the preliminary abnormal information of try-catch;
Include n try node in step 8, the hypothesis TRY_LIST chained lists, be designated as X={ x1,x2,…,xi,…, xn, xiRepresent any try nodes, 1≤i≤n;By any try nodes xiStarting position and end position be designated as respectivelyWith
Step 9, each the try node for traveling through the TRY_LIST chained lists, judge the try nodes x of current traversaliWhether be It is empty;If, then it represents that the set membership in the TRY_LIST chained lists between try nodes is set up and is completed, so that described first Step abnormal information generates complete abnormal information, and performs step 11;Otherwise, step 10 is performed;
Step 10, judge try nodes xjWhether it is empty, i+1≤j≤n;If it is empty, then i+1 value is assigned to i, and performed Step 9;Otherwise, try nodes x is judgediEnd positionWhether sign of inclusion ∞, if comprising, the value of i+1 is assigned to i, and Perform step 9;Otherwise, try nodes x is judgedjEnd positionWhether sign of inclusion ∞, if comprising the value of j+1 is assigned to J, and perform step 10;Otherwise, by try nodes xiStarting positionAnd end positionRespectively with try nodes xi+1Beginning PositionAnd end positionIt is compared successively, ifAndThen by try nodes xiAs try nodes xj's Father node, ifAndThen by try nodes xjAs try nodes xiFather node;The value of j+1 is assigned to j, and is held Row step 10;
Step 11, using the complete abnormal information as the corresponding abnormal information of the abnormality code.
Compared with prior art, the beneficial effects of the present invention are:
The present invention to be solved and can not position try starting positions in the intermediate code represented with CFG by source code pitching pile Problem;By compiler technologies, the complete semanteme of source program is maintained, an accurate abnormal information is maintained;By simple Sort algorithm, maintain the relation that top-down try-catch in source program processes code;Pass through different interval beginnings Relation between position and end position, solves the nest relation between try-catch treatment codes;After tested, using this Inventive method can quickly and accurately maintain all abnormal informations in C++ programs.
Brief description of the drawings
Fig. 1 is the exemplary plot of abnormal source code in C++ programs of the present invention;
Fig. 2 is the example code figure that the present invention is generated by compiler;
Fig. 3 is the TRY_LIST chained lists of present invention initialization;
Fig. 4 is CATCH_LIST chained lists of the present invention;
Fig. 5 is the catch process block lists after present invention sequence;
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 CFG is represented, the abnormality processing portion generated by CFG, also primary Into the abnormality processing data structure of each function, to perform exception handling code part;The plug-in unit provided by GCC compilers The preliminary abnormal information of gain-of-function, with reference to the pitching pile technology of source code, explores the abnormal information identification of complete set and builds Cube method, to obtain complete abnormal information;Include in abnormal information at try code blocks and catch codes for core code The acquisition of corresponding relation between reason block, and the nest relation between try-catch code blocks.The present invention is to static analysis Once supplement very well, by identification and the existing abnormal information of construction procedures, so as to obtain possible different before program operation Normal generating process, is that static source code analysis are prepared.
Specifically, a kind of abnormal information method for building up based on CFG is to carry out according to the following procedure:
Step 1, by pile pitching method, the starting position of all try blocks is marked in the exception handling code, from And obtain the pitching pile code for including label information;
Step 2, the pitching pile code is compiled, the intermediate code that acquisition is represented with CFG, in the intermediate code According to the label information, the starting position of all try blocks is extracted, so as to form the try agllutinations for only including the starting position The chained list of point composition, and it is set to the initial chained lists of TRY_LIST;
All catch process blocks in code between step 3, traversal are described, according to the start bit of each catch process blocks itself Put and extracted with end position, so as to form the chain of the catch process blocks node composition comprising starting position and end position Table, and it is set to CATCH_LIST chained lists;
Step 4, the traversal CATCH_LIST chained lists, according to each catch agllutination points in the CATCH_LIST chained lists The subsidiary numbering in starting position, extract all catch process block nodes with identical numbering and be organized into a child list, So as to generate catch process block lists, each the list node in the catch process blocks list is all pointed to each with identical The child list of numbering;
Step 5, using the numbering in the catch process blocks list as keyword to each list node by from small to large Order be ranked up, formed sequence after catch process block lists;
It is step 6, each the list node in the catch process block lists after the sequence is initial with the TRY_LIST Each try agllutinations point in chained list carries out correspondence successively so that a list node only corresponds to a try agllutinations point, so as to obtain Catch process block lists after must corresponding to;
Whether catch process block lists after step 7, the traversal correspondence, judge there is a catch in the child list The end position of process block node includes the jump information of itself, if so, then being obtained and the list according to the jump information The end position of the corresponding try agllutinations point of node;Otherwise, the end position of try blocks corresponding with the list node is marked It is mark ∞;So as to obtain all TRY_LIST chained lists comprising starting position and end position, by the catch after the correspondence Process block list and the TRY_LIST chained lists set up try-catch preliminary abnormal information;
Include n try node in step 8, the hypothesis TRY_LIST chained lists, be designated as X={ x1,x2,…,xi,…, xn, xiRepresent any try nodes, 1≤i≤n;By any try nodes xiStarting position and end position be designated as respectivelyWith
Step 9, each the try node for traveling through the TRY_LIST chained lists, judge the try nodes x of current traversaliWhether be It is empty;If, then it represents that the set membership in the TRY_LIST chained lists between try nodes, which is set up, to be completed, so that described first Walk abnormal information and generate complete abnormal information, and perform step 11;Otherwise, step 10 is performed;
Step 10, judge try nodes xjWhether it is empty, i+1≤j≤n;If it is empty, then the value of i+1 is assigned to i, and is performed Step 9;Otherwise, try nodes x is judgediEnd positionWhether sign of inclusion ∞, if comprising, the value of i+1 is assigned to i, and Perform step 9;Otherwise, try nodes x is judgedjEnd positionWhether sign of inclusion ∞, if comprising the value of j+1 is assigned to J, and perform step 10;Otherwise, by try nodes xiStarting positionAnd end positionRespectively with try nodes xi+1Beginning PositionAnd end positionIt is compared successively, ifAndThen by try nodes xiAs try nodes xj's Father node, ifAndThen by try nodes xjIt is used as try nodes xiFather node;The value of j+1 is assigned to j, and is held Row step 10;
Step 11, using the complete abnormal information as the corresponding abnormal information of the abnormality code.
In the present embodiment, illustrate for convenience, by taking abnormal source code in simple C++ programs as an example as shown in Figure 1;Its In, a leftmost row represent line number;Comprising nested try-catch code blocks in Fig. 1 structures, in first try code block Comprising second try code block, each try code block two catch process blocks of correspondence.
The code of Fig. 1 is as do not added italic in Fig. 2 by the intermediate code schematic configuration represented with CFG that compiler is generated Partial code, two parts are divided into the substantial result, and top is divided into the normal code block comprising try, and bottom is divided into all Catch treatment code block.
We process the normal code block comprising try first, do not add the code of italicized item raw after understanding to compile from Fig. 2 Into result without the try keywords in source code, it is therefore desirable to the pitching pile code in source code, i.e., by step 1, Following code is inserted before Fig. 1 (1), (2) position:{cout<<“trybegin”;, the code represents the starting position of try, So Fig. 2 is the intermediate code represented with CFG generated after pitching pile.The code of italicized item can identify opening for try from Fig. 2 Beginning position, formed initialization TRY_LIST chained lists, as shown in figure 3, Fig. 3 is the operating result of step 2.
Starting position bb blocks where pitching pile code correspondence in each node of TRY_LIST chained lists are initialized in Fig. 3 Numeral numbering replacing (as occurred in fig. 2 "<bb 2>" when, the numeral numbering for representing bb blocks is 2), so for step 10 is done Prepare.
All of catch treatment code block in lower treatment Fig. 2 is connect, according to step 3, by opening for each catch process block Beginning position and end position, form the CATCH_LIST chained lists such as Fig. 4, each node in the chained list is subsidiary in starting position Numbering (such as the 12nd row occurs in fig. 2 " _ _ builtin_eh_pointer (2) ", represents that subsidiary numbering is 2), to terminate Position has attached jump information (if yes, such as " the goto of the 17th row appearance in Fig. 2<bb 5>", expression jumps to the 5th bb Block, is represented with numeral 5).
Traversal CATCH_LIST chained lists, according to step 4 and step 5, with the beginning of each node in CATCH_LIST chained lists The subsidiary numbering in position is keyword, according to from small to large order, formed sequence after catch process block lists, such as Fig. 5, Each node of catch process block lists contains the numbering with numeral and points to catch process block child lists.
According to step 6, substantially obtain in Fig. 5 and Fig. 3 and corresponded between each node.
According to step 7, it may be determined that the end position of each node in the TRY_LIST chained lists of initialization, and ultimately form TRY_LIST chained lists comprising starting position and end position.The preliminary different of try-catch can be formd by step 6 and step 7 The part of dotted line is not added in normal information, such as Fig. 6.
According to the formalized description of step 8, step 9 and step 10, the position area of the nodes of try 1 and the nodes of try 2 is judged Between relation, due to 3>2 and 55, therefore the father node of the nodes of try 2 points to the nodes of try 1, the dotted line part added in such as Fig. 6 Point, it is to be nested in the inter-nodes of try 1 to indicate the nodes of try 2.
Each try code block can be obtained by the starting position of each node in TRY_LIST chained lists and end position in Fig. 6 Try codes distribution in corresponding diagram 2, and the nest relation between try code blocks;Obtain each by the list of catch process blocks Catch codes distribution in catch processing code blocks corresponding diagram 2, it is corresponding final complete result in formation of the code in Fig. 1 Abnormal information.
For C++ codes more complicated in actual items, the middle generation represented with CFG generated after compiler is compiled Code, is similar on framework substantially with Fig. 2 result.Therefore, the comprehensive abnormal information based on CFG using the present invention is built After cube method, after tested, for the engineering code of any C++ exploitations, the institute in C++ programs can quickly and be accurately maintained There is abnormal information.

Claims (1)

1. a kind of abnormal information method for building up based on CFG, is applied in C++ exception handling code, the abnormality processing Try blocks and corresponding one or more catch process blocks are included in code;It is characterized in that, the abnormal information method for building up is Carry out as follows:
Step 1, by pile pitching method, the starting position of all try blocks is marked in the exception handling code, so as to obtain The pitching pile code of label information must be included;
Step 2, the pitching pile code is compiled, obtains the intermediate code represented with CFG, the basis in the intermediate code The label information, extracts the starting position of all try blocks, so as to form the only try agllutinations point group comprising the starting position Into chained list, and be set to the initial chained lists of TRY_LIST;
All catch process blocks in code between step 3, traversal are described, according to the starting position of each catch process blocks itself and End position is extracted, so that the chained list of the catch process blocks node composition comprising starting position and end position is formed, and It is set to CATCH_LIST chained lists;
Step 4, the CATCH_LIST chained lists are traveled through, opened according to each catch agllutinations point in the CATCH_LIST chained lists The subsidiary numbering in beginning position, extracts all catch process block nodes with identical numbering and is organized into a child list, so that Generation catch process block lists, each list node in the catch process blocks list all points to each have identical numbering Child list;
It is step 5, suitable by from small to large to each list node using the numbering in the catch process blocks list as keyword Sequence is ranked up, and forms the catch process block lists after sequence;
Step 6, by each list node in the catch process block lists after the sequence and the initial chained lists of the TRY_LIST In each try agllutinations point carry out correspondence successively so that a list node only corresponds to a try agllutinations point, so as to obtain pair Catch process block lists after answering;
Whether catch process block lists after step 7, the traversal correspondence, judge there is a catch treatment in the child list The end position of agllutination point includes the jump information of itself, if so, then being obtained and the list node according to the jump information The end position of corresponding try agllutinations point;Otherwise, by the end position of try blocks corresponding with the list node labeled as note Number ∞;So as to obtain all TRY_LIST chained lists comprising starting position and end position, by the catch treatment after the correspondence Block list and the TRY_LIST chained lists set up the preliminary abnormal information of try-catch;
Include n try node in step 8, the hypothesis TRY_LIST chained lists, be designated as X={ x1,x2,…,xi,…,xn, xi Represent any try nodes, 1≤i≤n;By any try nodes xiStarting position and end position be designated as respectivelyWith
Each try nodes of step 9, the traversal TRY_LIST chained lists, judge the try nodes x currently traveled throughiWhether it is empty;If It is, then it represents that the set membership in the TRY_LIST chained lists between try nodes, which is set up, to be completed, so that the preliminary exception Information generates complete abnormal information, and performs step 11;Otherwise, step 10 is performed;
Step 10, judge try nodes xjWhether it is empty, i+1≤j≤n;If it is empty, then the value of i+1 is assigned to i, and performs step 9;Otherwise, try nodes x is judgediEnd positionWhether sign of inclusion ∞, if comprising the value of i+1 being assigned into i, and perform Step 9;Otherwise, try nodes x is judgedjEnd positionWhether sign of inclusion ∞, if comprising, the value of j+1 is assigned to j, and Perform step 10;Otherwise, by try nodes xiStarting positionAnd end positionRespectively with try nodes xi+1Starting positionAnd end positionIt is compared successively, ifAndThen by try nodes xiAs try nodes xjFather knot Point, ifAndThen by try nodes xjAs try nodes xiFather node;The value of j+1 is assigned to j, and performs step Rapid 10;
Step 11, using the complete abnormal information as the corresponding abnormal information of the 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 CN104407858A (en) 2015-03-11
CN104407858B true 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 (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101063944A (en) * 2006-12-27 2007-10-31 北京大学 Method for recognizing composite conditional branch structure

Family Cites Families (1)

* 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

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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
"Constructing Control Flow Graph for Java by Decoupling Exception Flow from Normal Flow";Jang-Wu JoByeong-Mo Chang;《Computational Science and Its Applications》;20041231;第106-113页 *

Also Published As

Publication number Publication date
CN104407858A (en) 2015-03-11

Similar Documents

Publication Publication Date Title
CN107832229B (en) NLP-based system test case automatic generation method
CN109783079A (en) A kind of code annotation generation method based on program analysis and Recognition with Recurrent Neural Network
Meyers et al. ProMoBox: a framework for generating domain-specific property languages
Lazar et al. Data-driven program synthesis for hint generation in programming tutors
CN109710741A (en) A kind of mask method the problem of study based on deeply towards online answer platform
Bui et al. Autofocus: interpreting attention-based neural networks by code perturbation
Bentivogli et al. Building Textual Entailment Specialized Data Sets: a Methodology for Isolating Linguistic Phenomena Relevant to Inference.
CN107153606A (en) A kind of program analyzes process visualization method and system
Geng et al. Can chatgpt pass an introductory level functional language programming course?
Brus et al. Design of intelligent system in cartography
CN110222176A (en) A kind of cleaning method of text data, system and readable storage medium storing program for executing
CN106951963A (en) The method and device of a kind of knowledge refinement
CN108037913A (en) A kind of conversion method of xUML4MC models to MSVL LISP program LISPs, computer program
CN105224455B (en) A kind of method for automatically generating character string type test case
André et al. Formalizing non-concurrent UML state machines using colored Petri nets
Teng et al. Sketch2Vis: Generating data visualizations from hand-drawn sketches with deep learning
CN104407858B (en) A kind of abnormal information method for building up based on CFG
CN103810365A (en) Automatic grading method based on hydroelectric simulation training system
Chen et al. Automated Domain Modeling with Large Language Models: A Comparative Study
Rahiman et al. CopyPoppy–A Source Code Plagiarism Detector
CN106354930A (en) Adaptive reconstruction method and system for spacecraft
Pashazadeh Modeling and verification of deadlock potentials of a concurrency control mechanism in distributed databases using hierarchical colored petri net
Blockeel et al. Modeling machine learning and data mining problems with FO (·)
Cai Data-driven supervisory control of discrete-event systems
CN110349477A (en) A kind of misprogrammed restorative procedure, system and server based on history learning behavior

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

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.

TR01 Transfer of patent right