Infinite loop detection method and related equipment

By extracting the loop program in the project file, building a loop variable collection, and dynamically executing the loop program to detect the dead loop, the problem of poor detection of complex dead loops in the existing technology is solved, and more efficient dead loop detection and repair is achieved.

CN119645805APending Publication Date: 2025-03-18AGRICULTURAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411716957.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2025-03-18

AI Technical Summary

Technical Problem

The existing technology is difficult to detect complex dead loops, resulting in poor detection of dead loops, affecting the termination of the program and business operation.

Method used

By obtaining the project file, extracting multiple loop programs, building a loop variable collection, inserting initialization and output code into the loop program, dynamically executing the loop program, comparing the loop variable values ​​to detect the dead loop.

Benefits of technology

It realizes effective detection of the complex loop structure of branch paths, improves the applicability and accuracy of dead loop detection, helps fix dead loop errors, and avoids unresponsiveness of the program.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119645805A_ABST
    Figure CN119645805A_ABST
Patent Text Reader

Abstract

The invention provides an endless loop detection method and related equipment. The method comprises the following steps: acquiring a first project file; extracting a plurality of loop programs from the first project file; aiming at each loop program in the plurality of loop programs: constructing a loop variable set comprising loop variables in the loop program; in the loop program, inserting a first code used for carrying out initialization assignment on all loop variables and a second code used for outputting loop variable values of all loop variables after a loop process; executing the loop program, assigning the original input to all loop variables through the first code, and determining loop variable values of all loop variables after a plurality of loop processes through the second code; and in response to the condition that the loop variable values of all the loop variables are the same after any two adjacent loop processes exist, determining a detection result representing that the loop program has an endless loop. The method can improve the applicability of endless loop detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device, computer-readable storage medium, and computer program product for detecting a dead loop. Background Art

[0002] For a program, an infinite loop is a program defect that can cause the program to not terminate. Usually, infinite loops are difficult to detect. Before the infinite loop error is triggered, the program may continue to run for a long time, causing the program to become unresponsive and affecting the program business. Therefore, it is particularly important to perform infinite loop detection and verify the termination of the program before the program goes online.

[0003] In the related art, a static analysis method is usually used to detect engineering files. However, the above method is difficult to detect complex dead loops, and the dead loop detection effect is not good. Summary of the invention

[0004] The present application provides a method for detecting a dead loop, which can detect a loop structure with complex branch paths and improve the applicability of dead loop detection. The present application also provides a device, an electronic device, a computer-readable storage medium, and a computer program product corresponding to the above method.

[0005] In a first aspect, the present application provides a method for detecting a dead loop. The method comprises:

[0006] Get the first project file;

[0007] Extracting a plurality of loop programs from the first engineering file; wherein each of the loop programs corresponds to a loop structure in the first engineering file;

[0008] For each loop program in the multiple loop programs, the following steps are performed: constructing a loop variable set including loop variables in the loop program; inserting a first code for initializing and assigning values ​​to all the loop variables and a second code for outputting loop variable values ​​of all the loop variables after one loop process in the loop program; executing the loop program, assigning original inputs to all the loop variables through the first code, and determining loop variable values ​​of all the loop variables after multiple loop processes through the second code; in response to the existence of the same loop variable values ​​of all the loop variables after any two adjacent loop processes, determining a detection result indicating the existence of an infinite loop in the loop program.

[0009] In some possible implementations, extracting a plurality of cycle programs from the first engineering file includes:

[0010] Extracting loop keywords and characters identifying loop structure ranges from the first project file;

[0011] Determine a plurality of loop structures according to the extracted loop keyword and the character identifying the loop structure range;

[0012] Main functions are respectively added to the multiple loop structures to form multiple loop programs.

[0013] In some possible implementations, the method further includes:

[0014] For each loop structure in the multiple loop structures, the following steps are performed: constructing a path constraint located before the loop structure in the first engineering file; and determining a precondition of the loop structure according to the path constraint.

[0015] In some possible implementations, constructing a loop variable set including loop variables in the loop program includes:

[0016] Construct a set of loop variables;

[0017] Scan the loop program, extract a first variable from a loop condition and a jump statement of the loop program, and add the extracted first variable as a loop variable to the loop variable set;

