Source code instrumentation method and device and storage medium

By using register variables in embedded software to cache the running results of instrumentation points, the problems of memory expansion and low operating efficiency are solved, and the test accuracy is improved.

CN118733426APending Publication Date: 2024-10-01SUZHOU DONGCHAYUN INFORMATION TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202310340913.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-03-31
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

The memory expansion problem caused by the existing embedded software instrumentation method increases the impact of code compilation time and system operating efficiency, and the test results are not accurate enough.

Method used

By setting the data structure in the source code, setting register variables for each function, determining the instrumentation point information, performing instrumentation, and saving the running results to the data structure, it reduces memory resource usage and reduces the impact of code instrumentation on system operation. Influence.

Benefits of technology

It effectively reduces the memory expansion rate of source code and improves the accuracy of embedded software testing and system operating efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733426A_ABST
    Figure CN118733426A_ABST
Patent Text Reader

Abstract

The invention discloses a source code instrumentation method. The method comprises the following steps: setting a data structure in a source code; setting a register variable for each function in at least one function included in the source code; determining information of an instrumentation point of each function, and performing instrumentation on the function according to the information of the instrumentation point to obtain an instrumented function; running the instrumented function to obtain a running result of the function; and according to the register variable, storing an operation result of the function into the data structure. The invention further discloses a source code instrumentation device and a storage medium.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a source code plugging method, device and storage medium. Background Art

[0002] Code stubbing technology is often used in the process of software coverage testing to obtain the covered statements, program execution paths, variable references, definitions, etc. However, the storage and operation of the stubbing point information usually leads to code expansion; due to the limited system resources of embedded software, such as small memory, fewer I / 0 channels, etc., excessive code expansion rate may exceed the memory resource limit, thereby increasing the compilation time of the code. For example, the function stubbing method in the existing embedded software stubbing method, on the one hand, needs to insert the function to insert the stubbing point. During the implementation process, the inserted function may be interrupted by other interrupt programs with higher priority, resulting in inaccurate results of the stubbing test; on the other hand, the inserted function needs to generate and store data in the memory during implementation, which may cause the code scale of the system to increase, thereby seriously affecting the operating efficiency of the system (more than 50%).

[0003] Therefore, it is necessary to provide an embedded software instrumentation method to solve the problem of excessive memory expansion caused by instrumentation. Summary of the invention

[0004] In order to solve the existing technical problems, the embodiments of the present invention provide a source code stub method, device and storage medium.

[0005] The technical solution of the present invention is achieved in this way:

[0006] In a first aspect, an embodiment of the present invention provides a source code stub method, wherein the source code includes at least one function; the method includes:

[0007] Setting a data structure in the source code;

[0008] setting a register variable for each of the at least one function;

[0009] Determine the information of the insertion point of each of the functions, and insert the function according to the information of the insertion point to obtain an inserted function;

[0010] Running the instrumented function to obtain the running result of the function;

[0011] According to the register variable, the running result of the function is saved in the data structure.

[0012] In the above solution, the step of setting a register variable for each function in the at least one function includes:

[0013] For each of the functions, a first register variable is set at the head of the function, and a first register is allocated to the first register variable; the first register is used to cache a first address of the running result of the function in the data structure;

[0014] A second register variable is set at the head of the function, and a second register is allocated to the second register variable; the second register is used to cache the running result of the function.

[0015] In the above solution, the step of inserting the function according to the information of the insertion point to obtain the inserted function includes:

[0016] Before the function is run, preset plug-in content is inserted into the plug-in point of the function according to the information of the plug-in point; the plug-in content is used to record the running result of the function during the running of the function.

[0017] In the above scheme, the step of saving the running result of the function to the data structure according to the register variable includes:

[0018] According to the first address of the first register cache, the running result of the function in the second register cache is saved to the first address of the data structure.

[0019] In the above scheme, the method further comprises:

[0020] Before the function is run, an assembly function is set in the function; the assembly function is used to save the running result of the function into the data structure according to the register variable before the function is run.

[0021] Determine that the function has finished running, and call the assembly function.

[0022] In the above scheme, the plugging content includes a preset assignment statement; the information of the plugging point includes: the position of the plugging point, the index value of the code block where the plugging point is located;

[0023] The inserting preset instrumentation content at the instrumentation point of the function according to the information of the instrumentation point includes:

[0024] According to the position of the insertion point, inserting a preset assignment statement at the insertion point;

[0025] In the above solution, the step of running the instrumented function to obtain the running result of the function includes:

[0026] Determine a bit in a second register variable of the function that is identical to an index value of the code block where the insertion point is located, and assign a value of 1 to the identical bit;

[0027] The result after assigning the second register variable is determined as the running result of the function; the running result represents the code block run in the function.

[0028] In the above solution, the setting of the data structure in the source code includes:

[0029] In the source code, a data structure is set for all functions included in the source code; the data structure is used to store the running results of all the functions.

[0030] In the above scheme, the source code includes at least one source file; each source file includes at least one function; and setting a data structure in the source code includes:

[0031] In the source code, a data structure is set for each source file in the at least one source file; the data structure is used to store the running results of all functions included in the source file.

[0032] In a second aspect, an embodiment of the present invention provides a source code plugging device, the device comprising: a setting module and a processing module; wherein:

[0033] The setting module is used to set a data structure in the source code; and set a register variable for each function in at least one function;

[0034] The processing module is used to determine the information of the insertion point of each function, insert the function according to the information of the insertion point to obtain the inserted function; run the inserted function to obtain the running result of the function; and save the running result of the function to the data structure according to the register variable.

[0035] In the above scheme, the setting module is specifically used for

[0036] For each of the functions, a first register variable is set at the head of the function, and a first register is allocated to the first register variable; the first register is used to cache a first address of the running result of the function in the data structure;

[0037] A second register variable is set at the head of the function, and a second register is allocated to the second register variable; the second register is used to cache the running result of the function.

[0038] In the above solution, the processing module is specifically used for

[0039] Before running the function, preset plug-in content is inserted into the plug-in point of the function according to the information of the plug-in point; the plug-in content is used to record the running result of the function during the running of the function.

[0040] In the above solution, the processing module is specifically used for

[0041] According to the first address of the first register cache, the running result of the function in the second register cache is saved to the first address of the data structure.

[0042] In the above solution, the processing module is also used

