Method for detecting multivariable atomic violation of interrupt-driven program

Through machine learning algorithms and static analysis technology, the associated variable pairs in interrupt-driven programs are automatically identified and multivariate atomic violations are detected, which solves the problems of low detection efficiency and insufficient security in the existing technology, and improves software development and testing Efficiency and safety.

CN119025409APending Publication Date: 2024-11-26BEIJING XUANYU INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410966968.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-18
Publication Date
2024-11-26

AI Technical Summary

Technical Problem

The prior art is difficult to efficiently detect multivariate atomicity violation defects in interrupt-driven programs, resulting in low software development and testing efficiency and insufficient security.

Method used

Using machine learning algorithms, a training data set of associated variables is constructed through static analysis and feature extraction, a classifier model is generated, and the associated variable pairs are automatically identified, and whether interrupt preemption is damaged is analyzed to realize multivariate atomicity violation detection.

Benefits of technology

It realizes automated detection of multivariate atomicity violation defects in interrupt-driven programs, improves software development and testing efficiency, and improves software security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119025409A_ABST
    Figure CN119025409A_ABST
Patent Text Reader

Abstract

The invention provides an interrupt-driven program multivariable atomic violation detection method, which comprises the following steps: by taking real aerospace embedded software as a database, screening software which is provided with detailed documents and has annotation source codes, and taking the software as a training data set of an associated variable pair recognition model; taking the shared variable pair as an object, performing feature extraction on the shared variable pair in the software in the training data set through static analysis, and constructing a training data set sample considering relevance features of the relevance variable pair; constructing a learning model and training by using the training data set sample to obtain a classifier model capable of automatically identifying the associated variable pair; analyzing the source program to be analyzed, and constructing a variable pair sample as a test sample; inputting a test sample into the classifier model to carry out correlation variable pair identification; and obtaining an atomic region according to the identified associated variable pair, analyzing whether the interrupted preemption may damage the atomic region or not, and completing multivariable atomic violation detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to an interrupt-driven program defect detection technology, in particular to an interrupt-driven program multi-variable atomicity violation detection method. Background Art

[0002] Interrupt-driven embedded software is widely used in aerospace, automotive, medical equipment and other fields with high safety requirements. This type of software usually uses interrupts to interact with hardware and respond to external stimuli in a timely manner. Since interrupt triggering is uncertain and unpredictable, it is very challenging for programmers to understand and develop interrupt-driven programs. Once the access to shared data is not properly synchronized or protected, the uncertain interleaved execution of interrupts may lead to concurrency defects, which may cause serious safety problems. According to statistics, about 80% of the software quality problems found in the spacecraft assembly and integration test phase are interrupt-related concurrency defects. These defects are still missed after various rigorous software tests and are one of the most difficult types of defects to eliminate in aerospace embedded software development. Among these concurrency defects, multi-variable atomicity violation is one of the most representative and difficult to detect defect modes, accounting for about 36% of all concurrency defects. The root cause of this type of defect is that unsynchronized concurrent access violates the semantic relationship between variables. In interrupt-driven programs, developers usually use multiple global variables to represent a single entity, or use variables as custom synchronization flags to restrict another variable. These variables are inherently related and need to be accessed in a consistent manner. Therefore, how to accurately identify variables with semantic associations and detect multi-variable atomicity violations is an important challenge.

[0003] In the existing technologies, the techniques and tools for detecting multivariable atomicity violations can be divided into three categories. First, most methods still need to identify the associated variables in the program through manual annotation, and then detect multivariable atomicity violations through dynamic methods. However, manual annotation requires in-depth understanding of the program and takes a lot of time, so it is difficult to apply to large-scale programs and real industrial scenarios. Secondly, some methods use a predefined pattern consisting of multiple variable access interleaving. During the program execution, the execution trace is collected and matched with the predefined pattern. If these patterns are met, it is judged as a defect. However, the predefined access interleaving pattern cannot accurately characterize the real associated variables, resulting in a large number of false positives and negatives in the results. The third type of method automatically identifies the associated variables in the program by combining static analysis and data mining techniques, and then detects multivariable atomicity violations through traditional program analysis methods. In comparison, this type of method has achieved the best results. However, since these methods only use some specific variable association features, the accuracy is still difficult to meet actual needs. In addition, these methods are all focused on multi-threaded programs. Due to the different concurrency mechanisms and programming practices of interrupt-driven programs, these methods are difficult to apply. Therefore, new research is urgently needed to address the challenges of multivariate atomicity violation detection methods in interrupt-driven environments. Summary of the invention

