CN109960529B - Program code repairing method and device - Google Patents

Program code repairing method and device Download PDF

Info

Publication number
CN109960529B
CN109960529B CN201711396845.7A CN201711396845A CN109960529B CN 109960529 B CN109960529 B CN 109960529B CN 201711396845 A CN201711396845 A CN 201711396845A CN 109960529 B CN109960529 B CN 109960529B
Authority
CN
China
Prior art keywords
program code
error
variables
variable
information
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
CN201711396845.7A
Other languages
Chinese (zh)
Other versions
CN109960529A (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.)
Beijing Qihoo Technology Co Ltd
Original Assignee
Beijing Qihoo 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 Beijing Qihoo Technology Co Ltd filed Critical Beijing Qihoo Technology Co Ltd
Priority to CN201711396845.7A priority Critical patent/CN109960529B/en
Publication of CN109960529A publication Critical patent/CN109960529A/en
Application granted granted Critical
Publication of CN109960529B publication Critical patent/CN109960529B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/72Code refactoring
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/75Structural analysis for program understanding

Abstract

The invention discloses a program code repairing method and device, electronic equipment and a computer readable storage medium. The method comprises the following steps: when the program code has an error during operation, acquiring error reporting information; the error reporting information comprises position information and error description information of the operation error of the program code; determining variables needing to be repaired according to the position information and the error description information; selecting predicates of the variables according to the determined variables; and synthesizing the variables and the predicates of the selected variables into conditional statements, and adding the synthesized conditional statements into the program codes. According to the technical scheme, when the program is mistakenly operated, the condition statements are synthesized and then added into the program codes, the repair of the program codes which are mistakenly operated due to the missing of the condition statements can be completed, time and labor consumption of manual repair is avoided, and the speed of repairing the program codes is increased.

Description