[0043] Before the function is run, an assembly function is set in the function; the assembly function is used to save the running result of the function into the data structure according to the register variable before the function is run.

[0044] Determine that the function has finished running, and call the assembly function.

[0045] In the above scheme, the plugging content includes a preset assignment statement; the information of the plugging point includes: the position of the plugging point, the index value of the code block where the plugging point is located; the processing module is specifically used to

[0046] According to the position of the insertion point, inserting a preset assignment statement at the insertion point;

[0047] Determine a bit in a second register variable of the function that is identical to an index value of the code block where the insertion point is located, and assign a value of 1 to the identical bit;

[0048] The result after assigning the second register variable is determined as the running result of the function; the running result represents the code block run in the function.

[0049] In the above scheme, the setting module is specifically used for

[0050] In the source code, a data structure is set for all functions included in the source code; the data structure is used to store the running results of all the functions.

[0051] In the above scheme, the source code includes at least one source file; each source file includes at least one function; the setting module is specifically used to

[0052] In the source code, a data structure is set for each source file in the at least one source file; the data structure is used to store the running results of all functions included in the source file.

[0053] In a third aspect, an embodiment of the present invention further provides a source code instrumentation device, comprising a memory, a processor, and an executable program stored in the memory and capable of being run by the processor, wherein the processor executes the steps of the source code instrumentation method provided by the embodiment of the present invention when running the executable program.

[0054] In a fourth aspect, an embodiment of the present invention further provides a storage medium on which an executable program is stored, and when the executable program is executed by a processor, the steps of the source code stubbing method provided by the embodiment of the present invention are implemented.

[0055] The source code stubbing method, device and storage medium provided by the embodiment of the present invention include: setting a data structure in the source code; setting a register variable for each function in at least one function included in the source code; determining the information of the stubbing point of each function, stubbing the function according to the information of the stubbing point, and obtaining the stubbing function; running the stubbing function to obtain the running result of the function; and saving the running result of the function to the data structure according to the register variable. In this way, by using register variables to cache the running results of the stubbing points, the memory resource occupation caused by code stubbing is reduced, the impact of code stubbing on the system running efficiency is reduced, and the accuracy of embedded software testing is further improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0056] Figure 1 A schematic diagram of a flow chart of a source code plugging method provided by an embodiment of the present invention;

[0057] Figure 2 A schematic diagram of a flow chart of a source code plugging method provided by an application embodiment of the present invention;

[0058] Figure 3 A schematic flow chart of another source code plugging method provided for an application embodiment of the present invention;

[0059] Figure 4 A schematic diagram of the structure of a source code plugging device provided by an embodiment of the present invention;

[0060] Figure 5 A schematic diagram of the structure of another source code instrumentation device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0061] In various embodiments of the present invention, a data structure is set in the source code; a register variable is set for each function in at least one function included in the source code; information of the insertion point of each function is determined, and the function is inserted according to the information of the insertion point to obtain an inserted function; the inserted function is run to obtain an operation result of the function; and the operation result of the function is saved in the data structure according to the register variable.

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

[0063] Figure 1 A schematic diagram of a flow chart of a source code plugging method provided by an embodiment of the present invention; Figure 1 As shown, the method is applied to a device for performing source code plugging, for example, it can be applied to intelligent electronic devices such as servers and computers; the method includes:

[0064] Step 101, setting a data structure in the source code;

[0065] In some embodiments, setting a data structure in the source code includes:

[0066] In the source code, a data structure is set for all functions included in the source code; the data structure is used to store the running results of all the functions.

[0067] Specifically, the source code may include at least one function. For the at least one function included in the source code, a data structure is set in the memory to store the information of the insertion points to which all functions in the source code are run.

[0068] In some embodiments, setting a data structure in the source code includes:

[0069] In the source code, a data structure is set for each source file in the at least one source file; the data structure is used to store the running results of all functions included in the source file.

[0070] Specifically, the source code may include at least one source file, each of the at least one source file may include at least one function. For each source file in the source code, a data structure is respectively set in the memory to store the information of the insertion points to which all functions in each of the source files are run.

[0071] Here, on the one hand, by storing the running results of all the functions through a data structure, it is possible to intuitively see which insertion points in all the functions have not been run through the elements of the data structure, thereby improving the efficiency of coverage testing; on the other hand, by storing the running results of the function through at least one data structure, it can be ensured that all the insertion points where the function is run are reflected in the data structure, thereby ensuring the accuracy of the source code test.

[0072] In some embodiments, the data structure includes, but is not limited to, one of the following: an array; a stack; a queue; a linked list.

[0073] For example, the data structure may be an array, wherein the type of the array element is a bit data type, the array element is defined by bytes, and the array element is aligned to 32 bits (Binary digit, Bit).

[0074] Here, the alignment refers to that the device assigns array elements to appropriate locations in the memory according to the size of the array elements, so that storage space can be saved through alignment.

[0075] The bit is a unit of information. The information contained in one bit of a binary number is 1 bit. For example, the memory size occupied by the binary number 0100 is 4 bits.

[0076] The byte is a unit of computer data storage. One byte stores 8 bits, that is, 1 Byte=8 Bit. The size of an integer in memory is 1 Byte.

[0077] In addition, the bit data type can take two values, 0 and 1. When a value other than 0 is input, the system regards the other value as 1.

[0078] Step 102: setting a register variable for each function in the at least one function;

[0079] In some embodiments, setting a register variable for each of the at least one function comprises:

[0080] For each of the functions, a first register variable is set at the head of the function, and a first register is allocated to the first register variable; the first register is used to cache a first address of the running result of the function in the data structure;

[0081] A second register variable is set at the head of the function, and a second register is allocated to the second register variable; the second register is used to cache the running result of the function.

[0082] Here, the setting may refer to a definition, and the setting or definition may refer to defining a variable or function in the code. After the definition is executed, the device (such as a computer or a server) to which the method is applied will allocate a block of memory in the memory to the defined variable or function.

[0083] Specifically, the device may define at least one second register variable in the header of each function in the source code, allocate a corresponding second register to each second register variable, and initialize each second register variable to 0.

[0084] The number of second register variables is related to the maximum index value of the code block corresponding to each function. The larger the maximum index value of the code block corresponding to the function, the more second registers are needed to cache the results of the insertion point operation; the number of second registers is at most four to avoid a major impact on the optimization of the compiler (such as the C language compiler, C++ compiler).