[0004] The technical problem solved by the present invention is to propose a method for detecting multivariable atomicity violations of interrupt-driven programs. The invention aims to provide an accurate and efficient method for detecting multivariable atomicity violations for interrupt-driven software, solve the problem that there is currently no efficient means to help developers and testers find software defects that violate multivariable atomicity of interrupt-driven programs, greatly improve software development and testing efficiency, and enhance software security.

[0005] The solution of the present invention is: a method for detecting atomicity violation of multiple variables in an interrupt-driven program, comprising:

[0006] Using real aerospace embedded software as a database, we screened software with detailed documentation and annotated source code as a training dataset for the model used to identify associated variable pairs.

[0007] Taking the shared variable pairs as the object, the features of the shared variable pairs in the software in the training data set are extracted through static analysis, and the training data set samples that consider the correlation features of the associated variables are constructed;

[0008] Build a learning model and use training data set samples for training to obtain a classifier model that can automatically identify associated variable pairs;

[0009] Analyze the source program to be analyzed, construct variable pair samples as test samples; input the test samples into the classifier model to identify associated variable pairs;

[0010] The atomic region is obtained based on the identified associated variable pairs, and it is analyzed whether the interrupt preemption may destroy the atomic region, thus completing the multi-variable atomicity violation detection.

[0011] Preferably, the training data set samples are as follows:

[0012] Samples=<Pair,L,R,CO,CD,DD,Arr,Fieds,Name,Label>

[0013] Among them, Pair represents the shared variable pair (x, y) in the program, L and R represent the number of times variable x and variable y appear in the program respectively, CO represents the number of times variable x and variable y have a proximity relationship; CD, DD, Arr, Fields and Name represent whether there is a data dependency relationship, a control dependency relationship, whether they belong to the same array, whether they belong to the same structure and whether they have similar naming rules respectively, Label is the label value, when the value is 1, it means that x and y are an associated variable pair, when it is 0, it means that they are not an associated variable pair.

[0014] Preferably, the neighbor distance relationship is determined by analyzing whether two variables co-appear in the same function in the source code and within a range of less than 10 lines of code.

[0015] Preferably, the similar naming rule is to compare whether the variable names contain a common prefix, and whether the prefix accounts for more than 20% of the total length of the variable name. The algorithm description of the similarity determination rule should be consistent in logic and expression.

[0016] Preferably, data dependency is identified by the following steps: first, the program code is analyzed to identify the access points of all global variables, and these nodes are mapped accordingly on the dependency graph. Next, the data dependency path between two access points is searched on the dependency graph. Specifically, if there is a path from the access point of one variable to the access point of another variable, and this path meets the definition of data dependency (i.e., the value of one variable affects the value of another variable), then it can be determined that there is a data dependency relationship between the two variables.

[0017] Preferably, the control dependency is identified by the following steps: first, all control statements in the program, such as conditional judgments and loop controls, are identified and used as key nodes in the dependency graph. Then, by analyzing the control flow path, which variables are affected by these control nodes is identified, thereby determining whether these variables have control dependencies.

[0018] Preferably, the variable pair sample is constructed in the following manner:

[0019] Convert the source program to be analyzed into an intermediate representation that is easy to process and analyze (i.e., an intermediate representation between source code and binary code, which facilitates further static and dynamic analysis);

[0020] Based on the intermediate representation, multiple key analysis steps are performed, including function call relationship analysis to generate a function call graph; control flow analysis to build a control flow graph; data flow analysis, pointing analysis and memory analysis to create a data dependency graph; the control flow graph generates a forward dominance tree through forward dominance analysis, and finally forms a control dependency graph;