[0018] In response to the existence of a second variable in the loop program, the second variable is added to the loop variable set as a loop variable; wherein, during the execution of the loop program, the second variable affects the variable value of the first variable.

[0019] In some possible implementations, the method further includes:

[0020] The loop program is scanned again, and for each code statement in the loop program, the following steps are performed: in response to the code statement not including a loop variable in the loop variable set, the code statement is deleted.

[0021] In some possible implementations, inserting a first code for initializing and assigning values ​​to all the loop variables and a second code for outputting loop variable values ​​of all the loop variables after one loop process into the loop program includes:

[0022] A first code for initializing and assigning values ​​to all the loop variables is inserted at a position after the main function in the loop program; and a second code for outputting the loop variable values ​​of all the loop variables after one loop process is inserted at a position before each loop end branch in the loop program.

[0023] In a second aspect, the present application provides a dead loop detection device. The device comprises:

[0024] An acquisition module, used for acquiring a first project file;

[0025] An extraction module, used for extracting a plurality of loop programs from the first engineering file; wherein each of the loop programs corresponds to a loop structure in the first engineering file;

[0026] The detection module is used to perform the following steps for each loop program in the multiple loop programs: construct a loop variable set including loop variables in the loop program; insert a first code for initializing and assigning values ​​to all the loop variables and a second code for outputting loop variable values ​​of all the loop variables after a loop process in the loop program; execute the loop program, assign original inputs to all the loop variables through the first code, and determine loop variable values ​​of all the loop variables after multiple loop processes through the second code; in response to the existence of the same loop variable values ​​of all the loop variables after any two adjacent loop processes, determine a detection result indicating that an infinite loop exists in the loop program.

[0027] In some possible implementations, the extraction module is specifically used to:

[0028] Extracting loop keywords and characters identifying loop structure ranges from the first project file;

[0029] Determine a plurality of loop structures according to the extracted loop keyword and the character identifying the loop structure range;

[0030] Main functions are respectively added to the multiple loop structures to form multiple loop programs.

[0031] In some possible implementations, the extraction module is further configured to:

[0032] For each loop structure in the multiple loop structures, the following steps are performed: constructing a path constraint located before the loop structure in the first engineering file; and determining a precondition of the loop structure according to the path constraint.

[0033] In some possible implementations, the detection module is specifically used to:

[0034] Construct a set of loop variables;

[0035] Scan the loop program, extract a first variable from a loop condition and a jump statement of the loop program, and add the extracted first variable as a loop variable to the loop variable set;

[0036] In response to the existence of a second variable in the loop program, the second variable is added to the loop variable set as a loop variable; wherein, during the execution of the loop program, the second variable affects the variable value of the first variable.

[0037] In some possible implementations, the detection module is further configured to:

[0038] The loop program is scanned again, and for each code statement in the loop program, the following steps are performed: in response to the code statement not including a loop variable in the loop variable set, the code statement is deleted.

[0039] In some possible implementations, the detection module is specifically used to:

[0040] A first code for initializing and assigning values ​​to all the loop variables is inserted at a position after the main function in the loop program; and a second code for outputting the loop variable values ​​of all the loop variables after one loop process is inserted at a position before each loop end branch in the loop program.

[0041] In a third aspect, the present application provides an electronic device, wherein the electronic device comprises a processor and a memory, wherein the memory stores instructions, and the processor executes the instructions so that the electronic device platform executes the method as described in the first aspect of the present application or any implementation of the first aspect.

[0042] In a fourth aspect, the present application provides a computer-readable storage medium. The computer-readable storage medium stores instructions, which, when executed on an electronic device, enable the electronic device to execute the method described in the first aspect or any one of the implementations of the first aspect.

[0043] In a fifth aspect, the present application provides a computer program product. The computer program product includes computer-readable instructions, and when the computer program product is executed on an electronic device, the electronic device executes the method described in the first aspect or any one of the implementations of the first aspect.

[0044] Based on the implementations provided in the above aspects, this application can also be further combined to provide more implementations.

[0045] Based on the above description, it can be seen that the technical solution of this application has the following beneficial effects:

[0046] Specifically, the method first obtains a first project file, extracts multiple loop programs from the first project file, wherein each loop program corresponds to a loop structure in the first project file, and performs the following steps for each loop program in the multiple loop programs: constructs a loop variable set including loop variables in the loop program; inserts a first code for initializing and assigning values ​​to all loop variables and a second code for outputting loop variable values ​​of all loop variables after a loop process in the loop program; executes the loop program, assigns original inputs to all loop variables through the first code, and determines loop variable values ​​of all loop variables after multiple loop processes through the second code; and in response to the existence of the same loop variable values ​​of all loop variables after any two adjacent loop processes, determines a detection result characterizing the existence of an infinite loop in the loop program.

[0047] In this method, loop programs are extracted from the project file, and for each loop program, the loop variable set involved is found. The loop program is run under the original input through the program instrumentation method, and the loop variable values ​​of multiple loop processes are output. The loop status is compared to detect whether there is a dead loop in the project file. In this way, dead loop detection based on dynamic analysis can detect loop structures with complex branch paths, improving the applicability of dead loop detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] The above and other features, advantages and aspects of the embodiments of the present application will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.

[0049] Figure 1 A schematic diagram of the architecture of a dead loop detection system provided in an embodiment of the present application;

[0050] Figure 2 A flowchart of a method for detecting a dead loop provided in an embodiment of the present application;

[0051] Figure 3 A schematic diagram of a flow chart of an extraction cycle structure provided in an embodiment of the present application;

[0052] Figure 4 A schematic diagram of a process for constructing a loop variable set provided in an embodiment of the present application;

[0053] Figure 5 A schematic diagram of the structure of a dead loop detection device provided in an embodiment of the present application;

[0054] Figure 6 A schematic diagram of the structure of an electronic device for implementing dead loop detection provided in an embodiment of the present application. DETAILED DESCRIPTION

[0055] The embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be construed as being limited to the embodiments described herein. Instead, these embodiments are provided to provide a more thorough and complete understanding of the present application. It should be understood that the drawings and embodiments of the present application are only for exemplary purposes and are not intended to limit the scope of protection of the present application.

[0056] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.

[0057] It should be noted that the concepts such as "first" and "second" mentioned in this application are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0058] It should be noted that the modifications of "one" and "plurality" mentioned in the present application are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0059] In order to facilitate understanding of the technical solution of the present application, the specific technical terms and application scenarios in the present application are explained below.

[0060] Infinite loop: Infinite loop refers to a loop structure that cannot be terminated by the program itself. During the program running process, an infinite loop usually sets an exit condition for a loop structure, but due to reasons such as program logic errors, the exit condition cannot be met.

[0061] Static analysis: Static analysis refers to a code analysis technology that scans program code through lexical analysis, syntax analysis, control flow, data flow analysis and other technologies without executing the program code to verify whether the code meets indicators such as standardization, security, reliability, and maintainability.

[0062] Dynamic analysis: Dynamic analysis refers to directly executing program code and checking the behavior of the program while it is running. The general steps of dynamic analysis are divided into three steps: instrumentation, execution, and analysis.

[0063] Loop state: The loop state refers to a set of variables that uniquely identifies the current loop execution status.

[0064] Precondition: Precondition refers to the constraints that need to be met to execute the loop structure, that is, the conditions that the variables must meet to execute the loop structure.

[0065] Fuzzy input: Fuzzy input refers to random input that is automatically or semi-automatically generated according to certain rules. There are two main types of algorithms for generating fuzzy input use cases: mutation-based and generation-based.

[0066] Fuzzy mutation: Fuzzy mutation is an algorithm for generating fuzzy input cases. It generates new fuzzy input cases based on known data samples through mutation methods (such as bit flipping, addition and subtraction, etc.).

[0067] Program slicing: Program slicing is a program analysis technique used to decompose a program. A program consisting of only statements and predicates related to a certain output statement is called a static slice of the program.

[0068] Jump statement: A loop jump statement is a statement that controls the loop execution path in a loop structure. In Java programs, it mainly includes the three keywords "continue", "break", and "return".

[0069] Loop variable: A loop variable is a variable whose value determines the loop execution path. Generally speaking, loop variables include variables in loop conditions and variables in jump statements.

[0070] Program instrumentation: Program instrumentation refers to inserting probes into the program under test, and obtaining the control flow and data flow information of the program through the execution of the probes, thereby achieving the purpose of testing.