[0085] In actual application, if the maximum index value of the code block corresponding to the function does not exceed the maximum storage bit number of a second register, a second register variable is defined;

[0086] If the maximum index value of the code block corresponding to the function exceeds the maximum storage bit of one second register and does not exceed the maximum storage bit of two second registers, two second register variables are defined;

[0087] If the maximum index value of the code block corresponding to the function exceeds the maximum storage bits of two second registers and does not exceed the maximum storage bits of three second registers, three second register variables are defined;

[0088] If the maximum index value of the code block corresponding to the function exceeds the maximum storage bits of three second registers and does not exceed the maximum storage bits of four second registers, four second register variables are defined;

[0089] If the maximum index value of the code block corresponding to the function exceeds the maximum storage bits of the four second registers, the portion exceeding the maximum storage bits of the four second registers is not stored through the second registers but is stored through the memory.

[0090] Furthermore, when the maximum index value of the code block corresponding to the function is not less than the maximum storage bit of the two second registers, that is, at least two second register variables need to be defined, the second registers respectively corresponding to the second register variables are continuous in the memory.

[0091] For example, when two second register variables are defined, the two second register variables correspond to the second registers r1 and r2 respectively; the end address of the second register r1 in the memory is consistent with the start address of the second register r2 in the memory, or the start address of the second register r1 in the memory is consistent with the end address of the second register r2 in the memory; the operation results stored in the second register r1 and the second register r2 are also continuous and uninterrupted.

[0092] In addition, the maximum storage bit refers to the exponential value of the maximum storage value of the register. For example, the maximum storage value of a 32-bit register is 2 to the power of 32, that is, the maximum storage bit of the 32-bit register is 32.

[0093] Specifically, the device can define a first register variable in the header of each function in the source code, and the first register corresponding to the first register variable is used to cache the first address in the data structure (which can be an array); the running result during the running of the function can be stored as a whole in the data structure (such as an array) through the first address; in this way, the storage speed of the running result can be improved, thereby improving the efficiency of the test.

[0094] In addition, the device can define a second register variable in the header of each function in the source code, and the second register corresponding to the second register variable is used to cache the running results; the running results of each function can be cached by the second register without frequently storing the running results in the memory. In this way, the frequency of access to the memory can be reduced, and the storage pressure of the memory can also be reduced, thereby improving the responsiveness of the system.

[0095] Step 103: Determine the information of the insertion point of each function, and insert the function according to the information of the insertion point to obtain an inserted function.

[0096] In some embodiments, instrumenting the function according to the information of the instrumentation point to obtain the instrumented function includes:

[0097] Before the function is run, preset plug-in content is inserted into the plug-in point of the function according to the information of the plug-in point; the plug-in content is used to record the running result of the function during the running of the function.

[0098] In some embodiments, the instrumentation content includes a preset assignment statement; the information of the instrumentation point includes: the location of the instrumentation point, and the index value of the code block where the instrumentation point is located;

[0099] The inserting preset instrumentation content at the instrumentation point of the function according to the information of the instrumentation point includes:

[0100] According to the position of the insertion point, a preset assignment statement is inserted at the insertion point.

[0101] Specifically, the preset assignment statement may be a statement for performing assignment after a bitwise OR operation, wherein the bitwise OR operation indicates that the binary bits corresponding to the two numbers involved in the operation are ORed, and as long as one of the two corresponding binary bits is 1, the result bit is 1. For example, the binary values ​​0001 and 0010 are bitwise ORed, and the result is 0011.

[0102] In some embodiments, source code may be instrumented by array instrumentation.

[0103] Specifically, array instrumentation refers to defining at least one array in the source code. The instrumentation content corresponding to the instrumentation point is the assignment statement for the array elements. The information of the instrumentation point can be stored in the array and sent periodically, thereby tracking the execution path of the source code.

[0104] Specifically, before inserting the source code, the source code can be precompiled and the code text of the source code can be replaced; the source code can be grammatically analyzed to obtain the language type and control flow information of the source code; the start and end positions of each function in the source code are determined; the control flow information is further analyzed to obtain the basic execution path of the source code and the information of the insertion points; according to the information of the insertion points, the insertion content is inserted into the insertion points of the source code to realize the tracking and recording of the basic execution path of the source code.

[0105] Here, the pre-compilation is also called pre-processing, which is the first work in the whole compilation process.

[0106] The control flow information refers to the order in which instructions or evaluations in the source code are executed during the execution of the source code.

[0107] Furthermore, the source code is divided into basic blocks, which are a sequence of continuous code statements or expressions, which can only be entered from its unique entrance and control can only be transferred at the unique exit at the end. If one of the code statements is executed, all the code statements can be executed.

[0108] Here, the source code includes at least one source file, each source file includes at least one function, and according to the definition of basic blocks, each function can be divided into at least one code block; each code block corresponds to an index value, and the index value can uniquely identify a code block.

[0109] In some embodiments, the language type of the source code includes but is not limited to one of the following: C language; C++; JAVA; Python. Different language types correspond to different compilers, and the compiler converts the source code into binary and gives it to the device for execution.

[0110] For example, the language type of the source code may be C language, and the compiler may be a C language compiler.

[0111] Step 104: Run the instrumented function to obtain the running result of the function.

[0112] In some embodiments, the running of the instrumented function to obtain the running result of the function includes:

[0113] Determine a bit in a second register variable of the function that is identical to an index value of the code block where the insertion point is located, and assign a value of 1 to the identical bit;

[0114] The result after assigning the second register variable is determined as the running result of the function; the running result represents the code block run in the function.

[0115] Specifically, the running result of the code block in the function is 1, indicating that the code block is executed during the function running process.

[0116] Step 105: Save the running result of the function into the data structure according to the register variable.

[0117] In some embodiments, the step of saving the execution result of the function to the data structure according to the register variable comprises:

[0118] According to the first address of the first register cache, the running result of the function in the second register cache is saved to the first address of the data structure.

[0119] In actual application, frequently saving the running result of the function to the first address of the data structure may cause the problem of excessive memory usage, thereby affecting the efficiency of the test.

[0120] Based on this, in some embodiments, the method further includes:

[0121] Before the function is run, an assembly function is set in the function; the assembly function is used to save the running result of the function into the data structure according to the register variable before the function is run.