[0021] Combine the control dependency graph, data dependency graph and function call graph to construct the program dependency graph;

[0022] Traverse the source code of the source program to be analyzed, collect the variable names, access locations and access times of all global variables and form variable pairs of all global variables, calculate the frequency of co-occurrence of variable pairs in the program, check whether the variable pairs belong to the same array or structure, and evaluate whether the variable pairs have similar naming rules; by traversing the program dependency graph, capture the control and data dependency relationships between variable pairs, and thus construct variable pair samples.

[0023] Preferably, based on the identified associated variable pairs, a cross-process data flow analysis is performed on the program to identify the reachable accesses between the associated variable pairs and form an atomic zone. This step is actually equivalent to defining a reachability analysis. Specifically, on the execution path of the program, check whether the access to the first variable can reach the access to its associated variable. If reachable, the two access points are matched to form an atomic zone. Then the old access records are cleared, while the new access records are retained for subsequent matching.

[0024] Preferably, whether the interrupted preemption destroys the atomic region is analyzed in the following manner:

[0025] An access interleaving pattern that may cause atomicity violations of multiple variables is proposed for driver-type programs, including 4 types of concurrent four-time access sequences;

[0026] According to the identified associated variable pairs, inter-procedural data flow analysis is performed in the main task of the source program to be analyzed and each interrupt program, respectively, to obtain all ordered pairs with associated variable access; the ordered pairs are combined and analyzed between the main program and the interrupt program, to obtain four concurrent access sequences composed of the associated variable pairs;

[0027] Pattern matching is performed on the four concurrent access sequences and the access interleaving pattern to obtain the four concurrent access sequences that may cause multi-variable atomicity violation;

[0028] A feasibility analysis is conducted on the concurrent four-access sequence that may cause multi-variable atomicity violations. Specifically, first, interference analysis is performed on the associated variable pairs in the concurrent four-access sequence, and a function summary model for each function in the main task and interrupt as well as a symbolic summary model for the interrupt are constructed;

[0029] Next, the interrupt enable analysis is performed on the source program to be analyzed, the location where the interrupt may be preempted is located, and the interrupt preemption point is determined;

[0030] Finally, for each interrupt preemption point obtained, the interrupt summary is merged and the path constraint conditions of the concurrent access sequence are constructed, which are output to the SMT solver for solving to determine whether the path is feasible. If feasible, it means that the concurrent access sequence is feasible and the interrupt preemption destroys the atomic area.

[0031] Preferably, there are four access interleaving modes, including: and

[0032] For a memory access Among them, P represents the memory access type, t represents the access is a task or interrupt (where h represents an interrupt and l represents a main task), and v represents shared data; the memory access types include read R, write W, read or write A; the two accesses between the square brackets '[' and ']' indicate that the order can be reversed.

[0033] The beneficial effects of the present invention compared with the prior art are:

[0034] Interrupt concurrency defects are one of the key issues affecting the credibility of my country's aerospace embedded software. However, there is currently no automated detection method for the multivariable atomicity violation defect mode, which can only be detected through manual inspection. Since interrupt-driven software is often large-scale, this screening task will consume a lot of manpower and time. This forces us to conduct new detection method research on multivariable atomicity violations in interrupt-driven programs.

[0035] The present invention discloses an interrupt-driven program multivariable atomicity violation detection method. The method uses a machine learning algorithm to automatically infer semantically related associated variables in a program, identify atomic regions composed of multiple variables in the program, and then detect multivariable atomicity violation defects.

[0036] Compared with the existing technology, the present invention has a unique ability to effectively detect multi-variable atomicity violation defects in interrupt-driven programs, which is difficult to achieve with existing methods. This innovation enhances the credibility of software and can help developers and testers identify and resolve potential software defects at an early stage, greatly improving software development and testing efficiency and enhancing software security. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] Figure 1 A flowchart of a method for detecting atomicity violations of multiple variables in an interrupt-driven program provided in an embodiment of the present application;

[0038] Figure 2 A framework diagram of an interrupt-driven program multi-variable atomicity violation detection method provided in an embodiment of the present application;

[0039] Figure 3 A schematic diagram of the interrupt preemption point selection process provided in an embodiment of the present application. DETAILED DESCRIPTION