Program code repairing method and device
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for repairing a program code, an electronic device, and a computer-readable storage medium.
Background
Whether the operation of the program code of one application program or one system is correct or not is related to the operation of the whole application program or the whole system, and after the operation of the program code is wrong, the program code needs to be repaired as soon as possible according to the reason or the position of the operation mistake of the program. In practical situations, the causes of the program code errors include various causes, for example, the program code operation errors caused by condition loss. When the program code has an error in operation, if manual repair is performed, time and labor are consumed, and the speed of repairing the program code is influenced slowly.
Disclosure of Invention
In view of the above problems, the present invention has been made to provide a method, an apparatus, an electronic device, and a computer-readable storage medium for repairing a program code that overcomes or at least partially solves the above problems.
According to an aspect of the present invention, there is provided a method for repairing program code, wherein the method includes:
when the program code has an error during operation, acquiring error reporting information; the error reporting information comprises position information and error description information of the operation error of the program code;
determining variables needing to be repaired according to the position information and the error description information;
selecting predicates of the variables according to the determined variables;
and synthesizing the variables and the predicates of the selected variables into conditional statements, and adding the synthesized conditional statements into the program codes.
Optionally, the determining, according to the location information and the error description information, a variable that needs to be repaired includes:
when the error description information contains a variable, determining the variable contained in the error description information as a variable needing to be repaired;
and searching all variables appearing in the context codes of the error position of the program code indicated by the position information, sequencing all the searched variables, and determining one or more variables needing to be repaired according to a sequencing result.
Optionally, when the determined variable needing to be repaired is multiple, adding the synthesized conditional statement to the program code includes:
and adding the conditional statements corresponding to each variable into the program codes in sequence according to the sequence in the sequencing result.
Optionally, sequentially adding the conditional statement corresponding to each variable to the program code according to the order in the sorting result includes:
adding a condition statement corresponding to the first variable into the program code according to the sequence in the sequencing result, verifying whether the program code added with the condition statement runs normally, and if so, completing the repair of the program code; if the program code is abnormal, adding the conditional statement corresponding to the second variable into the program code according to the sequence of the ordering, and verifying again; and the like until the program code runs normally.
Optionally, the selecting, according to the determined variable, a predicate of the variable includes:
selecting training data; inputting the selected training data into a naive Bayes model for training to obtain an associated probability model;
acquiring code characteristics of a context of a position indicated by the position information, wherein the position information indicates a program code error;
inputting the determined variables and the obtained code characteristics into an association probability model, and obtaining different predicates output by the association probability model and corresponding association probabilities;
and taking the predicate corresponding to the maximum association probability as the predicate of the variable.
Optionally, the selecting training data includes:
selecting data corresponding to the error information from data of a code base as training data;
and/or the presence of a gas in the atmosphere,
and crawling data corresponding to the error reporting information from the network as training data.
Optionally, the adding the synthesized conditional statement to the program code includes:
adding the synthesized conditional statement to the position before the position indicated by the position information, wherein the program code is in error;
alternatively, the first and second electrodes may be,
and adding the synthesized conditional statement to the statement block before the statement block in which the program code indicated by the position information is in error.
According to another aspect of the present invention, there is provided a program code repair apparatus, wherein the apparatus includes:
the acquisition unit is used for acquiring error reporting information when the program code has an error in operation; the error reporting information comprises position information and error description information of the operation error of the program code;
the variable determining unit is suitable for determining the variable needing to be repaired according to the position information and the error description information;
the predicate selecting unit is suitable for selecting predicates of the variables according to the determined variables;
and the synthesizing unit is suitable for synthesizing the variables and the predicates of the selected variables into conditional statements and adding the synthesized conditional statements into the program codes.
Alternatively,
the variable determining unit is suitable for determining the variable contained in the error description information as the variable needing to be repaired when the variable is contained in the error description information;
and searching all variables appearing in the context codes of the error position of the program code indicated by the position information, sequencing all the searched variables, and determining one or more variables needing to be repaired according to a sequencing result.
Alternatively,
and when a plurality of determined variables needing to be repaired are needed, the synthesis unit is suitable for sequentially adding the conditional statements corresponding to each variable into the program code according to the sequence in the sequencing result.
Alternatively,
the synthesis unit is suitable for adding the condition statement corresponding to the first variable into the program code according to the sequence in the sequencing result, verifying whether the program code added with the condition statement operates normally or not, and completing the repair of the program code if the program code added with the condition statement operates normally; if the program code is abnormal, adding a conditional statement corresponding to the second variable into the program code according to the sequencing order, and verifying again; and repeating the steps until the program code runs normally.
Alternatively,
the predicate selection unit is suitable for selecting training data; inputting the selected training data into a naive Bayes model for training to obtain an associated probability model;
acquiring code characteristics of a context of a position indicated by the position information, wherein the position information indicates a program code error;
inputting the determined variables and the obtained code characteristics into an association probability model, and obtaining different predicates output by the association probability model and corresponding association probabilities thereof;
and taking the predicate corresponding to the maximum association probability as the predicate of the variable.
Alternatively,
the predicate selecting unit is suitable for selecting data corresponding to the error reporting information from data of a code base as training data;
and/or the presence of a gas in the atmosphere,
and crawling data corresponding to the error reporting information from the network as training data.
Alternatively, the first and second liquid crystal display panels may be,
the synthesis unit is suitable for adding the synthesized conditional statement to the position before the position indicated by the position information, wherein the program code is in error;
alternatively, the first and second liquid crystal display panels may be,
and adding the synthesized conditional statement to the statement block before the statement block in which the program code indicated by the position information is in error.
According to still another aspect of the present invention, there is provided an electronic apparatus, wherein the electronic apparatus includes:
a processor; and the number of the first and second groups,
a memory arranged to store computer executable instructions that, when executed, cause the processor to perform a method according to the foregoing.
According to yet another aspect of the invention, there is provided a computer readable storage medium, wherein the computer readable storage medium stores one or more programs which, when executed by a processor, implement the aforementioned method.
According to the technical scheme of the invention, when the program code has an error in operation, error reporting information is acquired; the error reporting information comprises position information and error description information of the operation error of the program code; determining variables needing to be repaired according to the position information and the error description information; selecting predicates of the variables according to the determined variables; and synthesizing the variables and the predicates of the selected variables into conditional statements, and adding the synthesized conditional statements into the program codes. According to the technical scheme, when the program has an error in operation, the condition statements are synthesized and then added into the program codes, so that the repair of the error in operation of the program codes caused by the loss of the condition statements can be completed, the time and labor consumption of manual repair can be avoided, and the speed of repairing the program codes can be increased.
The above description is only an overview of the technical solutions of the present invention, and the present invention can be implemented in accordance with the content of the description so as to make the technical means of the present invention more clearly understood, and the above and other objects, features, and advantages of the present invention will be more clearly understood.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
FIG. 1 shows a flow diagram of a method for repairing program code according to one embodiment of the invention;
FIG. 2 is a schematic diagram showing the construction of a repair apparatus for program code according to an embodiment of the present invention;
FIG. 3 shows a schematic structural diagram of an electronic device according to one embodiment of the invention;
fig. 4 shows a schematic structural diagram of a computer-readable storage medium according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited by the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
Fig. 1 shows a flow chart of a repairing method of a program code according to an embodiment of the invention. As shown in fig. 1, the method includes:
step S110, when the program code has an error in operation, acquiring error reporting information; the error reporting information comprises position information and error description information of the operation error of the program code.
In this embodiment, the program code is a designated section of code, and the program code may be all program codes of a certain application program or program codes for implementing a specific function, or may be program codes of a certain system, and is not limited specifically herein.
In the running process of the program code, a running log of the program code is formed and output, and when the program code runs wrongly, corresponding error reporting information exists in the running log. The error reporting information comprises position information of the operation error of the program code and specific error description information.
And step S120, determining variables needing to be repaired according to the position information and the error description information.
And S130, selecting predicates of the variables according to the determined variables.
The predicate herein can be understood as the value of a variable, for example, if "a >2" is included in the program code, then a is the variable, and 2 is the predicate of the variable a. In this embodiment, predicates of the variables need to be selected according to the determined variables needing to be repaired.
And step S140, synthesizing the variables and predicates of the selected variables into conditional statements, and adding the synthesized conditional statements into program codes.
After the variables and predicates thereof which need to be repaired are selected, the conditional statement can be synthesized, and the synthesized conditional statement is added into the program code, so that the program code is repaired.
In this embodiment, mainly for a program code operation error caused by condition missing, when a synthesized conditional statement is added to a program code, the program code operates normally, which indicates that the repair is completed, and if the program code operates abnormally, the above embodiment may be repeatedly executed until the program code is repaired.
Therefore, according to the embodiment, when the program runs in error, the condition statement is synthesized and added into the program code, the repair of the program code running in error caused by the absence of the condition statement can be completed, the time and the labor consumed by manual repair are avoided, and the speed of repairing the program code is increased.
In an embodiment of the present invention, the determining the variable needing to be repaired according to the location information and the error description information in step S120 includes: when the error description information contains a variable, determining the variable contained in the error description information as a variable needing to be repaired; and searching all variables appearing in the context codes of the position where the program code has errors and indicated by the position information, sequencing all the searched variables, and determining one or more variables needing to be repaired according to a sequencing result.
In practical applications, some error description information in the error report information may include related variables of the program code that has run incorrectly, and in this case, the variables in the error description information may be used as variables that need to be repaired.
Meanwhile, in order to further ensure the repair rate of the program code, all variables appearing in the context of the position where the program code has an error and indicated by the error position information need to be searched, and after all variables are sorted, the variables needing to be repaired are determined according to the sorting result. The ordering here is based on the weight of the variables, e.g., topological ordering.
For example, the context-determining variables at the position where the program runs in error are a, x1, x2, whose relationship to each other is a = x1+ constant; x1= constant x2, it is found that a is the sum of x1 and the constant, x1 is the product of constant x2, and the order of sorting according to the weight of each variable is a > x1> x2.
When determining the variables needing to be repaired, the variables before the sorting test are determined as the variables needing to be repaired, where the number of the determined variables needing to be repaired may be limited according to the actual needs, for example, in the above example, a and x1 may be determined as the variables needing to be repaired.
On the basis of the above example, the error description information further includes a variable b, so that a, b, and x1 can be finally determined as variables that need to be repaired.
Further, in the above embodiment, when the determined variable that needs to be repaired is multiple, adding the synthesized conditional statement to the program code in step S140 includes: and sequentially adding the conditional statements corresponding to each variable into the program codes according to the sequence in the sequencing result.
In this embodiment, when it is determined that a plurality of variables need to be repaired, firstly, a predicate corresponding to each variable needs to be selected according to the determined variables, and then, each variable and the corresponding predicate are respectively synthesized into corresponding conditional statements. When the data are added into the program codes for repair, the data are sequentially added according to the sequence in the sequencing result.
Specifically, the above sequentially adding the conditional statement corresponding to each variable to the program code according to the sequence in the sorting result includes:
adding a condition statement corresponding to the first variable into the program code according to the sequence in the sequencing result, verifying whether the program code added with the condition statement operates normally, and if so, completing the repair of the program code; if the program code is abnormal, adding the conditional statement corresponding to the second variable into the program code according to the sequencing sequence, and verifying again; and the like until the program code runs normally.
For example, if the determined variables needing to be repaired are a, x1 and x2, and the ordering result is that a > x1> x2, then the conditional statement corresponding to the variable a is first added to the program code, and then the program code runs, and if the conditional statement is normal, it indicates that the program code can be repaired by using the conditional statement of the variable a, and then the repair is finished, that is, the conditional statements of x1 and x2 do not need to be added to the program code; if the program code is abnormal, deleting the condition statement corresponding to the variable a from the program code, then adding the condition statement corresponding to the x1 into the program code, then running the program code, and if the program code runs normally, finishing the repair; and if the operation is abnormal, adding the conditional statement corresponding to the variable x2 into the program code, and further improving the repair speed of the program code.
It should be noted that, if the determined variable to be repaired further includes a variable according to the error description information, the conditional statement corresponding to the variable in the error description information may be first added to the program code, the running result of the program code is detected, if the running result is normal, the repair is finished, and if the running result is false, the conditional statements corresponding to the determined other variables are sequentially added to the program code.
In one embodiment of the present invention, the step S130 of selecting the predicate of the variable according to the determined variable includes: selecting training data; inputting the selected training data into a naive Bayes model for training to obtain an associated probability model; acquiring code characteristics of a context of a position indicated by the position information, wherein the position of the program code is wrong; inputting the determined variables and the obtained code characteristics into an association probability model, and obtaining different predicates output by the association probability model and corresponding association probabilities; and taking the predicate corresponding to the maximum association probability as the predicate of the variable.
The naive Bayes method is a classification method based on Bayes theorem and independent hypothesis of characteristic conditions, and the naive Bayes model is a model for sample training by using the naive Bayes method. In this embodiment, the training data is predicate data to which some common variables can be assigned and corresponding program code and its context, which are known. And training the obtained training data by using the naive Bayes model to obtain an association probability model of the variables and the predicates. When the obtained code features and the determined variables are input into the association probability model in the implementation of the embodiment, the association probability model may output different predicates and corresponding association probabilities according to the currently obtained code features and the variables. And when the predicate is selected, taking the predicate corresponding to the maximum association probability as the predicate of the variable.
For example, for the determined predicate a that needs to be repaired, if the association probability of the output predicate 1 is 80%, the association probability of 4 is 95%, and the association probability of 10 is 70%, then 4 is determined as the predicate a.
Preferably, the selecting training data includes: selecting data corresponding to the error information from the data of the code base as training data; and/or crawling data corresponding to the error reporting information from the network as training data.
In this embodiment, the source of the training data may be selected from a network, for example, the related data in the article with missing conditions in the forum of the program code; and/or data accumulated during previous development of the program code.
Since the repair of the program code is performed for a position where the program code is in error, the synthesized conditional statement cannot be added to the program code at will. In one embodiment of the present invention, adding the synthesized conditional statement to the program code in step S140 includes: adding the synthesized conditional statement to the position before the position indicated by the position information, wherein the program code is in error; alternatively, the synthesized conditional statement is added to the statement block before the statement block where the position indicated by the position information where the program code is erroneous exists.
In the present embodiment, the synthesized conditional statement is added before the position indicated by the position information where the program code is erroneous, for example, the previous line of the line of code where the program code is erroneous. Or, if the position of the program code error is in the process of executing a functional or judgment statement, the synthesized conditional statement needs to be added before the statement block where the position of the program code error indicated by the position information is located, so as not to affect the integrity of the statement block and the logic of execution. For example, if the position of the program code error is in the process of the while conditional statement execution, the synthesized conditional statement needs to be added before the whole while conditional statement block in order not to affect the integrity of the while conditional statement.
Fig. 2 is a schematic structural diagram showing a repair apparatus of program codes according to an embodiment of the present invention. As shown in fig. 2, the apparatus 200 for restoring program code includes:
an obtaining unit 210, configured to obtain error reporting information when an error occurs in running of a program code; the error reporting information comprises position information and error description information of the operation error of the program code.
In this embodiment, the program code is a designated section of code, and the program code may be all program codes of a certain application program or program codes for implementing a specific function, or may be program codes of a certain system, and is not limited specifically herein.
In the running process of the program code, a running log of the program code is formed and output, and when the program code runs wrongly, corresponding error reporting information exists in the running log. The error reporting information contains the position information of the operation error of the program code and the specific error description information.
And a variable determining unit 220 adapted to determine a variable to be repaired according to the location information and the error description information.
And a predicate selection unit 230 adapted to select predicates of the variables according to the determined variables.
A predicate herein may be understood as a value of a variable, e.g., including "a >2" in the program code, then a is a variable and 2 is the predicate of the variable a. In this embodiment, predicates of the variables need to be selected according to the determined variables needing to be repaired.
And the synthesizing unit 240 is suitable for synthesizing the variables and predicates of the selected variables into conditional statements and adding the synthesized conditional statements into the program codes.
After the variables to be repaired and the predicates thereof are selected, the conditional statements can be synthesized, and the synthesized conditional statements are added to the program codes, so that the program codes are repaired.
In this embodiment, mainly for a program code operation error caused by condition missing, when a synthesized conditional statement is added to a program code, the program code operates normally, which indicates that the repair is completed, and if the program code operates abnormally, the above embodiment may be repeatedly executed until the program code is repaired.
Therefore, according to the embodiment, when the program runs in error, the condition statement is synthesized and added into the program code, the repair of the program code running in error caused by the absence of the condition statement can be completed, the time and the labor consumed by manual repair are avoided, and the speed of repairing the program code is increased.
In an embodiment of the present invention, the variable determining unit 220 is adapted to determine, when the variable is included in the error description information, the variable included in the error description information as a variable that needs to be repaired; and searching all variables appearing in the context codes of the position where the program code has errors and indicated by the position information, sequencing all the searched variables, and determining one or more variables needing to be repaired according to a sequencing result.
In practical applications, some error description information in the error report information may include related variables of the program code that has run incorrectly, and in this case, the variables in the error description information may be used as variables that need to be repaired.
Meanwhile, in order to further ensure the program code repair rate, all variables appearing need to be searched from the context of the position where the program code makes an error, which is indicated by the error position information, and after all variables are sorted, the variables needing to be repaired are determined according to the sorting result. The ordering here is based on the weight of the variables, e.g., topological ordering.
For example, the context-determining variables at the position where the program runs in error are a, x1, x2, whose relationship to each other is a = x1+ constant; x1= constant x2, it is understood that a is the sum of x1 and the constant, x1 is the product of constant x2, and the order of sorting is a > x1> x2 according to the weight of each variable.
When determining the variables needing to be repaired, the variables before the sorting test are determined as the variables needing to be repaired, where the number of the determined variables needing to be repaired may be limited according to the actual needs, for example, in the above example, a and x1 may be determined as the variables needing to be repaired.
On the basis of the above example, the error description information further includes a variable b, so that a, b, and x1 can be finally determined as variables that need to be repaired.
Further, when the variable determining unit 220 determines that there are a plurality of variables needing to be repaired, the synthesizing unit 240 is adapted to sequentially add the conditional statements corresponding to each variable to the program code in the order in the sorting result.
In this embodiment, when it is determined that a plurality of variables need to be repaired, firstly, a predicate corresponding to each variable needs to be selected according to the determined variables, and then, each variable and the corresponding predicate are respectively synthesized into corresponding conditional statements. When the data is added into the program codes for repairing, the data is sequentially added according to the sequence in the sequencing result.
Specifically, the synthesizing unit 240 is adapted to add a conditional statement corresponding to the first variable to the program code according to the order in the sorting result, verify whether the program code after adding the conditional statement operates normally, and if so, complete the repair of the program code; if the program code is abnormal, adding the conditional statement corresponding to the second variable into the program code according to the sequence, and verifying again; and the like until the program code runs normally.
For example, if the determined variables needing to be repaired are a, x1 and x2, and the ordering result is that a > x1> x2, then the conditional statement corresponding to the variable a is first added to the program code, and then the program code runs, if the conditional statement is normal, it indicates that the program code can be repaired by using the conditional statement of the variable a, and then the repair is finished, that is, the conditional statements of x1 and x2 do not need to be added to the program code; if the program code is abnormal, deleting the conditional statement corresponding to the variable a from the program code, then adding the conditional statement corresponding to the x1 into the program code, then running the program code, and if the program code is normal, finishing the repair; and if the operation is abnormal, adding the conditional statement corresponding to the variable x2 into the program code, and further improving the repair speed of the program code.
It should be noted that, if the determined variable to be repaired further includes a variable according to the error description information, the conditional statement corresponding to the variable in the error description information may be first added to the program code, the running result of the program code is detected, if the running result is normal, the repair is finished, and if the running result is false, the conditional statements corresponding to the determined other variables are sequentially added to the program code.
In one embodiment of the invention, the predicate extraction unit 230 is adapted to extract training data; inputting the selected training data into a naive Bayes model for training to obtain an associated probability model; acquiring code characteristics of a context of a position indicated by the position information, wherein the position of the program code is wrong; inputting the determined variables and the obtained code characteristics into an association probability model, and obtaining different predicates output by the association probability model and corresponding association probabilities; and taking the predicate corresponding to the maximum association probability as the predicate of the variable.
The naive Bayes method is a classification method based on Bayes theorem and independent hypothesis of characteristic conditions, and the naive Bayes model is a model for sample training by using the naive Bayes method. In this embodiment, the training data is predicate data to which some common variables can be assigned and corresponding program code and its context, which are known. And training the obtained training data by using a naive Bayes model to obtain an association probability model of the variables and the predicates. When the obtained code features and the determined variables are input into the association probability model in the implementation of the embodiment, the association probability model may output different predicates and corresponding association probabilities according to the currently obtained code features and the variables. And when the predicate is selected, taking the predicate corresponding to the maximum association probability as the predicate of the variable.
For example, for the determined predicate a that needs to be repaired, if the association probability of the output predicate 1 is 80%, the association probability of 4 is 95%, and the association probability of 10 is 70%, then 4 is determined as the predicate a.
Specifically, the predicate selection unit 230 is adapted to select data corresponding to the error reporting information from data in the code library as training data; and/or crawling data corresponding to the error reporting information from the network as training data.
In this embodiment, the source of the training data may be selected from a network, for example, the related data in the article with missing conditions in the forum of the program code; and/or data accumulated during previous development of the program code.
Since the repair of the program code is performed for a position where the program code is erroneous, the synthesized conditional statement cannot be added to the program code at will.
In an embodiment of the present invention, the synthesis unit 240 is adapted to add the synthesized conditional statement to a position before the position indicated by the position information where the program code is in error; alternatively, the synthesized conditional statement is added to the statement block before the statement block where the position indicated by the position information where the program code is erroneous exists.
In the present embodiment, the synthesized conditional statement is added before the position indicated by the position information where the program code is erroneous, for example, the previous line of the line of code where the program code is erroneous. Or, if the position of the program code error is in the process of executing a functional or judgment statement, the synthesized conditional statement needs to be added before the statement block where the position of the program code error indicated by the position information is located, so as not to affect the integrity of the statement block and the logic of execution. For example, if the program code is in error during the execution of the while conditional statement, the synthesized conditional statement needs to be added before the entire while conditional statement block in order not to affect the integrity of the while conditional statement.
The present invention also provides an electronic device, wherein the electronic device includes:
a processor; and the number of the first and second groups,
a memory arranged to store computer executable instructions that when executed cause the processor to perform a repair method according to the program code shown in figure 1 and its embodiments.
Fig. 3 shows a functional structure diagram of an electronic device according to an embodiment of the present invention. As shown in fig. 3, the electronic device 300 includes:
a processor 310; and a memory 320 arranged to store computer executable instructions (program code), in the memory 320 there being a memory space 330 in which the program code is stored, the program code 340 for performing the steps of the method according to the invention being stored in the memory space 330, the program code, when executed, causing the processor 310 to perform the method of repairing program code according to the method shown in fig. 1 and its various embodiments.
Fig. 4 shows a schematic structural diagram of a computer-readable storage medium according to an embodiment of the invention. As shown in fig. 4, the computer-readable storage medium 400 stores one or more programs (program codes) 410, and the one or more programs (program codes) 410, when executed by a processor, implement the repair method of the program codes shown in fig. 1 and its various embodiments.
It should be noted that the embodiments of the electronic device shown in fig. 3 and the computer-readable storage medium shown in fig. 4 are the same as the embodiments of the method shown in fig. 1, and the detailed description is given above and is not repeated here.
In summary, according to the technical solution of the present invention, when an error occurs in the running of the program code, the error reporting information is obtained; the error reporting information comprises position information and error description information of the operation error of the program code; determining variables needing to be repaired according to the position information and the error description information; selecting predicates of the variables according to the determined variables; and synthesizing the variables and the predicates of the selected variables into conditional statements, and adding the synthesized conditional statements into the program codes. According to the technical scheme, when the program is mistakenly operated, the condition statements are synthesized and then added into the program codes, the repair of the program codes which are mistakenly operated due to the missing of the condition statements can be completed, time and labor consumption of manual repair is avoided, and the speed of repairing the program codes is increased.
It should be noted that:
the algorithms and displays presented herein are not inherently related to any particular computer, virtual machine, or other apparatus. Various general purpose devices may be used with the teachings herein. The required structure for constructing such a device will be apparent from the description above. Moreover, the present invention is not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best mode of the invention.
In the description provided herein, numerous specific details are set forth. However, it is understood that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be construed to reflect the intent: that the invention as claimed requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments described herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
The various component embodiments of the invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It will be appreciated by those skilled in the art that microprocessors or Digital Signal Processors (DSPs) may be used in practice to implement some or all of the functions of some or all of the components of the repair device, the electronic device and the computer readable storage medium of the program code according to embodiments of the invention. The present invention may also be embodied as apparatus or device programs (e.g., computer programs and computer program products) for performing a portion or all of the methods described herein. Such programs implementing the present invention may be stored on computer-readable media or may be in the form of one or more signals. Such a signal may be downloaded from an internet website or provided on a carrier signal or in any other form.
For example, fig. 3 shows a schematic structural diagram of an electronic device according to an embodiment of the invention. The electronic device 300 conventionally comprises a processor 310 and a memory 320 arranged to store computer-executable instructions (program code). The memory 320 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read only memory), an EPROM, a hard disk, or a ROM. Memory 320 has storage space 330 for storing program code 340 for performing the method steps shown in fig. 1 and in any of the embodiments. For example, the memory space 330 for the program code may include respective program codes 340 for implementing the various steps in the above method, respectively. The program code can be read from or written to one or more computer program products. These computer program products comprise a program code carrier such as a hard disk, a Compact Disc (CD), a memory card or a floppy disk. Such a computer program product is generally a computer-readable storage medium 400, such as described in fig. 4. The computer-readable storage medium 400 may have memory segments, memory spaces, etc. arranged similarly to the memory 320 in the electronic device of fig. 3. The program code may be compressed, for example, in a suitable form. In general, the memory unit stores a program code 410 for performing the steps of the method according to the invention, i.e. a program code readable by a processor such as 310, which program code, when executed by an electronic device, causes the electronic device to perform the individual steps of the method described above.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention may be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means can be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names.
The invention discloses A1 and a program code repairing method, wherein the method comprises the following steps:
when the program code has an error during operation, acquiring error reporting information; the error reporting information comprises position information and error description information of the operation error of the program code;
determining variables needing to be repaired according to the position information and the error description information;
selecting predicates of the variables according to the determined variables;
and synthesizing the variables and the predicates of the selected variables into conditional statements, and adding the synthesized conditional statements into the program codes.
The method as in A1, wherein the determining, according to the location information and the error description information, a variable that needs to be repaired includes:
when the error description information contains a variable, determining the variable contained in the error description information as a variable needing to be repaired;
and searching all variables appearing in the context codes of the program code error position indicated by the position information, sequencing all the searched variables, and determining one or more variables needing to be repaired according to a sequencing result.
A3, the method as in A2, wherein when the determined variable to be repaired is multiple, the adding the synthesized conditional statement to the program code includes:
and adding the conditional statements corresponding to each variable into the program codes in sequence according to the sequence in the sequencing result.
A4, the method as in A3, wherein the sequentially adding the conditional statement corresponding to each variable to the program code according to the order in the sorting result includes:
adding a condition statement corresponding to the first variable into the program code according to the sequence in the sequencing result, verifying whether the program code added with the condition statement operates normally, and if so, completing the repair of the program code; if the program code is abnormal, adding the conditional statement corresponding to the second variable into the program code according to the sequence of the ordering, and verifying again; and repeating the steps until the program code runs normally.
The method A5, as described in A1, wherein the selecting the predicate of the variable according to the determined variable includes:
selecting training data; inputting the selected training data into a naive Bayes model for training to obtain an associated probability model;
acquiring code characteristics of a context of a position indicated by the position information, wherein the position information indicates a program code error;
inputting the determined variables and the obtained code characteristics into an association probability model, and obtaining different predicates output by the association probability model and corresponding association probabilities;
and taking the predicate corresponding to the maximum association probability as the predicate of the variable.
The method as in the method A5, wherein the selecting training data includes:
selecting data corresponding to the error information from data of a code base as training data;
and/or the presence of a gas in the gas,
and crawling data corresponding to the error reporting information from the network as training data.
The method according to A1, wherein the adding the synthesized conditional statement to the program code includes:
adding the synthesized conditional statement to the position before the position indicated by the position information, wherein the program code is in error;
alternatively, the first and second electrodes may be,
and adding the synthesized conditional statement to the statement block before the statement block in which the program code indicated by the position information is in error.
The invention also discloses B8, a device for restoring the program code, wherein the device comprises:
the acquisition unit is used for acquiring error reporting information when the program code has an error in operation; the error reporting information comprises position information and error description information of the operation error of the program code;
the variable determining unit is suitable for determining the variable needing to be repaired according to the position information and the error description information;
the predicate selecting unit is suitable for selecting predicates of the variables according to the determined variables;
and the synthesis unit is suitable for synthesizing the variables and the predicates of the selected variables into conditional statements and adding the synthesized conditional statements into the program codes.
B9, the device as in B8, wherein,
the variable determining unit is suitable for determining the variable contained in the error description information as the variable needing to be repaired when the variable is contained in the error description information;
and searching all variables appearing in the context codes of the error position of the program code indicated by the position information, sequencing all the searched variables, and determining one or more variables needing to be repaired according to a sequencing result.
B10. The apparatus of B9, wherein,
and when a plurality of determined variables needing to be repaired are available, the synthesis unit is suitable for sequentially adding the conditional statement corresponding to each variable into the program code according to the sequence in the sequencing result.
B11. The device according to B10, wherein,
the synthesis unit is suitable for adding the condition statement corresponding to the first variable into the program code according to the sequence in the sequencing result, verifying whether the program code added with the condition statement operates normally or not, and completing the repair of the program code if the program code added with the condition statement operates normally; if the program code is abnormal, adding the conditional statement corresponding to the second variable into the program code according to the sequence of the ordering, and verifying again; and the like until the program code runs normally.
B12, the apparatus of B8, wherein,
the predicate selection unit is suitable for selecting training data; inputting the selected training data into a naive Bayes model for training to obtain an associated probability model;
acquiring code characteristics of a context of a position indicated by the position information, wherein the position information indicates a program code error;
inputting the determined variables and the obtained code characteristics into an association probability model, and obtaining different predicates output by the association probability model and corresponding association probabilities;
and taking the predicate corresponding to the maximum association probability as the predicate of the variable.
B13, the apparatus of B12, wherein,
the predicate selecting unit is suitable for selecting data corresponding to the error reporting information from data of a code base as training data;
and/or the presence of a gas in the gas,
and crawling data corresponding to the error reporting information from the network as training data.
B14. The apparatus of B8, wherein,
the synthesis unit is suitable for adding the synthesized conditional statement to the position indicated by the position information, wherein the program code is in error;
alternatively, the first and second liquid crystal display panels may be,
and adding the synthesized conditional statement to the statement block before the statement block in which the program code indicated by the position information is in error.
The invention also discloses C15 and electronic equipment, wherein the electronic equipment comprises:
a processor; and the number of the first and second groups,
a memory arranged to store computer executable instructions that, when executed, cause the processor to perform a method according to any one of A1 to A7.
The invention also discloses D16, a computer readable storage medium, wherein the computer readable storage medium stores one or more programs which, when executed by a processor, implement the method of any one of A1-A7.