[0122] Determine that the function has finished running, and call the assembly function.

[0123] Specifically, an assembly function is set in the function, and it is determined that the function has ended (that is, the running status represents the end of the running), and the assembly function is called to save the running result of the function into a data structure (such as an array). In this way, by determining that the function has ended, the running results are stored in the data structure in a centralized manner, thereby avoiding the occupation of memory when frequently saving data, thereby saving memory space, alleviating code expansion, and improving test efficiency and accuracy.

[0124] Here, the assembly refers to the process of translating assembly language into equivalent machine language; the assembly language refers to the low-level language used for the device, also known as symbolic language; the assembly function refers to a program module written in assembly language, which is used to implement a specific function.

[0125] A specific example is provided below in combination with any of the above embodiments:

[0126] Figure 2 A schematic diagram of a source code plugging method provided by an application embodiment of the present invention; Figure 2 As shown, the language type of the source code is C language; the method includes:

[0127] Step 201: Divide the source code into one or more code blocks;

[0128] Specifically, there are the following source codes in C language:

[0129]

[0130]

[0131] Here, the source code is parsed and divided into multiple code blocks according to the definition of basic blocks. For example, the source code is divided as shown in Table 1 below:

[0132]

[0133] Table 1

[0134] As shown in Table 1, the source code is specifically divided into five code blocks, each code block corresponds to an index value, and the index value uniquely determines a code block; for example, the index value 0 determines the first code block, and the index value 4 determines the fifth code block.

[0135] Step 202: perform array stubbing on the source code according to the code block, run the stubbing source code, and determine the running result of the function included in the source code;

[0136] In some embodiments, after step 201, the method further includes:

[0137] Determine the insertion point information of the source code according to the code block; the insertion point information includes the location information of the insertion point and the index value of the code block where the insertion point is located;

[0138] Here, the insertion points of the source code are inserted according to the insertion point information. The source code is inserted using an array (equivalent to a data structure), and at least one of integer insertion and bit insertion can be used.

[0139] In one example, integer stubbing refers to using integers to assign array values ​​as the stubbing content of the source code. The code after the source code is stubbing with integers is as follows:

[0140]

[0141]

[0142] Specifically, the code defines an array with an integer data type and a name of _zoa_instru_data_1. The array has five elements, namely _zoa_instru_data_1[0], _zoa_instru_data_1[1], _zoa_instru_data_1[2], _zoa_instru_data_1[3] and _zoa_instru_data_1[4]. The integer 1 is assigned to the corresponding element in the array at the insertion point to record the code block that is run. However, this method of using integer assignment, since the size of each integer in the memory is 1 Byte, each insertion point also requires a memory size of 1 Byte, so that the code expansion rate is still large and cannot play a role in reducing the expansion rate.

[0143] In another example, Bit stubbing refers to using Bit to assign values ​​to an array as the stubbing content of the source code, while simplifying the code instructions for array operations, so that the expansion rate of the source code after stubbing is as low as possible while ensuring that sufficient operation results are obtained. The simplified code instructions for array operations mean that the array does not need to be repeatedly assigned and saved.

[0144] For example, the code after using Bit to instrument the source code is as follows:

[0145]

[0146]

[0147]

[0148] Specifically, the code "char__zoa_instru_data_1[4];" indicates the definition of an array of type char, which has four elements. Each of the elements occupies only one Byte in the memory, and the default value of each of the elements is 0, which reduces the expansion rate of the source code.

[0149] Preferably, Bit plugging is selected as the array plugging method.

[0150] Among them, in the code example of the Bit stub, the code "register int__reg0__asm__("r5")=0" means defining a second register variable __reg0 in the function header, allocating the second register r5 to __reg0, and initializing the value of __reg0 to 0.

[0151] Here, the keyword "__asm__" can start inline assembly and can be written in any legal statement in C language or C++; the keyword "__asm__" cannot appear alone, and must be connected to an assembly instruction, a group of instructions enclosed by curly braces, or a pair of empty brackets; the term "__asm__ block" here refers to any instruction or a group of instructions whether or not they are in brackets. Braces can clearly separate C language or C++ code from assembly code, avoiding unnecessary repetition of the keyword "__asm__" and avoiding code ambiguity. Among them, the inline assembly refers to assembly code embedded in C language or C++ code.

[0152] The code “register ZOA_DATA_TYPE*zoaDD__asm__("r10")=(&__zoa_data_instru_1[0]);” indicates that a first register variable zoaDD is defined in the function header, and a first register r10 is allocated to the first register variable zoaDD for caching the first address corresponding to the function in the array char__zoa_instru_data_1[]. __zoa_data_instru_1[0] corresponds to the first insertion point of the function, and &__zoa_data_instru_1[0] indicates the first address of the first insertion point in the array char__zoa_instru_data_1[].

[0153] The code "__reg0|=1" corresponds to the first insertion point __zoa_data_instru_1[0], which means that a bitwise OR operation is performed on the value 1 (i.e., binary 00000001) and the second register variable __reg0 whose initial value is 0, and the value after the bitwise OR operation (i.e., the running result of the first insertion point in the function) is assigned to __reg0, and the second register r5 caches the running result of the first insertion point with a size of one bit.

[0154] Here, the code "__reg0|=1" is the preset plug-in content of the first plug-in point; the value after the bitwise OR operation is assigned to the second register variable __reg0, which is the preset assignment statement of the first plug-in point.

[0155] The operator "|=" means bitwise OR and post-assignment. For example, there is the following code:

[0156] x=0001;

[0157] x|=0010;

[0158] Here, the variable x with a binary value of 0001 is bitwise ORed with the binary value 0010, and the result is 0011. The binary value 0011 is assigned to the variable x, that is, the binary value of the variable x after the bitwise OR assignment is 0011.

[0159] Similarly, the code “__reg0|=2” corresponds to the second insertion point __zoa_data_instru_1[1], indicating that the value 2 (ie, binary 00000010) is assigned to the second register variable __reg0 in a bitwise OR operation, and the second register r5 caches the operation result of the second insertion point in a size of one bit.

[0160] The code “__reg0|=4” corresponds to the third insertion point __zoa_data_instru_1[2], indicating that the value 4 (ie, binary 00000100) is assigned to the second register variable __reg0 in a bitwise OR operation, and the second register r5 caches the operation result of the third insertion point in a size of one bit.