[0040] The present invention will be further described below in conjunction with the embodiments.

[0041] The present invention proposes an interrupt-driven program multivariate atomicity violation detection method, which first uses a machine learning model to infer and identify associated variables in the program, and then detects multivariate atomicity violation defects on this basis.

[0042] The technical path of the present invention is as follows: training of the associated variable pair identification model. In order to train the learning model to identify the associated variable pairs, firstly, the real aerospace embedded software is used as the database, and the source code with design documents, test documents, regression test reports and line comment coverage exceeding 30% is selected as the training data set of the associated variable pairs. Then, the shared variable pairs are used as the object, and feature extraction is performed through static analysis technology. In order to fully extract the features, the correlation characteristics of the associated variables are fully considered when constructing the data set samples, including the data dependency, control dependency, structural relationship, source code distance and naming rules between the variables. The training data set sample is constructed as follows:

[0043] Samples=<Pair,L,R,CO,CD,DD,Arr,Fieds,Name,Label>

[0044] Wherein, Pair represents the variable pair (x, y) in the program; L and R represent the number of times variable x and variable y appear in the program respectively; CO represents the number of times variable x and variable y have a proximity distance relationship, where the proximity distance relationship is determined by analyzing whether the two variables co-appear in the same function in the source code and within a range of less than 10 lines of code; CD represents whether there is a control dependency relationship between the variable pairs, which is identified by the following steps: first, all control statements in the program are identified, such as conditional judgments and loop controls, and they are used as key nodes in the dependency graph. Then, by analyzing the control flow path, which variables are affected by these control nodes, it is determined whether these variables have control dependencies; DD represents whether there is a data dependency relationship between the variable pairs x and y, which is identified by the following steps: first, the program code is analyzed, the access points of all global variables are identified, and these nodes are mapped accordingly on the dependency graph. Next, the data dependency path between the two access points is searched on the dependency graph. Specifically, if there is a path from the access point of one variable to the access point of another variable, and this path meets the definition of data dependency (that is, the value of one variable affects the value of another variable), then it can be determined that there is a data dependency relationship between the two variables; Arr and Fields respectively indicate whether they belong to the same array and the same structure. First, analyze whether the variable belongs to an array or a structure. If so, we extract its top-level elements. By comparing the top-level elements, we can determine whether different variables belong to the same data structure; Name indicates whether they have similar naming rules, which is determined by comparing whether the variable names contain a common prefix and whether this prefix accounts for more than 20% of the total naming length of the variable name; Label is the label value. When the value is 1, it means that x and y are an associated variable pair, and when it is 0, it means that they are not an associated variable pair.

[0045] In order to obtain labeled samples, we conduct in-depth understanding and analysis of software documentation and source code, and communicate with developers. This process enables us to identify truly associated variable pairs in the software. Finally, we build a learning model and train it using the training dataset to obtain a classifier model that can automatically identify associated variable pairs.

[0046] (1) Identification of associated variable pairs. For a given source program to be analyzed, it is first converted into an intermediate representation that is easy to process and analyze (i.e., an intermediate representation between source code and binary code, which facilitates further static and dynamic analysis). On this basis, multiple key analysis steps are performed, including:

[0047] 1. Function call relationship analysis: Generate a function call graph to show the calling relationship between functions in the program.

[0048] 2. Control flow analysis: Build a control flow graph to show the execution order of control structures in the program.

[0049] 3. Data flow analysis, pointing analysis, and memory analysis: Create a data dependency graph to show the data dependency relationship between variables in the program. Among them, the control flow graph generates a forward dominator tree through forward dominator analysis, and finally forms a control dependency graph. Subsequently, we combine the control dependency graph, data dependency graph, and function call graph to construct a program dependency graph. Then traverse the source code, collect the variable names, access locations, and access times of all global variables, and form variable pairs of all global variables, calculate the number of times they appear adjacently in the program, check whether they belong to the same array or structure, and evaluate whether they have similar naming rules. In addition, by traversing the program dependency graph, the control and data dependency relationships between variable pairs are captured, so as to construct variable pair samples (i.e., test samples). Finally, the obtained test samples are input into the trained classifier model to identify associated variable pairs.