[0071] In the related art, a static analysis method is usually used to detect engineering files. However, the above method is difficult to detect complex dead loops, and the dead loop detection effect is not good.

[0072] In view of this, the present application provides a method for detecting an infinite loop. The method first obtains a first engineering file, extracts multiple loop programs from the first engineering file, wherein each loop program corresponds to a loop structure in the first engineering file, and performs the following steps for each loop program in the multiple loop programs: constructs a loop variable set including loop variables in the loop program; inserts a first code for initializing and assigning values ​​to all loop variables and a second code for outputting loop variable values ​​of all loop variables after a loop process in the loop program; executes the loop program, assigns the original input to all loop variables through the first code, and determines the loop variable values ​​of all loop variables after multiple loop processes through the second code; in response to the existence of the same loop variable values ​​of all loop variables after any two adjacent loop processes, determines a detection result characterizing the existence of an infinite loop in the loop program.

[0073] In this method, loop programs are extracted from the project file, and for each loop program, the loop variable set involved is found. The loop program is run under the original input through the program instrumentation method, and the loop variable values ​​of multiple loop processes are output. The loop status is compared to detect whether there is a dead loop in the project file. In this way, dead loop detection based on dynamic analysis can detect loop structures with complex branch paths, improving the applicability of dead loop detection.

[0074] Next, the dead loop detection method provided by the present application is described in detail with reference to the accompanying drawings. Figure 1 The schematic diagram of the architecture of a dead loop detection system is shown, and the dead loop detection system includes a loop extractor, a loop state builder, a loop plugger, a fuzzy inputter and a dynamic executor. They are introduced below.

[0075] The loop extractor is used to identify and extract the loop structure in the first project file, forming a loop program containing only the loop structure, thereby solving the problem of high program complexity during dynamic execution. Furthermore, the loop extractor is also used to calculate the preconditions before reaching the loop structure through static analysis to constrain the range of fuzzy input generated by the fuzzy inputter and improve the fuzzy efficiency.

[0076] The loop state builder is used to scan loop-related variables and build a loop variable set according to the extracted loop program by static scanning. Furthermore, the loop state builder is also used to simplify the loop program by program slicing.

[0077] The loop instrumenter is used to instrument each loop branch in the loop program to provide loop execution information when the loop program is dynamically executed.

[0078] The fuzzy inputter is used to provide different original inputs to the dynamic actuator through mutation strategies. Specifically, based on the precondition and the loop state, the fuzzy inputter generates the original input corresponding to the loop state and mutates the original input to generate a new original input.

[0079] The dynamic executor is used to take the original input generated by the fuzzy input device as the input of the loop program, dynamically execute the loop program, and detect whether the loop program is an infinite loop.

[0080] In this way, the loop structure in the first project file is detected based on the dynamic analysis method to find the potential dead loop and corresponding input in the first project file, so as to find the potential dead loop in the program before production, help programmers fix the dead loop error, and avoid the program from falling into an unresponsive state.

[0081] See also Figure 2The flowchart of a method for detecting a dead loop is shown in FIG. 1 , and the method specifically comprises the following steps:

[0082] S201: Obtain a first project file.

[0083] In the embodiment of the present application, the first project file can be understood as a project file with a dead loop detection requirement. The first project file can be a project file written in any programming language, for example, the first project file can be a Java project file.

[0084] S202: Extracting a plurality of loop programs from the first project file.

[0085] Each loop program corresponds to a loop structure in the first engineering file. That is, by statically scanning the first engineering file, the loop structure in the first engineering file is extracted, and the loop structure is constructed as an executable loop program.

[0086] When implementing it specifically, Figure 3 As shown, loop keywords and characters identifying the range of loop structures are extracted from the first project file, multiple loop structures are determined based on the extracted loop keywords and characters identifying the range of loop structures, and main functions are added to the multiple loop structures respectively to form multiple loop programs.

[0087] The first project files of different programming languages ​​may be configured with different loop keywords. For example, in a Java project file, the loop keywords may include for, while, do-while, etc. The characters identifying the scope of the loop structure may be brackets identifying the scope of the loop body.

[0088] Furthermore, for each loop structure in the plurality of loop structures, the following steps are performed: a path constraint located before the loop structure in the first project file is constructed, and a precondition of the loop structure is determined according to the path constraint.