[0161] The code “__reg0|=8” corresponds to the fourth insertion point __zoa_data_instru_1[3], indicating that the value 8 (ie, binary 00001000) is assigned to the second register variable __reg0 in a bitwise OR operation, and the second register r5 caches the operation result of the fourth insertion point in a size of one bit.

[0162] The code “__reg0|=16” corresponds to the fifth insertion point __zoa_data_instru_1[4], indicating that the value 16 (ie, binary 00010000) is assigned to the second register variable __reg0 in a bitwise OR operation, and the second register r5 caches the operation result of the fifth insertion point in a size of one bit.

[0163]

[0164]

[0165] It indicates that by calling the assembly function _zoa_dd_write_back1, the running result of the function cached in the second register r5 corresponding to the second register variable __reg0 is saved to the first address of the array __zoa_instru_data_1[].

[0166]

[0167] It is used to instruct the compiler to modify the address of the first register variable zoaDD and use the first register variable __reg0 as input, so as to avoid compiler optimization causing other operations on other registers used in the assembly function _zoa_dd_write_back1, thereby improving the stability of the write-back process.

[0168] In one example, if all five insertion points are executed during the execution of the source code, the execution result of the function cached in the second register r5 is "00011111", which indicates that the code blocks corresponding to the five insertion points in the function have all been executed.

[0169] By caching the function's running result in the second register r5, the number of times the source code accesses the memory is greatly reduced, the response time of the source code is shortened, and the utilization rate of storage resources is increased. In addition, since the assignment statement is also a statement in assembly and the execution time is very short, it avoids being interrupted by other requests, thereby improving the efficiency of coverage testing.

[0170] Step 203: write the running result of the function back to the array.

[0171] In some embodiments, after completing the array stubbing of the source code in step 202, before writing the running result back to the array, it is necessary to allocate a second register for each second register variable, and the second register is used to cache the running result of each function in the source code; the number of second registers is related to the maximum index value of the code block where the function is located, and the larger the maximum index value of the code block corresponding to the function, the more second registers are required; under the premise of using an Advanced RISC Machine (ARM) processor, the number of second registers is at most four.

[0172] Specifically, the first address of the first register cache saves the operating result of the second register cache to the first address through the assembly function.

[0173] In one example, when the second register is one, for example, the maximum index value of the code block where the function is located in the source code is 4, which does not exceed the maximum storage bit number of 32 of a single second register, then a second register r5 can be defined to cache the running result of the function, the first register r10 is used to cache the first address of the function in the array, and the assembly function _zoa_dd_write_back1 is used to write back the cached running result.

[0174] Specifically, the code of the assembly function _zoa_dd_write_back1 is:

[0175]

[0176] Among them, the code "Assembly language" means that this section of code is assembly language.

[0177] The code ".text" indicates that the following is a portion of an executable program with code.

[0178] In the code “.global_zoa_dd_write_back1”, global is a pseudo instruction, which is used to add an external link to the symbol _zoa_dd_write_back1.

[0179] The code “_zoa_dd_write_back1:” means that an assembly function named _zoa_dd_write_back1 is defined below.

[0180] The code "push{r2}" means pushing the word data (4 bytes, i.e. 32 bits) carried in register r2 into the system stack for storage; the push is an assembly language instruction, indicating a stacking operation, and its format is "push{a certain register}", which is used to push the data cached in a certain register into the stack; after the data in register r2 is pushed into the system stack, register r2 is empty.

[0181] Here, register r2 is a third register set in the processor, which is different from the first register r10 and the second register r5, and is used as a relay register to write the cached operation result back to the first address during the write-back process of the assembly function _zoa_dd_write_back1.

[0182] In addition, the number of the third registers is the same as the number of the second registers, and the number of the third registers is at most 4.

[0183] Furthermore, in the assembly, a section of memory is defined as a stack, and the characteristic of the stack is that data is first-in, last-out.

[0184] For example, the data "1", "2", "3" and "4" are stored in the stack in sequence, and the order of popping out the data is "4", "3", "2" and "1".

[0185] The code "ldm r10,{r2}" means caching the data in the first address cached by the first register r10 into the third register r2; since the data in the first address cached by the first register r10 are all 0, after calling the ldm instruction, the data cached in the third register r2 is consistent with the first register r10 and is also 0; the ldm is an assembly language instruction used to cache data at a segment of addresses in memory into multiple registers.

[0186] The code "orr r2,r2,r5" means performing an OR operation on the second register r5 and the third register r2, and caching the result in the third register r2; since the data cached in the third register r2 are all 0, calling the orr instruction will not change the operation result cached in the second register r5, and the operation result will be cached in the third register r2; the orr instruction is used to perform a logical OR operation on two operands, and cache the operation result in the target register.

[0187] The code "stm r10,{r2}" indicates that the operation result cached in the third register r2 is written into the first address cached in the first register r10; the stm instruction is used to write data of multiple registers into the memory.

[0188] Here, the operation result cached in the second register r5 is stored in the first address cached in the first register r10 through the third register.

[0189] Furthermore, the first address is stored in the big-endian in the memory, that is, the high-order bytes are stored at the low-address end of the memory, ensuring that the running results in the second register r5 are stored in the first address in the correct order of function running in the source code.

[0190] The code "pop{r2}" indicates that the 32-bit word data stored in the system stack is loaded back into the third register r2; the pop instruction is used to pop the stack.

[0191] The code "bx lr" indicates that the program will be returned from the subroutine and terminated; the bx instruction is used to jump to the target address specified in the instruction; and the lr is a link register used to store the return address of the subroutine.

[0192] Here, the return address of the subroutine is the address of the instruction that continues to be executed after the main program returns from the subroutine; before entering the subroutine, the return address of the subroutine is first stored in the lr; when the subroutine is called by an instruction, the hardware automatically saves the return address of the subroutine to the lr register.

[0193] In another example, when the maximum index value of the code block corresponding to the function exceeds the maximum storage bit of a second register and does not exceed the maximum storage bits of two second registers, two second register variables are defined, namely r5 and r6. The two second registers are used to cache the running results of the function, the first register r10 is used to cache the first address of the function in the array, and the assembly function _zoa_dd_write_back2 is used to write back the cached running results.

[0194] Specifically, the code of the assembly function _zoa_dd_write_back2 is:

[0195]