[0050] (2) Multi-variable atomicity violation detection. Atomic regions are obtained based on the identified associated variable pairs, and it is analyzed whether the interrupt preemption may destroy the atomic region. Based on the identified associated variable pairs, the program is subjected to cross-process data flow analysis to identify the reachable accesses between the associated variable pairs and form atomic regions. This step is actually equivalent to defining a reachability analysis. Specifically, on the execution path of the program, it is checked whether the access to the first variable can reach the access to its associated variable. If it is reachable, the two access points are matched to form an atomic region.

[0051] Analyzing whether the interrupt preemption may destroy the atomic zone is further divided into four sub-steps:

[0052] 1) Access interleaving pattern matching. In interrupt-driven programs, four access interleaving patterns are proposed. Four concurrent access sequences that meet these patterns may cause multi-variable atomicity violations: and For a memory access Among them, P represents the memory access type, which can be R (read), W (write) or A (read or write). t represents the task or interrupt that accesses it, and v represents shared data. For example, Indicates a read access to the shared data x of a task or a low-priority interrupt. In addition, the two accesses between the square brackets '[' and ']' indicate that the order can be reversed. For a given program, the four concurrent access sequences that may cause multi-variable atomicity violations are identified through inter-procedural data flow analysis and pattern matching techniques.

[0053] 2) Symbolic summary model construction. After obtaining the four concurrent access sequences that may cause atomicity violations, it is necessary to conduct a feasibility analysis to determine whether they can be true atomicity violations. In order to avoid repeated analysis of interrupts and save analysis overhead, a symbolic summary model is first constructed. Specifically, according to the function call graph, the main program and interrupt program are modularly analyzed from the called function to the calling function from the bottom up. The key point is to perform interference analysis on the associated variables obtained and construct a symbolic summary model for each function and interrupt. These summaries express the side effects of functions and interrupts, and characterize the path constraints and exit states from the entry to the associated variables.

[0054] 3) Interrupt preemption point analysis. Although interrupts may occur at any program point, only some program points will change the feasibility of the concurrent four-access sequence. Therefore, in order to avoid redundant analysis and further save analysis overhead. First, perform interrupt enable analysis on the program to accurately locate the location where interrupt preemption may occur. This analysis process helps us rule out situations where preemption is impossible due to interrupt masking or other reasons. Then, perform interrupt timing analysis to identify and rule out situations where interrupt preemption is impossible at the current moment. Finally, perform representative preemption point selection. Since the feasibility of the concurrent access sequence is only affected when the program statement directly modifies the constraints of two concurrent sub-paths, or modifies the variables on which the constraints depend, the concurrent paths corresponding to some preemption points can be selectively checked without checking all paths.

[0055] 4) Finally, based on the possible interrupt preemption points, the interrupt summary side effects are merged and the path constraints of the interleaved access order are constructed, which are output to the SMT solver for solving to determine whether the path is feasible. If feasible, a warning is given.

[0056] Example

[0057] The following is a further detailed description of an interrupt-driven program multivariable atomicity violation detection method provided by an embodiment of the present application in conjunction with the accompanying drawings. The specific implementation of the method may include the following steps (the method flow is as follows Figure 1 shown):

[0058] Step 1: training phase of the associated variable pair inference model. First, the associated variable pair recognition model of this patent is described, using real aerospace embedded software as a training set, and extracting features between shared variable pairs through association features to construct a training sample set for learning model training.

[0059] First, through the analysis of a large number of real cases, six characteristics of correlation variables are proposed, as shown in Table 1.

[0060] Table 1

[0061]

[0062]

[0063] Then, we selected interrupt-driven software with detailed documentation and annotated source code as the training data set for the associated variables. Since the association between multiple variables can be reflected by their pairwise interactions, we adopted a pairwise analysis strategy to reduce the complexity and overhead of the analysis, and extracted features through static analysis techniques to construct training samples. The constructed sample examples are shown in Table 2:

[0064] Table 2

[0065]