Claims (12)

1. A method of repairing program code, wherein the method comprises:
when the program code has an error during operation, acquiring error reporting information; the error reporting information comprises position information and error description information of the operation error of the program code;
determining variables needing to be repaired according to the position information and the error description information;
selecting predicates of the variables according to the determined variables;
synthesizing the variables and predicates of the selected variables into conditional statements, and adding the synthesized conditional statements into the program codes;
selecting predicates of the variables according to the determined variables comprises the following steps:
selecting training data; inputting the selected training data into a naive Bayes model for training to obtain an associated probability model;
acquiring code characteristics of a context of a position indicated by the position information, wherein the position information indicates a program code error;
inputting the determined variables and the obtained code characteristics into an association probability model, and obtaining different predicates output by the association probability model and corresponding association probabilities thereof;
taking the predicate corresponding to the maximum association probability as the predicate of the variable;
the adding the synthesized conditional statement to the program code comprises:
adding the synthesized conditional statement to the position before the position indicated by the position information, wherein the program code is in error;
alternatively, the first and second electrodes may be,
and adding the synthesized conditional statement to the statement block before the statement block in which the program code indicated by the position information is in error.
2. The method of claim 1, wherein the determining a variable that needs to be repaired based on the location information and the error description information comprises:
when the error description information contains a variable, determining the variable contained in the error description information as a variable needing to be repaired;
and searching all variables appearing in the context codes of the error position of the program code indicated by the position information, sequencing all the searched variables, and determining one or more variables needing to be repaired according to a sequencing result.
3. The method of claim 2, wherein when the determined variable requiring repair is plural, said adding the synthesized conditional statement to the program code comprises:
and sequentially adding the conditional statements corresponding to each variable into the program codes according to the sequence in the sequencing result.
4. The method as claimed in claim 3, wherein said adding the conditional statement corresponding to each variable to the program code in sequence in the order of the sorted result comprises:
adding a condition statement corresponding to the first variable into the program code according to the sequence in the sequencing result, verifying whether the program code added with the condition statement operates normally, and if so, completing the repair of the program code; if the program code is abnormal, adding the conditional statement corresponding to the second variable into the program code according to the sequence of the ordering, and verifying again; and the like until the program code runs normally.
5. The method of claim 1, wherein the selecting training data comprises:
selecting data corresponding to the error information from data of a code base as training data;
and/or the presence of a gas in the gas,
and crawling data corresponding to the error reporting information from the network as training data.
6. A repair apparatus of a program code, wherein the apparatus comprises:
the acquisition unit is used for acquiring error reporting information when the program code has an error in operation; the error reporting information comprises position information and error description information of the operation error of the program code;
the variable determining unit is suitable for determining a variable needing to be repaired according to the position information and the error description information;
the predicate selecting unit is suitable for selecting predicates of the variables according to the determined variables;
the synthesizing unit is suitable for synthesizing the variables and predicates of the selected variables into conditional statements and adding the synthesized conditional statements into the program codes;
the predicate selection unit is suitable for selecting training data; inputting the selected training data into a naive Bayes model for training to obtain an associated probability model;
acquiring code characteristics of a context of a position indicated by the position information, wherein the position information indicates a program code error;
inputting the determined variables and the obtained code characteristics into an association probability model, and obtaining different predicates output by the association probability model and corresponding association probabilities;
taking the predicate corresponding to the maximum association probability as the predicate of the variable;
the synthesis unit is suitable for adding the synthesized conditional statement to the position before the position indicated by the position information, wherein the program code is in error;
alternatively, the first and second liquid crystal display panels may be,
and adding the synthesized conditional statement to the statement block before the statement block in which the program code indicated by the position information is in error.
7. The apparatus of claim 6, wherein,
the variable determining unit is suitable for determining the variable contained in the error description information as the variable needing to be repaired when the variable is contained in the error description information;
and searching all variables appearing in the context codes of the error position of the program code indicated by the position information, sequencing all the searched variables, and determining one or more variables needing to be repaired according to a sequencing result.
8. The apparatus of claim 7, wherein,
and when a plurality of determined variables needing to be repaired are needed, the synthesis unit is suitable for sequentially adding the conditional statements corresponding to each variable into the program code according to the sequence in the sequencing result.
9. The apparatus of claim 8, wherein,
the synthesis unit is suitable for adding a condition statement corresponding to a first variable into the program code according to the sequence in the sequencing result, verifying whether the program code added with the condition statement operates normally or not, and completing the repair of the program code if the program code added with the condition statement operates normally; if the program code is abnormal, adding the conditional statement corresponding to the second variable into the program code according to the sequence of the ordering, and verifying again; and the like until the program code runs normally.
10. The apparatus of claim 6, wherein,
the predicate selecting unit is suitable for selecting data corresponding to the error reporting information from data of a code base as training data;
and/or the presence of a gas in the gas,
and crawling data corresponding to the error reporting information from the network as training data.
11. An electronic device, wherein the electronic device comprises:
a processor; and (c) a second step of,
a memory arranged to store computer executable instructions that, when executed, cause the processor to perform the method of any one of claims 1 to 5.
12. A computer readable storage medium, storing one or more programs which, when executed by a processor, implement the method of any of claims 1 to 5.
CN201711396845.7A 2017-12-21 2017-12-21 Program code repairing method and device Active CN109960529B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711396845.7A CN109960529B (en) 2017-12-21 2017-12-21 Program code repairing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711396845.7A CN109960529B (en) 2017-12-21 2017-12-21 Program code repairing method and device