[0196] Here, the code "push{r2,r3}" indicates setting two third registers, r2 and r3, in the processor, and pushing the data of the two third registers into the stack.

[0197] The code “ldm r10,{r2,r3}” indicates caching the data in the first address cached by the first register r10 into the third registers r2 and r3.

[0198] The code “orr r2, r2, r5” indicates performing an OR operation on the third register r2 and the second register r5, and caching the result in the third register r2.

[0199] The code “orr r3, r3, r6” indicates performing an OR operation on the third register r3 and the second register r6, and caching the result in the third register r3.

[0200] The code “stm r10,{r2,r3}” indicates writing the operation result cached in the third registers r2 and r3 into the first address cached in the first register r10.

[0201] The code “pop{r2,r3}” indicates loading the word data stored in the system stack back into the third registers r2 and r3 respectively.

[0202] The code "bx lr" indicates that the program will return from the subroutine and end.

[0203] In another example, when the maximum index value of the code block corresponding to the function exceeds the maximum storage bits of two second registers and does not exceed the maximum storage bits of three second registers, three second register variables are defined, namely r5, r6 and r7. The three second registers are used to cache the running results of the function, the first register r10 is used to cache the first address of the function in the array, and the assembly function _zoa_dd_write_back3 is used to write back the cached running results.

[0204] Specifically, the code of the assembly function _zoa_dd_write_back3 is:

[0205]

[0206] Here, the code "push{r2, r3, r4}" indicates setting three third registers in the processor, namely r2, r3 and r4, and pushing the data of the three third registers into the stack.

[0207] The code “ldm r10,{r2,r3,r4}” indicates caching the data in the first address cached by the first register r10 into the third registers r2, r3 and r4.

[0208] The code “orr r2, r2, r5” indicates performing an OR operation on the third register r2 and the second register r5, and caching the result in the third register r2.

[0209] The code “orr r3, r3, r6” indicates performing an OR operation on the third register r3 and the second register r6, and caching the result in the third register r3.

[0210] The code “orr r4, r4, r7” indicates performing an OR operation on the third register r4 and the second register r7, and caching the result in the third register r4.

[0211] The code “stm r10,{r2,r3,r4}” indicates writing the operation result cached in the third registers r2, r3 and r4 into the first address cached in the first register r10.

[0212] The code “pop{r2, r3, r4}” indicates loading the word data stored in the system stack back into the third registers r2, r3 and r4 respectively.

[0213] The code "bx lr" indicates that the program will return from the subroutine and end.

[0214] In another example, when the maximum index value of the code block corresponding to the function exceeds the maximum storage bits of three second registers and does not exceed the maximum storage bits of four second registers, four second register variables are defined, namely r5, r6, r7 and r8. The four second registers are used to cache the running results of the function, the first register r10 is used to cache the first address of the function in the array, and the assembly function _zoa_dd_write_back4 is used to write back the cached running results.

[0215] Specifically, the code of the assembly function _zoa_dd_write_back4 is:

[0216]

[0217]

[0218] Here, the code “push{r1, r2, r3, r4}” indicates selecting four third registers in the processor, namely r1, r2, r3 and r4, and pushing the data of the four third registers into the stack.

[0219] The code “ldm r10,{r1,r2,r3,r4}” indicates caching the data in the first address cached by the first register r10 into the third registers r1, r2, r3 and r4.

[0220] The code “orr r1, r1, r5” indicates performing an OR operation on the third register r1 and the second register r5, and caching the result in the third register r1.

[0221] The code “orr r2, r2, r6” indicates performing an OR operation on the third register r2 and the second register r6, and caching the result in the third register r2.

[0222] The code “orr r3, r3, r7” indicates performing an OR operation on the third register r3 and the second register r7, and caching the result in the third register r3.

[0223] The code “orr r4, r4, r8” indicates performing an OR operation on the third register r4 and the second register r8, and caching the result in the third register r4.

[0224] The code “stm r10,{r1,r2,r3,r4}” indicates writing the operation result cached in the third registers r1, r2, r3 and r4 into the first address cached in the first register r10.

[0225] The code “pop{r1, r2, r3, r4}” indicates loading the word data stored in the system stack back into the third registers r1, r2, r3 and r4 respectively.

[0226] The code "bx lr" indicates that the program will return from the subroutine and end.

[0227] The method of the embodiment of the present invention takes into account that the existing embedded software plugging method cannot effectively reduce the memory expansion rate of the plugging point processing method of the embedded software, therefore, a source code plugging method is proposed, by setting a data structure in the source code, setting a register variable for each function in the at least one function, determining the information of the plugging point of each function, plugging the function according to the information of the plugging point to obtain the plugged function, running the plugged function to obtain the running result of the function, and saving the running result of the function to the data structure according to the register variable, which not only effectively reduces the memory expansion rate of the source code, but also reduces the influence of code plugging on the system running efficiency, and further improves the accuracy of embedded software testing.

[0228] Figure 3 A flow chart of another source code plugging method provided by an application embodiment of the present invention; Figure 3 As shown, the source code stub method includes:

[0229] Step 301, determining the information of the insertion point in the source code;

[0230] Here, the source code may include at least one source file, each source file includes at least one function, each function may correspond to at least one code block; each code block corresponds to an index value, and the index value may uniquely identify a code block.

[0231] Here, the information of the insertion point includes: the position of the insertion point and the index value of the code block where the insertion point is located.

[0232] Step 302: insert the source code according to the information of the insertion point, run the inserted source code, and determine the running result of the function;

[0233] Specifically, for each source file of the source code, an array can be defined in the memory respectively; a first register variable can be defined in the header of the function, a first register can be allocated to the first register variable, and the first register can be used to cache the first address of the running result of the function in the array; at least one second register variable can be defined in the header of the function, a second register can be allocated to the second register variable, and the second register can be used to cache the running result of the function.

[0234] Specifically, the source code is instrumented, and the instrumented content may be a statement that uses a bit value to assign a value to the second register variable in a bitwise or post-assignment manner. When the source code runs to a corresponding instrumentation point, the assignment statement is executed to assign a value to the second register variable. The running result of the function may be a result of the bitwise or post-assignment of the second register variable corresponding to the instrumentation point.

[0235] Specifically, the array is used to store the running results of all functions included in the source file.

[0236] Step 303: Write the function's running result back to the memory.

[0237] Specifically, the step 303 includes: saving the running result of the function cached in the second register to the first address of the array by assembling the function.