[0089] That is to say, by reading and scanning the first engineering file, it is determined whether the scanning is completed. If the scanning is completed, the process ends. If the scanning is not completed, the precondition is calculated according to the path constraint before the loop structure is constructed. In some embodiments, if the precondition is too complicated or there is random input, the precondition can also be relaxed. Then, the loop keyword and the character identifying the loop structure range are extracted to determine the loop structure, and the main function is added before and after the loop structure to form an executable loop program.

[0090] S203: For each loop program in the plurality of loop programs, the following steps are performed: constructing a loop variable set including loop variables in the loop program; inserting in the loop program a first code for initializing and assigning values ​​to all loop variables and a second code for outputting loop variable values ​​of all loop variables after one loop process; executing the loop program, assigning original inputs to all loop variables through the first code, and determining loop variable values ​​of all loop variables after a plurality of loop processes through the second code; in response to the existence of the same loop variable values ​​of all loop variables after any two adjacent loop processes, determining a detection result indicating the existence of an infinite loop in the loop program.

[0091] The loop variable values ​​of the loop variables in the loop variable set can identify the loop state. For each loop program, the loop variable closure is determined by scanning the loop program to obtain the loop variable set constituting the loop state.

[0092] For specific implementation, see Figure 4 , construct a loop variable set, scan the loop program, extract a first variable from the loop condition and jump statement of the loop program, add the extracted first variable as a loop variable to the loop variable set, and in response to the existence of a second variable in the loop program, add the second variable as a loop variable to the loop variable set. In the process of executing the loop program, the second variable affects the variable value of the first variable.

[0093] That is to say, the loop variable set is initialized to be empty, and the variables involved in the loop condition and the variables involved in the jump statement in the loop program (referred to as the first variable in the embodiment of the present application) are added to the loop variable set if there is a variable that can affect the loop variable and the variable is not in the loop variable set. After the scan is completed, the construction of the loop variable set is completed.

[0094] In addition, the loop program may be scanned again, and for each code statement in the loop program, the following steps may be performed: in response to the code statement not including a loop variable in the loop variable set, the code statement may be deleted.

[0095] That is to say, after constructing the loop variable set, the loop program is scanned again. When the scanned code statement does not involve the change of the loop variable value, it means that the code statement will not affect the loop termination, and the code statement is deleted. When the scan reaches the end of the loop, the scan ends. By deleting the code statements that are not related to the loop variables, the slicing process based on the loop program is completed, and the loop program is simplified.

[0096] Next, the loop program is plugged so that the loop program accepts the original input and outputs the loop variable values ​​after each loop process. Specifically, a first code for initializing and assigning values ​​to all loop variables is inserted after the main function in the loop program, and a second code for outputting the loop variable values ​​of all loop variables after a loop process is inserted before each loop end branch in the loop program.

[0097] That is to say, scan the loop limit in the loop variable set, perform initialization assignment operation before the loop program starts, and complete the input of the loop variable. Secondly, locate each loop end branch, insert the loop variable output statement at the end of the loop end branch, and complete the output of the loop variable value after each loop process.

[0098] In the embodiment of the present application, the original input can be understood as a fuzzy input generated by the execution loop program. Moreover, through mutation, new original inputs that are more likely to trigger an infinite loop are continuously generated.

[0099] In specific implementation, a corresponding original input and mutation method can be provided for each loop variable in the loop variable set, and the range of generating fuzzy input can be narrowed according to the precondition.

[0100] In this way, errors can be continuously found without any interaction, which greatly reduces manpower and can generate test cases that are difficult to cover manually.

[0101] After completing the loop program stub, the loop program is dynamically executed, and the loop variable value of each loop process is used to determine whether the loop program is trapped in an infinite loop. Specifically, the original input is used as the input of the loop program, the loop program is actually run, and the output of the loop variable value is monitored in real time. When the same loop state appears twice in a row, it means that the loop program has fallen into an infinite loop, so the current input is recorded and the loop program is marked as an infinite loop.

[0102] In this way, for the loop structure in the first project file, a dead loop can be detected, and input samples that trigger the dead loop can be output to help repair personnel repair the dead loop program.