[0066] For example, sample 1 represents the variable pair gTime.Second and gTime.MilliSecond, which both appear 5 times in the program, and all these 5 times they appear together in the same function with a source code distance of less than 10 lines. There is no control dependency between the two variables, but there is a data dependency. The two variables are not array elements of the same array, but are different members of the same structure. The two variables do not have similar naming rules. Through manual analysis and identification, the two variables are associated variables. Similarly, sample 2 represents the variable pair open_count_2 and receive_buffer_A, the former appears 9 times in the program, and the latter appears 8 times, but they have never appeared together, and there is no control dependency and data dependency between them, and there is no structural relationship and similar naming rules. Through manual identification, the two variables are not associated variables. After constructing these sample data, they are input into the XGBoost model for training to obtain the final classifier.

[0067] Step 2: Correlated variable pair identification phase. Then, based on the XGBoost model, the correlated variable pairs in the given input program are identified.

[0068] Specifically, first, Clang is used to convert the target program into an intermediate representation LLVM IR. This process can convert the source code into a more abstract and easy-to-analyze form. On this basis, the tools provided by LLVM or static analysis tools are used to analyze the LLVM IR to generate a function call graph. The nodes in the graph represent functions, and the edges represent the call relationships between functions. In addition, the intermediate representation is used to perform control flow analysis and construct a control flow graph to represent the control flow of the source code. The control flow graph is used to perform forward dominance analysis to generate a forward dominance tree. The forward dominance tree is converted into a graph to generate a control dependency graph, in which the nodes represent basic blocks in the program and the edges represent control dependencies, which indicates whether a node controls another node during execution in the control flow of the program. Subsequently, data flow analysis, pointing analysis, and memory analysis are performed to generate a data dependency graph to represent the dependencies between various data in the program. Finally, the function call graph, data dependency graph, and control dependency graph are combined to form a program dependency graph, which is used to show the dependencies between various elements in the program. By traversing the source code, we collect the variable names, access locations, and access times of all global variables in the program, and build variable pairs of global variables through pairwise matching. We calculate the number of times they co-occur in the program, check whether they belong to the same array or structure, and determine whether they have similar names. By traversing the program dependency graph, we capture the control and data dependencies between variable pairs, and thus build variable pair samples. Finally, we input the variable pair samples into the XGBoost model, and output the resulting associated variable pairs.

[0069] Step 3: Multivariable atomicity violation detection phase. Based on the identified associated variable pairs, the atomic region is obtained and the interrupt preemption is analyzed to see whether it may destroy the atomicity.

[0070] It is divided into four sub-steps:

[0071] Access interleaving pattern matching. According to the associated variable pairs given in step 2, inter-procedural data flow analysis techniques are performed in the main task and each interrupt to obtain all ordered pairs with associated variable accesses. Then, a combined analysis is performed between the main program and the interrupt program to obtain all concurrent four-access sequences consisting of associated variable access pairs. Then, through pattern matching technology, the patterns that may constitute atomicity violations in Table 3 are identified to obtain concurrent four-access sequences that may cause multiple variable atomicity violations.

[0072] Table 3

[0073]

[0074]

[0075] Symbolic summary model construction. Based on the results of step (1), the concurrent four-time access sequence formed by each pair of associated variables is analyzed. Starting from the location of the associated variables, combined with the function call graph, a bottom-up modular analysis is performed from the called function to the calling function. The key point is to first perform interference analysis on the associated variables to be analyzed, and collect all direct and indirect dependencies of the associated variable pairs through the program dependency graph as the interference set S. Then, a symbolic summary model of each function and interrupt is constructed. These summaries are a triple <entry state, path constraint, exit state>, which expresses the side effects of the function and interrupt, and describes the path constraints and exit states from the entry to the associated variables. Among them, the entry state is the context that can affect the feasibility of the concurrent access sequence, which is obtained by intersecting the state of the function call point or interrupt trigger point with the interference set S; the path constraint is the path constraint from the entry point to the associated variable pair; the exit state is the impact of the function or interrupt on the feasibility of the concurrent access sequence.