[0238] In actual application, the number of second registers is related to the maximum index value of the code block corresponding to each function. The larger the maximum index value of the code block corresponding to the function, the more second registers may be required.

[0239] Based on this, the method may further include: determining the number of second registers, and saving the running results of the functions cached by each second register to the first address of the array, so as to ensure that the running results of the functions cached by all second registers are saved in the memory.

[0240] Specifically, the first register and the second register are both registers, and registers are the main components of the processor. The more general registers in the processor, the more insertion points that can be cached, and the better the optimization effect on the source code; for example, for a 64-bit processor (such as an ARM64 processor), it has 31 64-bit general registers, so more registers can be used, more insertion points can be cached, and a better optimization effect can be achieved; for a 32-bit processor (such as RISCV-32I), since it has 31 32-bit general registers, its optimization effect will also be better than that of an ARM processor.

[0241] Here, a general register is a type of register, and a register that is not assigned a specific purpose is a general register.

[0242] In some embodiments, the embodiments of the present invention use a 32-bit processor, and the 32-bit processor has 32-bit registers. The running result of an insertion point in the function is stored in 1 bit. One register can cache up to 32 running results, and 4 registers can cache up to 128 running results.

[0243] Here, the 32-bit processor may be an ARM processor. The advantages of the ARM processor are small size, low power consumption, low cost and high performance, which can further improve the effect of this embodiment in reducing the code expansion rate.

[0244] Figure 4 A schematic diagram of the structure of a source code plugging device provided by an embodiment of the present invention is shown in FIG. Figure 4 As shown, the device can be applied to intelligent electronic devices such as servers and computers; the device 40 includes: a setting module 401 and a processing module 402; wherein,

[0245] The setting module 401 is used to set the data structure in the source code;

[0246] setting a register variable for each of the at least one function;

[0247] The processing module 402 is used to determine the information of the insertion point of each function, and insert the function according to the information of the insertion point to obtain the inserted function;

[0248] Running the instrumented function to obtain the running result of the function;

[0249] According to the register variable, the running result of the function is saved in the data structure.

[0250] Specifically, the setting module 401 is used to set a first register variable at the head of each function and allocate a first register to the first register variable; the first register is used to cache the first address of the running result of the function in the data structure;

[0251] A second register variable is set at the head of the function, and a second register is allocated to the second register variable; the second register is used to cache the running result of the function.

[0252] Specifically, the processing module 402 is used to insert preset instrumentation content at the instrumentation point of the function according to the information of the instrumentation point before the function is run; the instrumentation content is used to record the running result of the function during the running of the function.

[0253] Specifically, the processing module 402 is further configured to save the running result of the function in the second register cache to the first address of the data structure according to the first address of the first register cache.

[0254] Specifically, the processing module 402 is used to set an assembly function in the function before the function is executed; the assembly function is used to save the execution result of the function to the data structure according to the register variable before the execution of the function ends;

[0255] Determine that the function has finished running, and call the assembly function.

[0256] Specifically, the plugging content includes a preset assignment statement; the information of the plugging point includes: the position of the plugging point, and the index value of the code block where the plugging point is located;

[0257] The processing module 402 is used to insert a preset assignment statement at the insertion point according to the position of the insertion point;

[0258] Determine a bit in a second register variable of the function that is identical to an index value of the code block where the insertion point is located, and assign a value of 1 to the identical bit;

[0259] The result after assigning the second register variable is determined as the running result of the function; the running result represents the code block run in the function.

[0260] Specifically, the processing module 402 is used to set a data structure in the source code for all functions included in the source code; the data structure is used to store the running results of all functions.

[0261] Specifically, the source code includes at least one source file; each of the source files includes at least one function;

[0262] The processing module 402 is used to set a data structure for each source file in the at least one source file in the source code; the data structure is used to store the running results of all functions included in the source file.

[0263] It should be noted that: when the source code plugging device provided in the above embodiment implements the corresponding source code plugging method, only the division of the above program modules is used as an example. In actual applications, the above processing can be assigned to different program modules as needed, that is, the internal structure of the device can be divided into different program modules to complete all or part of the above-described processing. Figure 1 The embodiments of the method shown belong to the same concept, and the specific implementation process is detailed in the method embodiments, which will not be repeated here.

[0264] To implement the method of the embodiment of the present invention, the embodiment of the present invention provides a source code plugging device, such as Figure 5 As shown, the device 50 includes: a processor 501 and a memory 502 for storing a computer program that can be run on the processor; when the processor 501 is used to run the computer program, it executes: setting a data structure in the source code; setting a register variable for each of the at least one function; determining the information of the insertion point of each function, and inserting the function according to the information of the insertion point to obtain an inserted function; running the inserted function to obtain the running result of the function; and saving the running result of the function to the data structure according to the register variable. Specifically, the device can also execute the following Figure 1 The method shown, and Figure 1 The method embodiments shown belong to the same concept, and their specific implementation processes are detailed in the method embodiments, which will not be repeated here.

[0265] In actual application, the device 50 may further include: at least one network interface 503. The various components in the device 50 are coupled together via a bus system 504. It is understood that the bus system 504 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 504 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, Figure 5 In the figure, various buses are labeled as bus system 504. There may be at least one processor 501. The network interface 503 is used for wired or wireless communication between the apparatus 50 and other devices.

[0266] The memory 502 in the embodiment of the present invention is used to store various types of data to support the operation of the device 50 .

[0267] The method disclosed in the above embodiment of the present invention can be applied to the processor 501, or implemented by the processor 501. The processor 501 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 501 or the instruction in the form of software. The above processor 501 can be a general processor, a digital signal processor (DSP, Digital Signal Processor), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The processor 501 can implement or execute the methods, steps and logic block diagrams disclosed in the embodiment of the present invention. The general processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiment of the present invention can be directly embodied as a hardware decoding processor to execute, or the hardware and software modules in the decoding processor can be combined to execute. The software module can be located in a storage medium, which is located in the memory 502. The processor 501 reads the information in the memory 502 and completes the steps of the above method in combination with its hardware.

[0268] In an exemplary embodiment, the device 50 can be implemented by one or more application specific integrated circuits (ASIC), DSP, programmable logic device (PLD), complex programmable logic device (CPLD), field programmable gate array (FPGA), general processor, controller, microcontroller (MCU), microprocessor, or other electronic components to execute the aforementioned method.

[0269] The embodiment of the present invention also provides a computer-readable storage medium, on which a computer program is stored; when the computer program is executed by a processor, the following is performed: setting a data structure in the source code; setting a register variable for each of the at least one function; determining the information of the insertion point of each of the functions, inserting the function according to the information of the insertion point, and obtaining an inserted function; running the inserted function to obtain the running result of the function; and saving the running result of the function to the data structure according to the register variable. Specifically, the computer program can also perform the following Figure 1 The method shown, and Figure 1The method embodiments shown belong to the same concept, and their specific implementation processes are detailed in the method embodiments, which will not be repeated here.

[0270] In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored, or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

[0271] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0272] In addition, all functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.

[0273] A person of ordinary skill in the art can understand that: all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), disks or optical disks, etc. Various media that can store program codes.

[0274] Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention can be essentially or partly reflected in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.

[0275] It should be noted that: "first", "second", etc. are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0276] In addition, the technical solutions described in the embodiments of the present application can be combined arbitrarily without conflict.

[0277] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. A source code instrumentation method, characterized in that: The source code includes at least one function; the method includes: Setting a data structure in the source code; setting a register variable for each of the at least one function; Determine the information of the insertion point of each of the functions, and insert the function according to the information of the insertion point to obtain an inserted function; Running the instrumented function to obtain the running result of the function; According to the register variable, the running result of the function is saved in the data structure.

2. The method according to claim 1, characterized in that The step of setting a register variable for each of the at least one function comprises: For each of the functions, a first register variable is set at the head of the function, and a first register is allocated to the first register variable; the first register is used to cache a first address of the running result of the function in the data structure; A second register variable is set at the head of the function, and a second register is allocated to the second register variable; the second register is used to cache the running result of the function.

3. The method according to claim 1, characterized in that The step of inserting the function according to the information of the insertion point to obtain the inserted function includes: Before the function is run, preset plug-in content is inserted into the plug-in point of the function according to the information of the plug-in point; the plug-in content is used to record the running result of the function during the running of the function.

4. The method according to claim 2, characterized in that: The step of saving the running result of the function to the data structure according to the register variable comprises: According to the first address of the first register cache, the running result of the function in the second register cache is saved to the first address of the data structure.

5. The method according to claim 4, characterized in that The method further comprises: Before the function is run, an assembly function is set in the function; the assembly function is used to save the running result of the function into the data structure according to the register variable before the function is run. Determine that the function has finished running, and call the assembly function.

6. The method according to claim 3, characterized in that The plugging content includes a preset assignment statement; the plugging point information includes: the location of the plugging point, and the index value of the code block where the plugging point is located; The inserting preset instrumentation content at the instrumentation point of the function according to the information of the instrumentation point includes: According to the position of the insertion point, inserting a preset assignment statement at the insertion point; The running of the instrumented function to obtain the running result of the function includes: Determine a bit in a second register variable of the function that is identical to an index value of the code block where the insertion point is located, and assign a value of 1 to the identical bit; The result after assigning the second register variable is determined as the running result of the function; the running result represents the code block run in the function.

7. The method according to claim 1, characterized in that The step of setting a data structure in the source code comprises: In the source code, a data structure is set for all functions included in the source code; the data structure is used to store the running results of all the functions.

8. The method according to claim 1, characterized in that The source code includes at least one source file; each of the source files includes at least one function; The step of setting a data structure in the source code comprises: In the source code, a data structure is respectively set for each source file in the at least one source file; The data structure is used to store the running results of all functions included in the source file.

9. A source code plugging device, characterized in that: The device comprises: a setting module and a processing module; wherein, The setting module is used to set a data structure in the source code; setting a register variable for each of the at least one function; The processing module is used to determine the information of the insertion point of each function, insert the function according to the information of the insertion point to obtain the inserted function; run the inserted function to obtain the running result of the function; According to the register variable, the running result of the function is saved in the data structure.

10. The device according to claim 9, characterized in that The setting module is specifically used to set a first register variable at the head of each function and allocate a first register to the first register variable; the first register is used to cache the first address of the running result of the function in the data structure; Setting a second register variable in the header of the function and allocating a second register to the second register variable; The second register is used to cache the running result of the function.

11. The device according to claim 9, characterized in that The processing module is specifically used to insert preset plug-in content at the plug-in point of the function according to the information of the plug-in point before running the function; the plug-in content is used to record the running result of the function during the running of the function.

12. The device according to claim 10, characterized in that The processing module is specifically configured to save the running result of the function cached by the second register to the first address of the data structure according to the first address of the first register cache.

13. The device according to claim 12, characterized in that The processing module is also used Before the function is run, an assembly function is set in the function; the assembly function is used to save the running result of the function into the data structure according to the register variable before the function is run. Determine that the function has finished running, and call the assembly function.

14. The device according to claim 11, characterized in that The plugging content includes a preset assignment statement; the information of the plugging point includes: the location of the plugging point, the index value of the code block where the plugging point is located; the processing module is specifically used to According to the position of the insertion point, inserting a preset assignment statement at the insertion point; Determine a bit in a second register variable of the function that is identical to an index value of the code block where the insertion point is located, and assign a value of 1 to the identical bit; The result after assigning the second register variable is determined as the running result of the function; the running result represents the code block run in the function.

15. The device according to claim 9, characterized in that The setting module is specifically used to set a data structure in the source code for the source code including all functions; the data structure is used to store the running results of all the functions.

16. The device according to claim 9, characterized in that The source code includes at least one source file; each source file includes at least one function; the setting module is specifically used for In the source code, a data structure is set for each source file in the at least one source file; the data structure is used to store the running results of all functions included in the source file.

17. A source code plugging device, characterized in that: The device comprises a network interface, a memory and a processor; wherein, The network interface is used to realize connection and communication between components; The memory is used to store a computer program that can be run on the processor; The processor is used to execute the method according to any one of claims 1 to 8 when running the computer program.

18. A computer storage medium, characterized in that The computer storage medium stores a computer program, and when the computer program is executed by at least one processor, the method according to any one of claims 1 to 8 is implemented.

Citation Information

Cited By

  • Method and device for detecting bit displacement of key function code segment of relay protection device

    CN119988179A

  • Method and device for detecting bit shift of key function code segment of relay protection device

    CN119988179B