[0103] In this method, loop programs are extracted from the project file, and for each loop program, the loop variable set involved is found. The loop program is run under the original input through the program instrumentation method, and the loop variable values ​​of multiple loop processes are output. The loop status is compared to detect whether there is a dead loop in the project file. In this way, dead loop detection based on dynamic analysis can detect loop structures with complex branch paths, improving the applicability of dead loop detection.

[0104] Based on the above method provided in the embodiment of the present application, the embodiment of the present application also provides a dead loop detection device corresponding to the above method. The units / modules involved in the embodiments of the present application can be implemented by software or by hardware. The name of the unit / module does not constitute a limitation on the unit / module itself in some cases.

[0105] See also Figure 5 The structural diagram of the dead loop detection device shown in FIG. 5 includes:

[0106] An acquisition module 501 is used to acquire a first project file;

[0107] An extraction module 502 is used to extract a plurality of loop programs from the first engineering file; wherein each of the loop programs corresponds to a loop structure in the first engineering file;

[0108] The detection module 503 is used to perform the following steps for each loop program in the multiple loop programs: construct a loop variable set including loop variables in the loop program; insert a first code for initializing and assigning values ​​to all the loop variables and a second code for outputting loop variable values ​​of all the loop variables after a loop process in the loop program; execute the loop program, assign the original input to all the loop variables through the first code, and determine the loop variable values ​​of all the loop variables after multiple loop processes through the second code; in response to the existence of the same loop variable values ​​of all the loop variables after any two adjacent loop processes, determine a detection result indicating that an infinite loop exists in the loop program.

[0109] In some possible implementations, the extraction module 502 is specifically configured to:

[0110] Extracting loop keywords and characters identifying loop structure ranges from the first project file;

[0111] Determine a plurality of loop structures according to the extracted loop keyword and the character identifying the loop structure range;

[0112] Main functions are respectively added to the multiple loop structures to form multiple loop programs.

[0113] In some possible implementations, the extraction module 502 is further configured to:

[0114] For each loop structure in the multiple loop structures, the following steps are performed: constructing a path constraint located before the loop structure in the first engineering file; and determining a precondition of the loop structure according to the path constraint.

[0115] In some possible implementations, the detection module 503 is specifically configured to:

[0116] Construct a set of loop variables;

[0117] Scan the loop program, extract a first variable from a loop condition and a jump statement of the loop program, and add the extracted first variable as a loop variable to the loop variable set;

[0118] In response to the existence of a second variable in the loop program, the second variable is added to the loop variable set as a loop variable; wherein, during the execution of the loop program, the second variable affects the variable value of the first variable.

[0119] In some possible implementations, the detection module 503 is further configured to:

[0120] The loop program is scanned again, and for each code statement in the loop program, the following steps are performed: in response to the code statement not including a loop variable in the loop variable set, the code statement is deleted.

[0121] In some possible implementations, the detection module 503 is specifically configured to:

[0122] A first code for initializing and assigning values ​​to all the loop variables is inserted at a position after the main function in the loop program; and a second code for outputting the loop variable values ​​of all the loop variables after one loop process is inserted at a position before each loop end branch in the loop program.

[0123] The dead loop detection device 500 according to the embodiment of the present application may correspond to the method described in the embodiment of the present application, and the above and other operations and / or functions of each module / unit of the dead loop detection device 500 are respectively to implement Figure 2 For the sake of brevity, the corresponding processes of each method in the illustrated embodiment are not described in detail here.

[0124] The functions described above in this document may be performed at least in part by one or more hardware logic components. Figure 6 The schematic diagram of the structure of the electronic device 600 for realizing the dead loop detection shown in FIG. Figure 6 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0125] like Figure 6As shown, the electronic device 600 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0126] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 6 The electronic device 600 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0127] The present application also provides a computer-readable storage medium, also referred to as a machine-readable medium. In the context of the present application, a machine-readable medium may be a tangible medium that may contain or store a program for use by an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0128] It should be noted that the computer-readable medium mentioned above in the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0129] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: obtains a first project file; extracts multiple loop programs from the first project file; wherein each loop program corresponds to a loop structure in the first project file; for each loop program in the multiple loop programs, performs the following steps: constructs a loop variable set including loop variables in the loop program; inserts a first code for initializing and assigning values ​​to all the loop variables and a second code for outputting loop variable values ​​of all the loop variables after a loop process into the loop program; executes the loop program, assigns the original input to all the loop variables through the first code, and determines the loop variable values ​​of all the loop variables after multiple loop processes through the second code; in response to the existence of the same loop variable values ​​of all the loop variables after any two adjacent loop processes, determines a detection result indicating the existence of an infinite loop in the loop program.

[0130] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via a communication device, or installed from a storage device. When the computer program is executed by a processing device, the above-mentioned functions defined in the method of the embodiment of the present application are executed.

[0131] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.

[0132] Although several specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present application. Certain features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination.

[0133] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in this application (but not limited to) by each other to form a technical solution.

Claims

1. A method for detecting a dead loop, characterized in that: The method comprises: Get the first project file; Extracting a plurality of loop programs from the first engineering file; wherein each of the loop programs corresponds to a loop structure in the first engineering file; For each loop program in the multiple loop programs, the following steps are performed: constructing a loop variable set including loop variables in the loop program; inserting a first code for initializing and assigning values ​​to all the loop variables and a second code for outputting loop variable values ​​of all the loop variables after one loop process in the loop program; executing the loop program, assigning original inputs to all the loop variables through the first code, and determining loop variable values ​​of all the loop variables after multiple loop processes through the second code; in response to the existence of the same loop variable values ​​of all the loop variables after any two adjacent loop processes, determining a detection result indicating the existence of an infinite loop in the loop program.

2. The method according to claim 1, characterized in that The step of extracting a plurality of cycle programs from the first engineering file includes: Extracting loop keywords and characters identifying loop structure ranges from the first project file; Determine a plurality of loop structures according to the extracted loop keyword and the character identifying the loop structure range; Main functions are respectively added to the multiple loop structures to form multiple loop programs.

3. The method according to claim 2, characterized in that The method further comprises: For each loop structure in the multiple loop structures, the following steps are performed: constructing a path constraint located before the loop structure in the first engineering file; and determining a precondition of the loop structure according to the path constraint.

4. The method according to claim 1, characterized in that: The step of constructing a loop variable set including loop variables in the loop program includes: Construct a set of loop variables; Scan the loop program, extract a first variable from a loop condition and a jump statement of the loop program, and add the extracted first variable as a loop variable to the loop variable set; In response to the existence of a second variable in the loop program, the second variable is added to the loop variable set as a loop variable; wherein, during the execution of the loop program, the second variable affects the variable value of the first variable.

5. The method according to claim 4, characterized in that The method further comprises: The loop program is scanned again, and for each code statement in the loop program, the following steps are performed: in response to the code statement not including a loop variable in the loop variable set, the code statement is deleted.

6. The method according to claim 1, characterized in that The first code for initializing and assigning values ​​to all the loop variables and the second code for outputting the loop variable values ​​of all the loop variables after one loop process are inserted into the loop program, including: A first code for initializing and assigning values ​​to all the loop variables is inserted at a position after the main function in the loop program; and a second code for outputting the loop variable values ​​of all the loop variables after one loop process is inserted at a position before each loop end branch in the loop program.

7. A dead loop detection device, characterized in that: The device comprises: An acquisition module, used for acquiring a first project file; An extraction module, used for extracting a plurality of loop programs from the first engineering file; wherein each of the loop programs corresponds to a loop structure in the first engineering file; The detection module is used to perform the following steps for each loop program in the multiple loop programs: construct a loop variable set including loop variables in the loop program; insert a first code for initializing and assigning values ​​to all the loop variables and a second code for outputting loop variable values ​​of all the loop variables after a loop process in the loop program; execute the loop program, assign original inputs to all the loop variables through the first code, and determine loop variable values ​​of all the loop variables after multiple loop processes through the second code; in response to the existence of the same loop variable values ​​of all the loop variables after any two adjacent loop processes, determine a detection result indicating that an infinite loop exists in the loop program.

8. An electronic device, characterized in that: The electronic device comprises a processor and a memory, wherein instructions are stored in the memory, and the processor executes the instructions so that the electronic device executes the method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The method comprises computer-readable instructions, and when the computer-readable instructions are executed on an electronic device, the electronic device executes the method according to any one of claims 1 to 6.

10. A computer program product, characterized in that The computer program product comprises computer-readable instructions, and when the computer program product is run on an electronic device, the electronic device executes the method according to any one of claims 1 to 6.