[0076] Interrupt preemption point analysis. First, perform interrupt enable analysis on the program to accurately locate the location where the interrupt may be preempted. This analysis process helps us exclude those situations where preemption is impossible due to interrupt masking or other reasons, thereby avoiding invalid analysis in these situations, focusing on the interrupt preemption points that really need to be paid attention to, and improving the efficiency and accuracy of the analysis. Secondly, interrupts usually have strict timing constraints in the system. This means that some interrupts will only be triggered when specific time requirements and timing conditions are met. Through interrupt timing analysis, we identify and exclude those situations where interrupt preemption is impossible at the current moment, further enhancing the accuracy of our analysis and ensuring that we focus resources on those interrupt preemption points that may actually have an impact on system behavior. In addition, the feasibility of the concurrent three-access sequence will only be affected when the program statement directly modifies the constraints of the two concurrent sub-paths, or modifies the variables on which the constraints depend. In other words, the side effects of some program statements may have no effect on the results of the feasibility check of these two sub-paths. Therefore, we can selectively check the concurrent paths corresponding to some preemption points without checking all paths. These preemption points are called representative preemption points. For example, Figure 3 As shown, for low priority interrupt ISR L , high priority interrupt ISR H Preemption may occur at m points. However, since the program disables interrupts at point 1 and enables interrupts at point 3, the ISR H It is not possible to preempt between points 1 and 3. By analyzing the interrupt timing, ISR H It can only be triggered under certain time constraints, such as when the ISR LIt can only be triggered when the execution reaches point m-2, so interrupt preemption cannot occur before point m-2. Furthermore, although the interrupt may still be triggered after points m-2 and m-1, since point m-1 does not produce side effects, the interrupt preemption at these two points has no effect on the feasibility of the concurrent access sequence, and there is no need to perform repeated analysis. In the end, only one preemption point needs to be analyzed.

[0077] Concurrent interleaving feasibility analysis. According to the interrupt preemption points obtained, analyze them one by one. For each preemption point, merge the interrupt summary side effects and construct the path constraints of the interleaving concurrent access order, output them to the SMT solver for solving, and determine whether the path is feasible. If feasible, a warning will be given.

[0078] Although the present invention has been disclosed as above in the form of a preferred embodiment, it is not intended to limit the present invention. Any person skilled in the art may make possible changes and modifications to the technical solution of the present invention by using the methods and technical contents disclosed above without departing from the spirit and scope of the present invention. Therefore, any simple modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention shall fall within the protection scope of the technical solution of the present invention.

[0079] Parts not described in detail in the present invention belong to common knowledge of those skilled in the art.

Claims

1. A method for detecting atomicity violations of multiple variables in interrupt-driven programs, characterized in that include: Using real aerospace embedded software as a database, we screened software with detailed documentation and annotated source code as a training dataset for the model used to identify associated variable pairs. Taking the shared variable pairs as the object, the features of the shared variable pairs in the software in the training data set are extracted through static analysis, and the training data set samples that consider the correlation features of the associated variables are constructed; Build a learning model and use the training data set samples for training to obtain a classifier model that can automatically identify associated variable pairs; Analyze the source program to be analyzed and construct variable pair samples as test samples; Inputting the test sample into the classifier model to identify the associated variable pairs; The atomic region is obtained based on the identified associated variable pairs, and it is analyzed whether the interrupt preemption may destroy the atomic region, thus completing the multi-variable atomicity violation detection.

2. The method according to claim 1, characterized in that: The training data set samples are as follows: Samples=<Pair,L,R,CO,CD,DD,Arr,Fieds,Name,Label> Among them, Pair represents the shared variable pair (x, y) in the program, L and R represent the number of times variable x and variable y appear in the program respectively, CO represents the number of times variable x and variable y have a proximity relationship; CD, DD, Arr, Fields and Name represent whether there is a data dependency relationship, a control dependency relationship, whether they belong to the same array, whether they belong to the same structure and whether they have similar naming rules respectively, Label is the label value, when the value is 1, it means that x and y are an associated variable pair, when it is 0, it means that they are not an associated variable pair.

3. The method according to claim 2, characterized in that: The neighbor distance relationship is calculated by analyzing whether two variables co-occur in the same function in the source code with less than 10 lines of code.

4. The method according to claim 2, characterized in that: The similar naming rule compares variable names to see if they contain a common prefix that accounts for more than 20% of the total variable name length.

5. The method according to claim 2, characterized in that: Data dependencies are identified through the following steps: first, the program code is analyzed to identify the access points of all global variables and these nodes are mapped accordingly on the dependency graph; next, the data dependency path between two access points is searched on the dependency graph; if there is a path from the access point of one variable to the access point of another variable and this path meets the definition of data dependency, that is, the value of one variable affects the value of another variable, then it is determined that there is a data dependency relationship between the two variables.

6. The method according to claim 2, characterized in that: Control dependencies are identified through the following steps: first, all control statements in the program are identified and used as key nodes in the dependency graph; then, by analyzing the control flow path, we identify which variables are affected by these control nodes, thereby determining whether these variables have control dependencies.

7. The method according to claim 1, characterized in that: Construct a sample of variable pairs as follows: Convert the source program to be analyzed into an intermediate representation that is easy to process and analyze, that is, an intermediate representation between source code and binary code, which is convenient for further static and dynamic analysis; Based on the intermediate representation, multiple key analysis steps are performed, including function call relationship analysis, to generate a function call graph; Control flow analysis to build control flow graphs; Data flow analysis, pointing analysis, and memory analysis to create data dependency graphs; The control flow graph generates a forward dominance tree through forward dominance analysis, and finally forms a control dependency graph; Combine the control dependency graph, data dependency graph and function call graph to construct the program dependency graph; Traverse the source code of the source program to be analyzed, collect the variable names, access locations and access times of all global variables and form variable pairs of all global variables, calculate the frequency of co-occurrence of variable pairs in the program, check whether the variable pairs belong to the same array or structure, and evaluate whether the variable pairs have similar naming rules; by traversing the program dependency graph, capture the control and data dependency relationships between variable pairs, and thus construct variable pair samples.

8. The method according to claim 1, characterized in that: The atomic region is obtained in the following way: based on the identified associated variable pairs, the program is subjected to cross-process data flow analysis to identify the reachable accesses between the associated variable pairs and form an atomic region, that is, on the program execution path, it is checked whether the access of the first variable can reach the access of its associated variable. If so, the two access points are matched to form an atomic region.

9. The method according to claim 1, characterized in that: Analyze whether the interrupt preemption destroys the atomic area in the following way: An access interleaving pattern that may cause multi-variable atomicity violations for driver-type programs is proposed, which includes four types of concurrent four-time access sequences. According to the identified associated variable pairs, inter-procedural data flow analysis is performed in the main task of the source program to be analyzed and each interrupt program to obtain all ordered pairs with associated variable accesses. The ordered pairs are combined and analyzed between the main program and the interrupt program to obtain concurrent four-time access sequences composed of associated variable pairs. Pattern matching is performed on the four concurrent access sequences and the access interleaving pattern to obtain the four concurrent access sequences that may cause multi-variable atomicity violation; A feasibility analysis is conducted on the concurrent four-access sequence that may cause multi-variable atomicity violations: Specifically, first, interference analysis is conducted on the associated variable pairs in the concurrent four-access sequence, and a function summary model for each function in the main task and interrupt as well as a symbolic summary model for the interrupt are constructed; Next, the interrupt enable analysis is performed on the source program to be analyzed, the location where the interrupt may be preempted is located, and the interrupt preemption point is determined; Finally, for each interrupt preemption point obtained, the interrupt summary is merged and the path constraint conditions of the concurrent access sequence are constructed, which are output to the SMT solver for solving to determine whether the path is feasible. If feasible, it means that the concurrent access sequence is feasible and the interrupt preemption destroys the atomic area.

10. The method according to claim 9, characterized in that: There are four access interleaving modes, including and For a memory access Wherein, P represents the memory access type, t represents the access occurring as a task or interrupt, h represents an interrupt, l represents the main task, and v represents shared data; the memory access types include read R, write W, read or write A; the two accesses between the square brackets '[' and ']' indicate that the order can be reversed.