Publications (2)

Publication Number Publication Date
CN109960529A CN109960529A (en) 2019-07-02
CN109960529B true CN109960529B (en) 2023-03-17

Family

ID=67018599

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711396845.7A Active CN109960529B (en) 2017-12-21 2017-12-21 Program code repairing method and device

Country Status (1)

Country Link
CN (1) CN109960529B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103605555A (en) * 2013-11-28 2014-02-26 中国科学院微电子研究所 VHDL information acquiring method and system
CN105446725A (en) * 2014-09-25 2016-03-30 国际商业机器公司 Method and system for model driven development
CN106250319A (en) * 2016-08-15 2016-12-21 腾讯科技(深圳)有限公司 Static code scanning result treating method and apparatus

Family Cites Families (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7058925B2 (en) * 2002-04-30 2006-06-06 Microsoft Corporation System and method for generating a predicate abstraction of a program
US7026979B2 (en) * 2003-07-03 2006-04-11 Hrl Labortories, Llc Method and apparatus for joint kinematic and feature tracking using probabilistic argumentation
US7873945B2 (en) * 2007-06-29 2011-01-18 Microsoft Corporation Automatically generating test cases for binary code
US20100169618A1 (en) * 2008-12-30 2010-07-01 Microsoft Corporation Identifying concurrency control from a sequential proof
US8726236B2 (en) * 2009-10-26 2014-05-13 International Business Machines Corporation Determining context specific content
US20130162426A1 (en) * 2011-12-22 2013-06-27 Tyco Healthcare Group Lp Wireless Relay Module For Remote Monitoring Systems Having Alarm And Display Functionality
US9135139B2 (en) * 2012-06-27 2015-09-15 Intel Corporation Methods and systems to identify and reproduce concurrency violations in multi-threaded programs using expressions
CN103559131B (en) * 2013-11-07 2017-04-26 中国科学院软件研究所 Effective layering error locating method
AU2014262202A1 (en) * 2014-02-06 2015-08-20 National Ict Australia Limited Analysis of Program Code
CN104503908A (en) * 2014-12-17 2015-04-08 西北工业大学 Predicate frequency statistics based software fault locating method
CN105260312B (en) * 2015-10-26 2018-04-06 北京航空航天大学 A kind of adjustment method of multinuclear real time system application data contention mistake
CN106201868A (en) * 2016-06-28 2016-12-07 Tcl集团股份有限公司 A kind of method and apparatus repairing Android application program

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103605555A (en) * 2013-11-28 2014-02-26 中国科学院微电子研究所 VHDL information acquiring method and system
CN105446725A (en) * 2014-09-25 2016-03-30 国际商业机器公司 Method and system for model driven development
CN106250319A (en) * 2016-08-15 2016-12-21 腾讯科技(深圳)有限公司 Static code scanning result treating method and apparatus

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
基于关键谓词的程序错误定位方法;辛良等;《计算机工程》;20100720(第14期);全文 *
基于程序行为特征比较的谓词切换排序;苏欣等;《计算机系统应用》;20121115(第11期);全文 *
嵌入式软件中基于栈的错误追踪机制设计;杜立新等;《单片机与嵌入式系统应用》;20100601(第06期);全文 *

Also Published As

Publication number Publication date
CN109960529A (en) 2019-07-02

Similar Documents

Publication Publication Date Title
EP2960799A1 (en) Defect localization in software integration tests
US8230259B2 (en) Automatic analysis of log entries through use of clustering
CN106776334B (en) Comment-based test case generation method and device
CN111338692B (en) Vulnerability classification method and device based on vulnerability codes and electronic equipment
CN111198809A (en) Interface automation test method and device
CN114936158A (en) Software defect positioning method based on graph convolution neural network
JP2020102209A (en) Identification method of defect location on software program
CN112528030A (en) Semi-supervised learning method and system for text classification
CN112783749A (en) Static code scanning optimization method and device, electronic equipment and storage medium
US20120310849A1 (en) System and method for validating design of an electronic product
US20060161806A1 (en) Method and system of configuring a software program
CN109960529B (en) Program code repairing method and device
CN110727691A (en) Data analysis and verification method and device
CN115640155A (en) Program automatic repairing method and system based on statement dependence and patch similarity
WO2021135369A1 (en) Sample processing method and apparatus
US20140088903A1 (en) Manufacturing control system, amnufacturing control method, and manufacturing control program
US20160349317A1 (en) Method and apparatus for obtaining a maximally compressed verification test set
CN112698883A (en) Configuration data processing method, device, terminal and storage medium
CN112685277A (en) Warning information checking method and device, electronic equipment and readable storage medium
CN112631852A (en) Macro checking method, macro checking device, electronic equipment and computer readable storage medium
CN111143229A (en) Software testing method and device, computer equipment and computer readable storage medium
CN112783751A (en) Incremental code scanning method and device, electronic equipment and storage medium
CN111753183A (en) Search result processing method and device
CN110990395B (en) Data processing method and device
CN111324757B (en) Map data problem processing method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant