Static and dynamic debugging method for RISC-V random instruction block
By generating static and dynamic debugging information, the characteristics and locations of RISC-V random instruction blocks are revealed, solving the problem of insufficient instruction block information in existing technologies and improving the efficiency and accuracy of instruction generation and debugging.
Patent Information
- Application Number
- CN202410436317.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-11
- Publication Date
- 2025-10-24
Smart Images

Figure CN120832298A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of computer architecture verification, in particular to a static and dynamic debugging method for RISC-V random instruction blocks. BACKGROUND
[0002] In the CPU verification process, generating a large number of random test instruction sets is a key means to improve verification coverage. The block-based random instruction generation algorithm can conveniently generate test instruction sets by converting the jumps between instructions into jumps between instruction blocks. However, the instruction sets generated by the existing technology cannot reflect the relevant information of the instruction blocks contained, and the debugging process is complex and difficult to improve specifically.
[0003] The block-based random instruction generation algorithm is one of the methods currently used to generate RISC-V random instructions. Its algorithm mainly consists of two parts: block labeling algorithm and block filling algorithm. The main idea of this method is to convert the jumps between instructions into jumps between instruction blocks. The specific implementation method is as follows: first, execute the block labeling algorithm, divide a continuous instruction space into several instruction blocks of different sizes using the block segmentation function, use the block attribute function and the target block search function to determine the order relationship of the execution of each instruction block according to the offset obtained from the continuously updated source block and the random target block position, and label the attributes of the blocks. Use the block traversal function to check whether all blocks have been marked; after all the block attribute marking is completed, execute the block filling algorithm, fill the corresponding instructions according to the different block attributes, such as Figure 1 It is noted that the block labeling algorithm does not label the instruction blocks in natural order, while the block filling algorithm fills each instruction block in natural order.
[0004] Although the block-based random instruction generation algorithm can conveniently generate test instruction sets, since the instruction sets are randomly generated and the obtained instruction assembly file only contains the information of each specific instruction, it is impossible to reflect the relevant information of the specific instruction blocks contained in the instruction set. However, the test process of the CPU is complex and variable, and the change of a certain test requirement may require modification of the internal structure of some instruction blocks or addition of instruction blocks with different functions, so it is necessary to clearly present whether the instruction set generated after the change can correctly present the functions described at the code level of the instruction generation algorithm, so as to improve it specifically. SUMMARY
[0005] The present application proposes a static and dynamic debugging method for RISC-V random instruction blocks, which mainly realizes two functions:
[0006] Static debugging: the name, number, internal instruction structure, external loop nesting or calling structure and jump relationship before and after the instruction block can be obtained through the generated static instruction assembler;
[0007] Dynamic debugging: according to the static instruction assembler, the block name, block number and loop nesting level of each instruction can be marked in the instruction stream log after the dynamic execution of the program.
[0008] A static debugging method for RISC-V random instruction blocks, the method comprising:
[0009] S1, generating static debugging information, which reveals the following characteristics of the instruction block by analyzing the static instruction assembler:
[0010] The name and number of the instruction block;
[0011] The internal instruction structure of the instruction block;
[0012] The generation of the static debugging information further comprises:
[0013] S11, obtaining the lexicographic block number, which is used to generate a test instruction set for the RISC-V architecture, to convert the jump between instructions into the jump between instruction blocks, to simplify the code logic and improve the generation efficiency of the test instruction set, to introduce a special block type of subroutine calling structure and loop structure, and to introduce a block attribute function and a block traversal function for marking the block number, and to introduce a stack push and pop operation for tracking and marking the special block number.
[0014] The subroutine calling structure comprises a subroutine calling block, a subroutine entry block, a subroutine stack block, a subroutine return block and a subroutine reserved block;
[0015] The block attribute function is used to generate the subroutine calling structure, the loop structure and other conventional blocks, and the number of loop layers of the special instruction block is recorded, the special instruction block number is pushed to the stack, the sub-instruction space is divided, and the block numbers of some special instruction blocks are recorded.
[0016] The block traversal function is used to mark the block numbers of all quasi-source blocks, check whether the attributes of all blocks are marked and whether the block numbers of all blocks are marked, and pop the stack to release the stack operation performed in the block attribute function, to update the position of the source block in the sub-instruction space or the global instruction space, and mark the block number of the special block released by the stack.
[0017] The loop structure includes: a loop control block, a loop return block, a loop return predecessor block and a loop reserve block; in the subroutine call structure or loop structure, if the number of blocks contained in the structure reaches a certain requirement, it is necessary to enter the temporary instruction space where the structure is located to mark the blocks in the instruction space with block attributes. In order to define the upper and lower limits of the temporary instruction space, protect register values, and be able to return to the correct block number for subsequent marking operations after exiting the temporary instruction space, it is necessary to push the corresponding block number into the stack, and pop these block numbers when exiting the temporary instruction space. Whether the stack needs to be pushed / popped is related to the total number of instruction blocks contained in the structure;
[0018] S12. Mark the loop level where the block is located. Use loop control counters and stack operations to mark the loop level where the block is located. When generating an assembly instruction set containing block information, the loop level where a block is located will be indexed by the block number.
[0019] S13, generating an assembly instruction set including block information;
[0020] Generate an assembly instruction set containing the block information, insert uppercase block name characters and block number before the first instruction of each instruction block, and insert a line break before the block name characters and block number to achieve a separation effect and increase readability; insert lowercase block name characters, block number and loop level number after each instruction; in order to ensure that the instructions in the assembly instruction set are arranged in the direction of increasing PC address, the block filling algorithm fills the instruction block in natural order; in order to avoid the newly added block information causing the assembly instruction set to be unable to be compiled into an executable file, the assembly instruction set containing the block information is written into another file for static debugging only, thereby obtaining an assembly instruction set containing the block name, block number and loop level number of the block; the required block information includes the block name, block number and loop level number of the instruction, which can be obtained from the assembly instruction set containing the block information; use a simulator to run the executable file generated by the assembly instruction set to obtain a dynamic instruction stream;
[0021] S14. Inserting directed annotations and auxiliary information into the assembly instruction set containing the block information. Using a static debugging script, generate directed annotations by performing two staggered permutations based on the block numbers in the obtained dictionary sequence table. To increase processing speed, a multi-stage pipeline is used to perform the replacement operation in the static debugging script, thereby obtaining an assembly instruction set containing complete static debugging information, including directed annotations for each instruction block and necessary auxiliary information. The block numbers in the obtained dictionary sequence table are then subjected to two staggered permutations by the static debugging script, which is a bash shell script, to obtain directed annotations. Each block number in the dictionary sequence table and the directed annotation corresponding to the block number form a dictionary.
[0022] S2, modification of subroutine call structure and subroutine reserved block, including:
[0023] the external loop nesting relationship of instruction blocks or the subroutine call structure;
[0024] the jump relationship between instruction blocks, including forward and backward jumps; the subroutine call block controlled by the direct jump instruction; the subroutine call block controlled by the register jump instruction; according to the specific instruction in the subroutine call block, the successor block of the subroutine return block and the predecessor block of the subroutine reserved block are modified to ensure the accuracy of the debugging information.
[0025] A static debugging method for RISC-V random instruction blocks, the step S11 is specifically:
[0026] S111, enter the block attribute function: judge what kind of instruction block structure can be generated by the instruction space surrounded by the source block position and the target block position, and mark the block number according to different structures that can be generated;
[0027] S1111, if the subroutine call structure can be generated, the block attribute is valued and marked according to the number of blocks contained in the subroutine structure; since the subroutine call structure contains any number of blocks, it must contain the subroutine call block and the subroutine reserved block, and the two blocks will be updated as the source block in the traversal order, that is, they belong to the quasi-source block, and their block numbers are recorded in the block traversal function; the number of "subroutine blocks" described below is the number of special blocks contained in the subroutine call structure after removing the subroutine call block and the subroutine reserved block: if the number of subroutine blocks is 1, the subroutine only contains one subroutine return block, there is no stack operation, and the block number of the block is directly marked in the block attribute function; if the number of subroutine blocks is 2, the subroutine contains one subroutine entry block and one subroutine return block, there is no stack operation, and the block numbers of the two blocks are directly marked in the block attribute function; if the number of subroutine blocks is 3, there is a stack operation, the subroutine contains one subroutine entry block, one subroutine return block and one regular block, the regular block is located between the subroutine entry block and the subroutine return block, and the block number of the subroutine entry block is marked in the block attribute function; since there is a stack operation, the block number pushed into the stack is the block number of the subroutine return block, so the stack needs to be popped in the block traversal function and the block number of the subroutine return block is marked; if the number of subroutine blocks is greater than 3, there is a stack operation, the subroutine contains one subroutine entry block, one subroutine return block and other internal regular instruction blocks, the block number of the subroutine entry block is marked in the block attribute function, the block numbers of the subroutine return block and the subroutine stack block are pushed into the stack, and the block numbers of the two blocks are marked in the block traversal function, the remaining regular instruction blocks are quasi-source blocks, and the remaining regular instruction blocks are marked in the block traversal function;
[0028] S1112, if the subroutine call structure cannot be generated, it is determined whether the instruction space can generate a loop structure. If the loop structure can be generated, the block attribute is valued and the block number is marked according to the number of blocks contained in the loop structure. Since the loop structure contains a certain number of blocks, it must contain a loop reserved block, and the loop reserved block will not be executed in the loop structure. Therefore, the "loop block number" described below is the number of special blocks contained in the loop structure after removing the loop reserved block; the loop reserved block and the loop control block belong to the quasi-source block, so the block number is marked in the block traversal function; if the loop block number is 2, the loop structure includes the loop control block and the loop return block, and there is no stack operation. The block number of the loop return block is directly marked in the block attribute function; if the loop block number is greater than 2, the loop structure includes the loop control block, the loop return predecessor block and the loop return block, and there is a stack operation. The block numbers of the loop return block and the loop return predecessor block are pushed into the stack. Since the loop return predecessor block also belongs to the quasi-source block, the block number of the loop return predecessor block is directly marked in the block traversal function, and the block number of the loop return block is marked after the stack is popped.
[0029] S1113, if the subroutine call structure and the loop structure cannot be generated, it is determined which kind of regular instruction block is generated. Since these regular instruction blocks are quasi-source blocks, the marking of the block number is performed in the block traversal function; S112, enter the block traversal function: mark the quasi-source block number, and mark the special type of instruction block according to the type of instruction block generated in the block attribute function and whether there is a stack operation.
[0030] A static debugging method for RISC-V random instruction blocks, the steps S12 are specifically:
[0031] S121, mark the number of loop levels in which the block is located: a new attribute is added to the block attribute, that is, the number of loop levels in which the block is located, so that the information can be obtained in the block filling function subsequently;
[0032] S122, use the loop control counter: use the loop control counter to track and control the increase and decrease of the number of loop levels, so as to ensure that the number of loop levels of each block can be correctly marked;
[0033] S123, enter the loop structure: when entering the loop structure, the value of the loop control counter is correspondingly increased; S124, mark other blocks in the loop structure: when marking other blocks in the loop structure, the value of the loop control counter is kept unchanged;
[0034] In the loop structure, the loop control block and the loop reserved block are both quasi-source blocks, so no tracking mark is needed; the loop return block is special, although it is not pushed to the stack, but its predecessor block is pushed to the stack, which is equivalent to an indirect stack operation, so in the block attribute function, the block number of the loop return block can be indirectly obtained from the stack, and its block number is the loop return predecessor block number + 1; for the loop return block without stack operation, tracking mark is recorded in the block attribute function;
[0035] S125, exit the loop: the exit of the loop is controlled by the pop stack operation in the block traversal function, and the loop level of the special type instruction block popped out of the stack is recorded before the loop control counter is reduced;
[0036] S126, record the loop level of the non-quasi-source block: the loop level of the non-quasi-source block is recorded when its block number is marked;
[0037] The step S13 is specifically:
[0038] S131, generate an assembly instruction set containing block information: before the start of each instruction block, insert a line containing the uppercase block name character, the block number and a line feed character, to improve the readability of the assembly instruction set;
[0039] S132, append block information to each instruction: append the lowercase block name character, the block number and the loop level of the block where the instruction belongs to after each instruction, to further enrich the block information in the assembly instruction set; S133, fill using block filling algorithm: fill according to the natural order of instruction blocks, to ensure that the instructions in the generated assembly instruction set are arranged in ascending order according to the program counter PC address;
[0040] S134, output the assembly instruction set with block information to a new file: in order to avoid the added block information interfering with the compilation process of the assembly instruction set, output the assembly instruction set with block information to a new file, which is used for static debugging analysis, not directly for compilation and execution;
[0041] S135, realize the generation of the assembly instruction set containing complete block information;
[0042] The step S14 is specifically:
[0043] S141, insert directed labels and auxiliary information: using the static debugging script, according to the block number in the lexicographic list obtained, generate directed labels by two times of transposition, the format is predecessor block number -> current block number -> successor block number;
[0044] S142, create a dictionary pair: create a dictionary to pair each block number with its corresponding directed label, to realize the query of the predecessor and successor block numbers through the block number;
[0045] S143, replacing the block number right to the capital block name character: using the static debugging script, finding the block number right to the capital block name character in the generated assembly instruction set and replacing it with the corresponding directed label;
[0046] S144, replacing operation is performed in a multi-stage pipeline mode: in order to improve the processing speed, the replacing operation in the static debugging script is performed in a multi-stage pipeline mode;
[0047] S145, inserting auxiliary information into subroutine call blocks and loop control blocks: for subroutine call blocks, the auxiliary information includes subroutine return block block numbers; and for loop control blocks, the auxiliary information includes loop return block block numbers and loop reserved block block numbers;
[0048] S146, ensuring that the auxiliary information source contains necessary block number information: these information can be directly obtained from the block attribute function.
[0049] A static debugging method for RISC-V random instruction blocks, in the subroutine call structure, for subroutine call blocks, whether stack operation is performed or not, the block number of the subroutine call block can be updated to the source block number, that is, the subroutine call block belongs to the quasi-source block, and when the block traversal function acts on this block, the block index will be recorded at the same time; for subroutine entry blocks, if the number of blocks in the subroutine structure reaches the stack operation requirement, since its execution order is earlier than that of other regular blocks in the subroutine structure, the block number thereof is tracked and marked in the block attribute function;
[0050] On the basis of the original block attributes, a new attribute, i.e., the number of loop layers in which the block is located, is added, and the number of loop layers in which the block is located can be obtained in the block labeling function, wherein the block attribute function records the number of loop layers in which all non-quasi-source blocks are located; the block traversal function records the number of loop layers in which all quasi-source blocks are located, since all non-quasi-source block numbers and quasi-source block numbers constitute all block numbers in the current instruction space, the marking of the number of loop layers in which each block is located is completed without omission.
[0051] A static debugging method for RISC-V random instruction blocks, in order to accelerate the replacing speed of the directed label, a multi-stage pipeline mode is used in the static debugging script;
[0052] The implementation mode of the multi-stage pipeline is as follows:
[0053] The pipeline replacing is divided into several groups, the upper limit of the number of pipeline stages in each group is denoted as MAX_PIPE, the number of replacing lines is denoted as LINES, the number of replacing groups is denoted as N, if LINES is an integer multiple of MAX_PIPE, then
[0054] N = LINES / MAX_PIPE
[0055] If LINES is not an integer multiple of MAX_PIPE, then there are
[0056] N = [LINES / MAX_PIPE] + 1
[0057] Wherein, the “[]” represents rounding down, and the number of pipeline stages in the last group is less than MAX_PIPE if LINES is not an integer multiple of MAX_PIPE; if different MAX_PIPE is given or LINES changes, an exact N can be obtained adaptively, and the multi-stage pipeline adaptive grouping replacement operation is completed according to the above.
[0058] A dynamic debugging method for RISC-V random instruction blocks, the method relies on block information and dynamic instruction flow, and the dynamic instruction flow is obtained by running an executable file generated by an assembly instruction set using a simulator, wherein the required block information includes the block name, block number and loop layer number where the instruction is located, and can be obtained from an assembly instruction set containing block information, a multi-stage pipeline command mode is used, and multi-stage pipeline grouping replacement is used to implement multi-stage pipeline grouping replacement, and n-stage pipeline can execute n+1 commands.
[0059] A dynamic debugging method for RISC-V random instruction blocks, the method also includes: since the PC address of an instruction uniquely corresponds to an instruction, the dynamic instruction flow is based on a static assembly instruction set, and therefore each instruction in the dynamic instruction flow and its PC address can be found in the static assembly instruction set.
[0060] A dynamic debugging method for RISC-V random instruction blocks, the method also includes: recording the PC address as key, and recording the block name, block number and loop layer number where the instruction is located as value, and only need to insert value before key in the dynamic instruction flow, that is, replace the beginning of the line of the dynamic instruction flow log file with value, and the dynamic instruction flow containing block information can be obtained; the dynamic instruction flow more detailedly and completely shows how the block information changes during the running of each instruction.
[0061] A dynamic debugging method for RISC-V random instruction blocks, and the multi-stage pipeline command mode specifically includes: adopting a grouping replacement strategy, after each replacement is completed, the result is saved to a temporary file tmp.1og through a redirection command, and the tmp.1og is renamed as insn_tr.log using a mv command; in the next group replacement, the insn_tr.log is read again and the replacement, redirection and renaming operations are performed; in the replacement process, the number of replacement groups is determined by calculating the quotient of the number of replacement lines and the upper limit of the number of pipeline stages in each group, so as to realize the adaptive grouping replacement operation of the multi-stage pipeline.
[0062] A dynamic debugging method for RISC-V random instruction blocks, in order to always use the multi-stage pipeline mode in the replacement process, the replacement needs to be divided into several groups, and the upper limit of the number of pipeline stages in each group is recorded as MAX_PIPE, the number of replacement lines is LINES, and the number of replacement groups is N. If LINES is an integer multiple of MAX_PIPE, then
[0063] N=LINES / MAX_PIPE
[0064] If LINES is not an integer multiple of MAX_PIPE, then
[0065] N=[LINES / MAX_PIPE]+1
[0066] Wherein "[]" represents rounding down, and in the case of a non-integer multiple, the number of pipeline stages in the last group is less than MAX_PIPE. If different MAX_PIPE is given, or LINES changes, an exact N can be obtained adaptively, and the multi-stage pipeline adaptive grouping replacement operation is completed according to the above. BRIEF DESCRIPTION OF DRAWINGS
[0067] The present specification will be further illustrated in the form of exemplary embodiments, which will be described in detail with reference to the accompanying drawings. These embodiments are not limiting, and in these embodiments, the same numbers represent the same structures, wherein:
[0068] Figure 1 is a flowchart of existing instruction block labeling and instruction padding;
[0069] Figure 2 is a flowchart of the static debugging method provided by the embodiment of the present application;
[0070] Figure 3 is a flowchart of generating static debugging information provided by the embodiment of the present application;
[0071] Figure 4 is a flowchart of judging the instruction space surrounded by the source block position and the target block position to generate which instruction block structure provided by the embodiment of the present application.
[0072] Figure 5 is a flowchart of updating the source block number and the target block number provided by the embodiment of the present application;
[0073] Figure 6 is a schematic diagram of subprogram call structure provided by the embodiment of the present application;
[0074] Figure 7 is a schematic diagram of loop structure provided by the embodiment of the present application;
[0075] Figure 8is a process diagram of obtaining a dictionary sequence provided by an embodiment of the present application;
[0076] Figure 9 is a static and dynamic debugging file diagram of a subroutine call structure provided by an embodiment of the present application;
[0077] Figure 10 is a static and dynamic debugging file diagram of a loop structure provided by an embodiment of the present application;
[0078] Figure 11 is a flowchart of the number of loop layers in which a marking block is located provided by an embodiment of the present application;
[0079] Figure 12 is a flowchart of generating an assembly instruction set containing block information provided by an embodiment of the present application;
[0080] Figure 13 is a flowchart of inserting directed labels and auxiliary information in an assembly instruction set containing block information provided by an embodiment of the present application.
[0081] Figure 14 is a schematic diagram of block number misalignment arrangement and directed labeling provided by an embodiment of the present application;
[0082] Figure 15 is a correction flowchart of a subroutine call block and a subroutine reserved block provided by an embodiment of the present application;
[0083] Figure 16 is an internal structure diagram of two kinds of subroutine call blocks provided by an embodiment of the present application;
[0084] Figure 17 is a multi-stage pipeline adaptive grouping replacement flowchart provided by an embodiment of the present application. DETAILED DESCRIPTION
[0085] In order to more clearly understand the above-mentioned purposes, features and advantages of the present application, the embodiments of the present application will be further described below. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict.
[0086] In the following description, many specific details are set forth in order to provide a thorough understanding of the present application, but the present application can also be implemented in other ways different from those described herein. Obviously, the embodiments in the specification are only some of the embodiments of the present application, not all the embodiments.
[0087] The present patent adds a function for implementing static and dynamic debugging in the block labeling algorithm and block filling algorithm of the block-based random instruction generation algorithm.
[0088] I. A static debugging method for RISC-V random instruction blocks, as shown inFigure 2 The method comprises:
[0089] S1, generating static debugging information;
[0090] S2, modification of subroutine call structure and subroutine reserved block.
[0091] Regarding the generation of static debugging information in step S1, the information reveals the following characteristics of the instruction block by analyzing the static instruction assembler:
[0092] The name and number of the instruction block;
[0093] The internal instruction structure of the instruction block;
[0094] The external loop nesting relationship or subroutine call structure of the instruction block;
[0095] The jump relationship between instruction blocks, including forward and backward jumps;
[0096] In the process of generating static debugging information, the subroutine call block and the subroutine reserved block are modified, which distinguishes between the following two cases:
[0097] Subroutine call block controlled by direct jump instruction;
[0098] Subroutine call block controlled by register jump instruction;
[0099] According to the specific instructions inside the subroutine call block, the successor block of the subroutine return block and the predecessor block of the subroutine reserved block are modified to ensure the accuracy of the debugging information.
[0100] Regarding the generation of static debugging information as shown in Figure 3 , the specific steps are as follows:
[0101] S11, obtain the lexicographic block number, the specific steps are as follows:
[0102] As shown in Figure 4 , S111, enter the block attribute function: judge what kind of instruction block structure can be generated by the instruction space surrounded by the source block position and the target block position, and mark the block number for different types of instruction blocks according to the different structures that can be generated;
[0103] S1111, if the subroutine call structure can be generated, the block attribute is valued and the block number is marked according to the number of blocks contained in the subroutine structure. Since the subroutine call structure contains the subroutine call block and the subroutine reserved block regardless of the number of blocks, the two blocks are updated as the source block in the traversal order, i.e. both belong to the quasi-source block, and the block number is recorded in the block traversal function. The "subroutine block number" described below is the number of special blocks contained in the subroutine call structure except the subroutine call block and the subroutine reserved block: if the subroutine block number is 1, the subroutine only contains one subroutine return block, there is no stack operation, and the block number of the block is directly marked in the block attribute function; if the subroutine block number is 2, the subroutine contains one subroutine entry block and one subroutine return block, there is no stack operation, and the block numbers of the two blocks are directly marked in the block attribute function; if the subroutine block number is 3, there is a stack operation, the subroutine contains one subroutine entry block, one subroutine return block and one regular block between the subroutine entry block and the subroutine return block, the block number of the subroutine entry block is marked in the block attribute function, and since there is a stack operation, the block number of the subroutine return block is pushed into the stack, so the stack is popped in the block traversal function and the block number of the subroutine return block is marked; if the subroutine block number is greater than 3, there is a stack operation, the subroutine contains one subroutine entry block, one subroutine return block, one subroutine stack block and other internal regular instruction blocks, the block number of the subroutine entry block is marked in the block attribute function, and the block numbers of the subroutine return block and the subroutine stack block are pushed into the stack, so the stack is popped in the block traversal function and the block numbers of the two blocks are marked, and the remaining regular instruction blocks are quasi-source blocks, so they are marked in the block traversal function;
[0104] S1112, if the subroutine call structure cannot be generated, it is determined whether the instruction space can generate a loop structure. If the loop structure can be generated, the block attribute is valued and the block number is marked according to the number of blocks contained in the loop structure. Since the loop structure contains the loop reserved block regardless of the number of blocks, the loop reserved block will not be executed in the loop, and will only be executed when the loop structure is exited, so the "loop block number" described below is the number of special blocks contained in the loop structure except the loop reserved block. The loop reserved block and the loop control block belong to the quasi-source block, so their block numbers are marked in the block traversal function. If the loop block number is 2, the loop structure includes the loop control block and the loop return block, there is no stack operation, and the block number of the loop return block is directly marked in the block attribute function; if the loop block number is greater than 2, the loop structure includes the loop control block, the loop return predecessor block and the loop return block, there is a stack operation, and the block numbers of the loop return block and the loop return predecessor block are pushed into the stack. Since the loop return predecessor block also belongs to the quasi-source block, the block number of the loop return predecessor block is directly marked in the block traversal function after the stack is popped, and the block number of the loop return block is marked;
[0105] S1113, if the subprogram call structure and the loop structure cannot be generated, determine which regular instruction block is generated, since these regular instruction blocks are all quasi-source blocks, the block number markers of which are marked in the block traversal function;
[0106] S112, enter the block traversal function: mark the quasi-source block block number, and according to the instruction block type generated in the block attribute function and whether there is a stack operation, mark the special type of instruction block.
[0107] In the block marking algorithm, the predecessor block of each regular block is determined by the source block number (except for the first block), and the successor block is determined by the target block (except for the tail block). Since the target block is constantly updated to the source block, and the source block is constantly looking for the next target block until the tail block is reached, since the update of the source block number is performed in the block traversal function, to simplify the code logic, the marking of the source block number only needs to be implemented in the block traversal function. As shown in Figure 5 .
[0108] Since in the traversal process, some special block numbers will not be directly updated to the source block according to the traversal order, and need to be tracked and marked, these special block numbers are distributed in the subprogram call structure and the loop structure. The subprogram call structure 100 includes the following five special types of blocks (as shown in Figure 6 .
[0109] Subprogram call block 101: divided into register jump type subprogram call block and direct jump type subprogram call block, which contains register jump instructions or direct jump instructions whose jump target position is the subprogram entry block (or subprogram return block), used to call the subprogram;
[0110] Subprogram entry block 102: the first block of the subprogram;
[0111] Subprogram stack out block 103: appears only when the total number of instruction blocks contained in the subprogram structure > 3 (does not include subprogram reserved block and subprogram call block), used to restore the value in the return register to ensure that the subprogram call can be successfully returned after completion;
[0112] Subprogram return block 104: used to return after the completion of the subprogram call, the return position is the address of the next instruction of the jump instruction in the subprogram call block, i.e. the subprogram return target address;
[0113] Subprogram reserved block 105: the subprogram reserved block must be the successor block of the subprogram call block, used to ensure that the subprogram can be successfully returned when the subprogram return target address is not inside the subprogram call block.
[0114] The loop structure 200 contains the following four special types of blocks (as shown in Figure 7 .
[0115] Loop control block 201: the first block of the loop structure, used to control the loop times and the loop exit target address of the loop structure;
[0116] Loop return block 202: used to return to the loop control block 201 before the loop times are exhausted;
[0117] Loop return predecessor block 203: appears only when the total number of blocks contained in the loop structure > 2 (not including the loop reservation block)
[0118] Loop reservation block 204: used to save the loop exit address, ensuring successful exit after the loop ends.
[0119] In the subroutine call structure 100 or the loop structure 200, if the number of blocks contained in the structure reaches a certain requirement, it is necessary to enter the temporary instruction space where the structure is located to mark the block attribute of the blocks in the instruction space. In order to define the upper and lower limits of the temporary instruction space, protect the register value, and return to the correct block number for subsequent marking operations after exiting the temporary instruction space, it is necessary to push the corresponding block number into the stack and pop these block numbers when exiting the temporary instruction space. Whether to push / pop the stack is related to the total number of instruction blocks contained in the structure, as shown in Table 1.
[0120] In the block attribute function, the block number of each block can be directly obtained, so the tracking mark for a certain block only needs to be placed at the position marked by the block number. In the block traversal function, in addition to the quasi-source block, the block numbers of other special non-quasi-source blocks are recorded in the stack, and the tracking mark for these blocks needs to query the content in the stack. Although some special blocks that execute before other regular blocks can also be recorded in the stack (such as the subroutine entry block 102), for the sake of simplicity, we believe that for instruction blocks with stack operations, whether the tracking mark is located in the block attribute function or the block traversal function depends on whether the actual execution order of the instruction block is before or after other regular blocks within the structure. If the actual execution order of the instruction block is before other regular blocks within the structure, the tracking mark is located in the block attribute function. If the actual execution order of the instruction block is after other regular blocks within the structure, the tracking mark is located in the block traversal function. Therefore, for block number marking, the functions of the block traversal function and the block attribute function can be divided as follows:
[0121] Block attribute function: for structures with stack operations, used to track non-quasi-source blocks whose actual execution order is before other regular blocks within the structure; used to track all non-quasi-source blocks without stack operations;
[0122] Block traversal function: records the block numbers of all quasi-source blocks; for structures with stack operations, used to track non-quasi-source blocks whose actual execution order is after other regular blocks within the structure;
[0123] The sequence composed of the block numbers arranged according to the traversal sequence is a traversal sequence, and the sequence composed of the block numbers arranged according to the dictionary sequence is a dictionary sequence. The process of obtaining the dictionary sequence is shown in Figure 8 .
[0124] In the subroutine call structure, for the subroutine call structure 101, the block number of the subroutine call structure 101 can be updated to the source block number regardless of whether the stack operation is performed, that is, the subroutine call structure 101 belongs to the quasi-source block, and when the block traversal function acts on this block, the block index will be recorded at the same time, so it is not necessary to separately increase the redundant logic; for the subroutine entry block 102, if the number of blocks in the subroutine structure reaches the requirement of the stack operation, since its execution order is earlier than that of other regular blocks in the subroutine structure 100, the block number thereof is tracked and marked in the block attribute function; the subroutine stack-out block 103 only exists in the subroutine structure 100 with the number of blocks greater than 3, so there must be a stack operation, and since the execution order of the subroutine stack-out block 103 is later than that of other regular instruction blocks in the subroutine structure, the block number thereof is tracked and marked in the block traversal function; for the subroutine return block 104 with the stack operation, the execution order thereof is later than that of other regular blocks in the subroutine structure, and the block number thereof is tracked and marked in the block traversal function; for the subroutine return block 104 without the stack operation, the block number thereof is tracked and marked in the block attribute function; and the subroutine reserved block 105 belongs to the quasi-source block, and does not need to be tracked and marked.
[0125] In the loop structure 200, the loop control block 201 and the loop reserved block 204 both belong to the quasi-source block, and thus do not need to be tracked and marked; the loop return block 202 is relatively special, although it does not perform the stack operation, but the preceding block thereof is stacked, which is equivalent to indirectly performing the stack operation, so that the block number of the loop return block 202 can be indirectly obtained from the stack in the block attribute function, and the block number is loop return preceding block number + 1; for the loop return block 202 without the stack operation, the block number is tracked and marked in the block attribute function.
[0126] Overall, the quasi-source block does not need to be tracked and marked, and the non-quasi-source block needs to be tracked and marked. After the block attribute function and the block marking function are used to complete the marking of all block numbers in the current instruction space, the dictionary sequence list of the block numbers can be obtained.
[0127] Figure 9 and Figure 10The contents of static and dynamic debugging files are shown in the figure. The file with suffix ".S" is a static debugging file, and the file with suffix ".log" is a dynamic debugging file. In the static debugging file, the block name in capital letters marked by "[]" is the block name in capital letters. The directed mark on the right side of the block name in capital letters is in the format of "predecessor block number -> (current block number) -> successor block number". The auxiliary information corresponding to each instruction is separated by "#" on the right side of "#", and is in the format of "block name in small letters idx: block number loop_layer: the number of the loop layer in which the block is located". In the dynamic debugging file, the auxiliary information corresponding to each instruction is separated by "#" on the left side of "#", and is in the same format as the auxiliary information corresponding to the aforementioned instruction.
[0128] S12, mark the number of the loop layer in which the block is located; as shown in Figure 11
[0129] S121, mark the number of the loop layer in which the block is located: a new attribute, i.e. the number of the loop layer in which the block is located, is added to the block attribute, so that the information can be obtained in the subsequent block filling function;
[0130] S122, use the loop control counter: the loop control counter is used to track and control the increase and decrease of the number of the loop layer, so as to ensure that the number of the loop layer in which each block is located can be correctly marked; in the block-based random instruction generation algorithm, the loop structure is designed to be able to embed any structure except the tail block, including subprogram structure and loop structure, so in the process of marking the block attribute, in order to correctly mark the number of the loop layer in which each block is located, the loop control counter is increased to control the increase of the number of the loop layer when the loop structure condition is met.
[0131] S123, enter the loop structure: when the loop structure is entered, the value of the loop control counter is correspondingly increased;
[0132] S124, mark other blocks inside the loop structure: when other blocks inside the loop structure are marked, the value of the loop control counter remains unchanged; when other blocks inside the loop structure are marked and no loop is nested again, the loop control counter remains unchanged, i.e. the number of the loop layer in which the blocks inside the loop remains unchanged; after the loop is exited, the loop control counter is decreased, so as to ensure that the number of the loop layer in which the blocks marked after that decreases. In the loop structure, the loop control block and the loop reserved block both belong to the quasi-source block, so there is no need to track the mark; the loop return block is special, although it is not pushed to the stack, but the successor block thereof is pushed to the stack, which is equivalent to indirectly performing the push operation, so in the block attribute function, the block number of the loop return block can be indirectly obtained from the stack, and the block number is loop return predecessor block number + 1; for the loop return block without stack operation, the mark is tracked in the block attribute function;
[0133] S125, exit loop: the exit of loop is controlled by the pop operation in the block traversal function, and the loop level of the quasi-source block is recorded before the loop control counter is decreased; the exit of loop is controlled by the pop operation in the block traversal function, that is, the loop control counter is increased in the block attribute function and is decreased in the block traversal function, and the attribute of the block is uniquely determined by the block number, so the loop level of the block is also uniquely determined by the block number, which is only related to which layer of the loop structure the block number is located in, and is irrelevant to the actual execution order of the block; for the quasi-source block, we only need to record the loop level of the block before the block is updated to the source block, that is, for the quasi-source block, we only need to record the loop level of the block before the loop control counter is decreased.
[0134] S126, record the loop level of the non-quasi-source block: at the same time, the loop level of the non-quasi-source block is recorded when the attribute of the block is marked. For the non-quasi-source block, we only need to record the loop level of the block when the attribute of the block is marked. In step S11, we have explained the different functions of the block attribute function and the block traversal function in the marking of the block number. Here, new functions are added to each of them:
[0135] Block attribute function: record the loop level of all non-quasi-source blocks;
[0136] Block traversal function: record the loop level of all quasi-source blocks;
[0137] Since all non-quasi-source block numbers and quasi-source block numbers make up all block numbers in the current instruction space, the marking of the loop level of each block can be completed without omission.
[0138] S13, generate an assembly instruction set containing block information;
[0139] As shown in FIG. 13, S131, generate an assembly instruction set containing block information: before the start of each instruction block, insert a line containing the uppercase block name character, the block number, and a line feed character to improve the readability of the assembly instruction set; Figure 12
[0140] S132, append block information to each instruction: after each instruction, append the lowercase block name character, the block number of the block to which the instruction belongs, and the loop level of the block to further enrich the block information in the assembly instruction set;
[0141] S133, fill using the block filling algorithm: fill according to the natural order of the instruction block to ensure that the instructions in the generated assembly instruction set are arranged in ascending order according to the program counter (PC) address;
[0142] In S12, we add a new block attribute in the block labeling algorithm, i.e. the number of loop levels where the block is located. The block name and block number are original attributes in the block labeling algorithm, so we only need to supplement the three block information in the assembly instruction set by using the block filling algorithm to generate the assembly instruction set containing block information. The capital block name character and block number are inserted before the first instruction of each instruction block, and the line feed is inserted before the block name character and block number to separate and increase readability. The lowercase block name character, block number and the number of loop levels where the block is located are inserted after each instruction. In order to ensure that the instructions in the assembly instruction set are arranged in the direction of PC address increment, the block filling algorithm fills the instruction blocks in natural order.
[0143] S134, output the assembly instruction set with block information to a new file: in order to avoid the added block information interfering with the compilation process of the assembly instruction set, the assembly instruction set with block information is output to a new file, which is used for static debugging analysis, not directly used for compilation and execution;
[0144] S135, realize the generation of the assembly instruction set containing complete block information.
[0145] S14, insert directed labels and auxiliary information in the assembly instruction set containing block information;
[0146] As shown in Figure 13 S141, insert directed labels and auxiliary information: use the static debugging script to generate directed labels by two times of transposition arrangement according to the block numbers in the obtained dictionary order list, and the format is predecessor block number->current block number->successor block number; for example, record the block numbers in the dictionary order list obtained in S11 as key, and use the static debugging script (bash shell script) to obtain directed labels after two times of transposition arrangement of the list, and the format of the directed labels is: predecessor key->key->successor key.
[0147] S142, create a dictionary pair: create a dictionary to pair each block number with its corresponding directed label, so as to realize the query of the predecessor and successor block numbers through the block number; as shown in Figure 14 , record the directed labels as value, and the dictionary is composed of each key in the dictionary order list and the value corresponding to the key. At this time, the corresponding value can be uniquely determined by the key, that is, the predecessor block and successor block can be uniquely determined by the block number.
[0148] S143, replace the block number right to the uppercase block name character: using the static debugging script, find the block number right to the uppercase block name character in the generated assembly instruction set, and replace it with the corresponding directed label; the key can uniquely determine the corresponding value, that is, the block number uniquely determines the predecessor block and the successor block. The block number right to the uppercase block name character in the assembly instruction set containing the block generated in step S13 is used as the key, and the static debugging script is used to query the value corresponding to the key in the dictionary, and the original position of the key is replaced, so that the predecessor block and the successor block of each block can be known.
[0149] S144, replace the operation by using multi-stage pipeline: in order to improve the processing speed, the replacement operation in the static debugging script is executed by using multi-stage pipeline; in order to accelerate the replacement speed of the value, the multi-stage pipeline is used in the static debugging script. Specifically, the replacement operation is performed by using multi-stage pipeline command (“|”). With the increase of the number of pipeline commands, the system will continuously create new processes, and when the number of processes reaches a certain upper limit, resource shortage will occur. We use the multi-stage pipeline grouping replacement method to operate. An n-stage pipeline can execute n+1 commands. If 600 replacements are taken as a group, 600 stages of pipeline are needed, and the remaining one command is a file reading command, which is used to read the instruction stream log file. In order to avoid data loss, a redirection command is added after each replacement is completed, which redirects the instruction stream log information after the replacement to a temporary file tmp.log. In order to avoid constantly generating new temporary files, after redirection to tmp.log, the mv command is used to rename tmp.log to insn_tr.log. When the next group of replacements occurs, insn_tr.log is read again for replacement and redirection and renaming operation. In order to always use the multi-stage pipeline method during replacement, we need to divide the replacement into several groups, let the upper limit of the number of pipeline stages of each group be MAX_PIPE, let the number of replacement lines be LINES, and let the number of replacement groups be N. If LINES is an integer multiple of MAX_PIPE, then
[0150] N=LINES / MAX_PIPE
[0151] If LINES is not an integer multiple of MAX_PIPE, then
[0152] N=[LINES / MAX_PIPE]+1
[0153] Where “[]” means rounding down. In the case of non-integer multiple, the number of pipeline stages in the last group is less than MAX_PIPE. If different MAX_PIPE is given, or LINES changes, an exact N can be obtained adaptively, and the multi-stage pipeline adaptive grouping replacement operation can be successfully completed. The replacement process is as followsFigure 17 As shown.
[0154] It is found by comparison that when MAX_PIPE = 600, the running time required by the replacement operation performed by multiple groups of multi-stage pipeline commands is only about 1 / 100 of the replacement operation directly on insn_tr.log, thereby improving the replacement speed.
[0155] S145, inserting auxiliary information into the subroutine call block and the loop control block: for the subroutine call block, the auxiliary information includes the subroutine return block block number; and for the loop control block, the auxiliary information includes the loop return block block number and the loop reserved block block number; since the successor block of the subroutine call structure 101 is the subroutine entry block 102, only the value information cannot know the block number of the subroutine return block 104, the predecessor block and the successor block of the loop control block 201 are neither any of the loop return block 202 nor any of the loop reserved block 204, and the possibly adjacent blocks also belong to the subroutine call structure 101 or the loop control block 201, resulting in that in the analysis and debugging process, it cannot be directly seen which instruction blocks are contained in the subroutine or the loop structure pointed to by the current block, in order to more intuitively analyze and debug, we select to insert auxiliary information in the subroutine call structure 101 and the loop control block 201, for the subroutine call structure 101, the auxiliary information displays the block number where the subroutine return block 104 corresponding to the subroutine call structure 101 is located, which is recorded as “return_from: subroutine return block 104 block number”, therefore the subroutine call structure 101 number and the corresponding subroutine return block 104 number should be contained in the auxiliary information source; for the loop control block 201, the auxiliary information simultaneously displays the block numbers where the loop return block 202 and the loop reserved block 204 corresponding to the loop control block 201 are located, which are recorded as “return_from: loop return block 202 block number” and “exit_to: loop reserved block 204 block number” respectively
[0156] S146, ensuring that the auxiliary information source contains necessary block number information: these information can be directly obtained from the block attribute function.
[0157] It can be obtained from step S145 that the auxiliary information source should contain the loop control block 201 number, the corresponding loop return block 202 number and the loop reserved block 204 number, both of the auxiliary information sources can be obtained from the block attribute function. After inserting the directional mark and the auxiliary information, an assembly instruction set containing complete static debugging information can be obtained.
[0158] S2, modification of the subroutine call structure 101 and the subroutine reserved block 105;
[0159] In the block marking algorithm, for subroutine call structure 101, the subroutine return target address can only be located in subroutine call structure 101 or subroutine reserved block 105, depending on the size of subroutine call structure 101. For the block marking algorithm of RISC-V, the minimum volume of a block is 4*halfword, the minimum volume of subroutine call structure 101 controlled by a direct jump instruction is 4*halfword, and the minimum volume of subroutine call structure 101 controlled by a register jump instruction is 7*halfword. The specific structures inside the two kinds of subroutine call structure 101 are as shown in Figure 16 For subroutine call structure 101 controlled by a direct jump instruction, after accommodating the direct jump instruction, the remaining space inside is sufficient, and the subroutine return target address must be located in the remaining space of the block. The successor block of the subroutine return block 104 corresponding to the subroutine call structure 101 is the subroutine call structure 101 itself, and the predecessor block of the subroutine reserved block 105 is also the subroutine call structure 101.
[0160] For subroutine call structure 101 controlled by a register jump instruction, after accommodating the register jump instruction, the subroutine return target address is not necessarily located in the remaining space inside: when the remaining space inside is sufficient, the case is the same as that of subroutine call structure 101 controlled by a direct jump instruction; when the remaining space inside is insufficient, the subroutine return target address will be located in the successor block of the subroutine call structure 101, i.e., the subroutine reserved block 105, and the predecessor block of the subroutine reserved block 105 is the subroutine return block 104.
[0161] In the dictionary sequence mentioned above, the dictionary sequence is obtained based on the block marking order of the block marking algorithm, and has not been filled with internal instructions, so it cannot eliminate the influence of internal instructions. In the dictionary sequence, the successor block of the subroutine return block 104 is always the subroutine call structure 101, and the predecessor block of the subroutine reserved block 105 is always the subroutine return block 104. In order to restore the real block execution order, we need to correct the successor block of the subroutine return block 104 and the predecessor block of the subroutine reserved block 105 according to the specific instructions inside the subroutine call structure 101. The correction information source needs to include all the block numbers of the subroutine call structure 101 and the corresponding block numbers of the subroutine return block 104, which can be obtained from the block attribute function and corrected by using a static debugging script.
[0162] The correction process is as follows Figure 15As shown, the correction method is: traversing the block number of the subroutine call structure 101; in the traversal process, it is judged whether the subroutine call structure 101 is controlled by a direct jump instruction or a register jump instruction: if it is controlled by a direct jump instruction, the successor block of the subroutine return block 104 does not need to be corrected, and the predecessor block of the subroutine reserved block 105 is corrected to the subroutine call structure 101; if it is controlled by a register jump instruction, it is judged whether the subroutine call structure 101 fills the register jump instruction in the case that there is sufficient space in the internal space; if it is sufficient, the successor block of the subroutine return block 104 does not need to be corrected, and the predecessor block of the subroutine reserved block 105 is corrected to the subroutine call structure 101; if it is not sufficient, the successor block of the subroutine return block 104 is corrected to the subroutine reserved block 105, and the predecessor block of the subroutine reserved block 105 does not need to be corrected.
[0163] After the correction is completed, the final assembly instruction set containing complete block information is obtained, which reflects the real execution order of the instruction blocks and can be used for static debugging. Part of the judgment logic involved in the implementation process of the static debugging function is arranged in Table 1.
[0164] Table 1: Part of the judgment logic involved in the implementation process of the static debugging function
[0165]
[0166]
[0167] Note: “X” represents the logic “no”, and “√” represents the logic “yes”.
[0168] II. Implementation process of a dynamic debugging method for RISC-V random instruction blocks.
[0169] The implementation of the dynamic debugging function depends on the block information and the dynamic instruction stream, and the required block information includes the block name, block number and loop level where the instruction is located, which can be obtained from the assembly instruction set containing the block information; the dynamic instruction stream is obtained by running the executable file generated by the assembly instruction set using the simulator.
[0170] Since the PC address of an instruction uniquely corresponds to an instruction, the dynamic instruction stream is based on the static assembly instruction set, so each instruction and its PC address in the dynamic instruction stream can be found in the static assembly instruction set. We record the PC address as key and the block name, block number and loop level where the instruction is located as value. We only need to insert value before key in the dynamic instruction stream, that is, replace the beginning of the line in the dynamic instruction stream log file with value, to obtain the dynamic instruction stream containing the block information. The dynamic instruction stream more detailedly and completely shows how the block information changes during the running of each instruction.
[0171] In the process of implementation, since the dynamic instruction stream log file insn_tr.log often contains the execution process of hundreds of thousands of instructions, if the log file recording the dynamic instruction stream is directly operated, tens of thousands of file exclusive write operations will occur, and the replacement efficiency is low, therefore in Linux, we use the multi-stage pipeline command (|) to replace the operation. However, with the increase of the number of pipeline commands, the system will continuously create new processes, and when the number of processes reaches a certain upper limit, resource shortage will occur, and in the Linux platform tested in this patent, the upper limit number of pipeline commands is about 600, therefore in the dynamic debugging script (bash shell), we use the multi-stage pipeline grouping replacement method to operate. An n-stage pipeline can execute n+1 commands, if 600 replacements are a group, then 600 stages of pipelines are needed, and the remaining one command is a file reading command, which is used to read the dynamic instruction stream log file, in order to avoid data loss, a redirection command is added after each replacement is completed, which redirects the instruction stream log information after the replacement to the temporary file tmp.log, in order to avoid constantly generating new temporary files, after redirection to tmp.log, the mv command is used to rename tmp.log to insn_tr.log, and when the next group of replacements occurs, insn_tr.log is read again for replacement and redirection and renaming operation. In order to always use the multi-stage pipeline method during replacement, we need to divide the replacement into several groups, let the upper limit of the number of pipeline stages be MAX_PIPE, let the number of replacement lines be LINES, and let the number of replacement groups be N, if LINES is an integer multiple of MAX_PIPE, then
[0172] N=LINES / MAX_PIPE
[0173] If LINES is not an integer multiple of MAX_PIPE, then
[0174] N=[LINES / MAX_PIPE]+1
[0175] Where “[]” means rounding down, and in the case of non-integer multiples, the number of pipeline stages in the last group is less than MAX_PIPE. If different MAX_PIPE is given, or LINES changes, an exact N can be obtained adaptively, and the multi-stage pipeline adaptive grouping replacement operation is successfully completed, and the replacement flow is as shown in Figure 17 .
[0176] After comparison, it is found that when MAX_PIPE=600, the running time required by the replacement operation of multiple groups of multi-stage pipeline commands is only about 1 / 100 of the replacement operation of directly operating insn_tr.log, which greatly improves the replacement speed.
[0177] The above describes an implementation method of static and dynamic debugging functions for RISC-V random instruction blocks. The instruction set containing block information obtained by using the static debugging function can directly analyze which types of blocks are marked by the block marking algorithm and the predecessors and successors of the block, and which instructions are filled in the blocks by the block filling algorithm in the assembly file containing block information. The nesting relationship between the instruction block structures in the instruction set can be analyzed by using the number of loop layers where the block is located. Without analyzing the dynamic instruction flow, changes caused by the modified content in the block marking algorithm and the fast filling algorithm can be quickly reflected. By using the dynamic debugging function, the execution process of all blocks and the relationship between instruction execution and blocks can be more clearly and intuitively seen, and the correctness of the modified content in the block marking algorithm and the fast filling algorithm can be further verified. In combination with the static and dynamic debugging methods, the block-based random instruction generation algorithm finally outputs three files, namely the assembly instruction set insn.S, the assembly instruction set blk_tr.S containing block information, and the dynamic instruction flow insn_tr.log containing block information. The relationship between the three files and their specific uses are shown in Table 2.
[0178] Table 2: Relationship between the three output files
[0179]
[0180] The implementation method of static and dynamic debugging functions for RISC-V random instruction blocks can simplify the code logic of the block-based random instruction generation algorithm. If the functions implemented in the present application are implemented in the algorithm, a large amount of control logic needs to be added, resulting in long code. The present application only needs to add the required marking information in the code implementing the algorithm, and other things are left to the dynamic and static debugging scripts. This can greatly simplify the code structure of the instruction generation algorithm, so that it can only focus on the algorithm itself. The present application has the following advantages:
[0181] Good universality: if new instruction blocks or instruction blocks are modified, only the support for the instruction block needs to be added in the script or a small amount of marking information needs to be added in the instruction generation algorithm; for the dynamic instruction flow insn_tr.log, no matter how the replacement times change, adaptive grouping replacement operations can be efficiently completed;
[0182] Strong scalability: for some data statistical work, only the corresponding functions need to be added in the script, without the need to recompile and run the instruction generation algorithm; after slight modification, it can be embedded into other scripts to automatically complete tasks in different scenarios in batches;
[0183] Fast running speed: For the dynamic instruction stream text of tens of thousands of lines, the adaptive multi-stage pipeline method under Linux is developed, which greatly reduces the file reading and writing operation, and the annotation process only takes tens of seconds, which is more than 100 times faster than the non-multi-stage pipeline method;
[0184] Simple debugging method and clear annotation result: Without running the executable file, the generated assembly program with fast information can be used to debug the instruction generation algorithm; by running the executable file, the dynamic debugging script can be used to annotate the block name, block number and loop number of each instruction in the dynamic instruction stream, so that the relationship between the instruction and the block can be known in more detail.
[0185] It should be noted that in this paper, relationship terms such as "first" and "second" are intended to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between the entities or operations. Moreover, the term "include", "contain" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to the process, method, article or device. Without more limitations, the element defined by the statement "including a" does not exclude the presence of other identical elements in the process, method, article or device including the element.
[0186] The above is only an embodiment of the present application, which enables those skilled in the art to understand and implement the present application. Various modifications of the embodiment will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments described herein, but will conform to the widest range consistent with the principles and features disclosed herein.
Claims
1. A static debugging method for RISC-V random instruction block, characterized in that, The method comprises: S1, generating static debugging information, which is obtained by analyzing a static instruction assembler to reveal the following features of an instruction block: a name and a number of the instruction block; an internal instruction structure of the instruction block; The generation of the static debugging information further comprises: S11, obtaining a lexicographic block number, which is used to generate a test instruction set for a RISC-V architecture, to convert a jump between instructions into a jump between instruction blocks, to simplify code logic and improve the generation efficiency of the test instruction set, to introduce a special block type of a subroutine call structure and a loop structure, to introduce a block attribute function and a block traversal function for marking a block number, to introduce a stack push and a stack pop operation for tracking and marking a special block number; The subroutine call structure comprises: a subroutine call block, a subroutine entry block, a subroutine stack exit block, a subroutine return block, and a subroutine reserved block; The block attribute function is used to generate the subroutine call structure, the loop structure, and other regular blocks, to record a loop level of a special instruction block, to perform a stack push operation on a special instruction block number, to divide a sub-instruction space, and to record a block number of part of the special instruction blocks; The block traversal function is used to mark a block number of all quasi-source blocks, to check whether the attributes of all blocks are marked and whether the block numbers of all blocks are marked, and to perform a stack pop operation on a stack push operation performed in the block attribute function, to update a position of a source block in a sub-instruction space or a global instruction space, and to mark a block number of a special block released from the stack; The loop structure comprises: a loop control block, a loop return block, a loop return predecessor block, and a loop reserved block; in the subroutine call structure or the loop structure, if a number of blocks contained in the structure reaches a certain requirement, a temporary instruction space in which the structure is located needs to be entered to mark block attributes of blocks in the temporary instruction space; to define upper and lower limits of the temporary instruction space, to protect register values, and to return to a correct block number for subsequent marking operations after exiting the temporary instruction space, a corresponding block number needs to be pushed into a stack, and the block number needs to be popped out when the temporary instruction space is exited; whether the stack push / pop is needed is related to a total number of instruction blocks contained in the structure; S12, marking a loop level in which a block is located, using a loop control counter and a stack operation to mark the loop level in which the block is located; when an assembler instruction set containing block information is generated, a loop level in which a certain block is located is indexed by a block number; S13, generating an assembler instruction set containing block information; The assembly instruction set containing the block information is generated, a capital block name character and a block number are inserted before the first instruction of each instruction block, and a line feed is inserted before the block name character and the block number to serve as a separation effect and increase readability; a small block name character, a block number and a loop layer number in which the block is located are inserted after each instruction; in order to ensure that the instructions in the assembly instruction set are arranged in the direction of PC address increment, a block filling algorithm fills the instruction blocks in a natural order; in order to avoid that the newly added block information causes the assembly instruction set to be unable to be compiled into an executable file, the assembly instruction set containing the block information is written into another file, which is only used for static debugging, and thus an assembly instruction set containing a block name, a block number and a loop layer number in which the block is located is obtained; The required block information includes a block name in which an instruction is located, a block number and a loop layer number in which the block is located, and can be obtained from the assembly instruction set containing the block information; a dynamic instruction stream is obtained by running an executable file generated by the assembly instruction set by using a simulator; S14, a directed label and auxiliary information are inserted in the assembly instruction set containing the block information, a static debugging script is used, a directed label is generated by twice transposition arrangement according to the block number in the obtained dictionary order list, in order to improve processing speed, a replacement operation in the static debugging script is executed in a multi-stage pipeline manner, an assembly instruction set containing complete static debugging information is obtained, and the assembly instruction set contains a directed label and necessary auxiliary information of each instruction block; wherein the block number in the obtained dictionary order list is a directed label obtained by twice transposition arrangement of the list by using a static debugging script which is a bash shell script, each block number in the dictionary order list and a directed label corresponding to the block number constitute a dictionary; S2, modification of subprogram call structure and subprogram reserved block, including: An external loop nesting relationship of an instruction block or a subprogram call structure; A jump relationship between instruction blocks, including forward and backward jumps; a subprogram call block controlled by a direct jump instruction; a subprogram call block controlled by a register jump instruction; a successor block of a subprogram return block and a predecessor block of a subprogram reserved block are modified according to a specific instruction in the subprogram call block, so as to ensure accuracy of debugging information.
2. The static debugging method for RISC-V random instruction block of claim 1, wherein, The step S11 is specifically: S111, entering a block attribute function: judging what kind of instruction block structure can be generated by an instruction space surrounded by a source block position and a target block position, and marking a block number of different types of instruction blocks according to different structures that can be generated; S1111, if the subroutine call structure can be generated, the block attribute is valued and the block number is marked according to the number of blocks contained in the subroutine structure. Since the subroutine call structure contains the subroutine call block and the subroutine reserved block no matter how many blocks it contains, the two blocks are updated as the source block in the traversal order, i.e. both belong to the quasi-source block, and the block number is recorded in the block traversal function. The "subroutine block number" described below is the number of special blocks contained in the subroutine call structure after removing the subroutine call block and the subroutine reserved block. If the subroutine block number is 1, the subroutine only contains a subroutine return block, there is no stack operation, and the block number of the block is directly marked in the block attribute function. If the subroutine block number is 2, the subroutine contains a subroutine entry block and a subroutine return block, there is no stack operation, and the block numbers of the two blocks are directly marked in the block attribute function. If the subroutine block number is 3, there is a stack operation, the subroutine contains a subroutine entry block, a subroutine return block and a regular block between the subroutine entry block and the subroutine return block. The block number of the subroutine entry block is marked in the block attribute function. Since there is a stack operation, the block number of the subroutine return block is pushed into the stack, and thus the block number of the subroutine return block is marked after being popped from the stack in the block traversal function. If the subroutine block number is greater than 3, there is a stack operation, the subroutine contains a subroutine entry block, a subroutine return block, a subroutine stack block and other internal regular instruction blocks. The block number of the subroutine entry block is marked in the block attribute function. The block numbers of the subroutine return block and the subroutine stack block are pushed into the stack. The block numbers of the two blocks are marked after being popped from the stack in the block traversal function. The remaining regular instruction blocks are quasi-source blocks, and the block numbers are marked in the block traversal function. S1112, if the subroutine call structure cannot be generated, it is determined whether the instruction space can generate a loop structure. If the loop structure can be generated, the block attribute is valued and the block number is marked according to the number of blocks contained in the loop structure. Since the loop structure contains the loop reserved block no matter how many blocks it contains, the loop reserved block will not be executed in the loop, and will only be executed when the loop structure is exited. Therefore, the "loop block number" described below is the number of special blocks contained in the loop structure after removing the loop reserved block. The loop reserved block and the loop control block belong to the quasi-source block, and thus the block numbers are marked in the block traversal function. If the loop block number is 2, the loop structure includes the loop control block and the loop return block, there is no stack operation, and the block number of the loop return block is directly marked in the block attribute function. If the loop block number is greater than 2, the loop structure includes the loop control block, the loop return predecessor block and the loop return block, there is a stack operation, and the block numbers of the loop return block and the loop return predecessor block are pushed into the stack. Since the loop return predecessor block also belongs to the quasi-source block, the block number of the loop return predecessor block is directly marked in the block traversal function, and the block number of the loop return block is marked after being popped from the stack. S1113, if the subprogram call structure and the loop structure cannot be generated, determine which regular instruction block is generated, since these regular instruction blocks are all quasi-source blocks, the block number markers of which are marked in the block traversal function; S112, enter the block traversal function: mark the quasi-source block block number, and mark the special type of instruction block according to the instruction block type generated in the block attribute function and whether there is a stack operation.
3. The static debugging method for RISC-V random instruction block of claim 1, wherein, The step S12 is specifically: S121, mark the loop level of the block: increase a new attribute based on the block attribute, that is, the loop level of the block, so as to obtain the information in the subsequent block filling function; S122, use the loop control counter: use the loop control counter to track and control the increase and decrease of the loop level, to ensure that the loop level of each block can be correctly marked; S123, enter the loop structure: when entering the loop structure, the value of the loop control counter is correspondingly increased; S124, mark other blocks inside the loop structure: when marking other blocks inside the loop structure, the value of the loop control counter is kept unchanged; In the loop structure, the loop control block and the loop reserved block both belong to the quasi-source block, so there is no need to track and mark; the loop return block is relatively special, although it does not perform stack compression, but the predecessor block of the loop return block is compressed, which is equivalent to indirectly performing the stack compression operation, so that the block number of the loop return block can be indirectly obtained from the stack in the block attribute function, and the block number is loop return predecessor block number+1; for the loop return block without stack operation, the tracking and marking are performed in the block attribute function; S125, exit the loop: control the exit of the loop through the stack pop operation in the block traversal function, and record the loop level of the special type of instruction block popped out of the stack before the loop control counter is decreased; S126, record the loop level of the non-quasi-source block: at the same time, record the loop level of the non-quasi-source block when the block number of the non-quasi-source block is marked; The step S13 is specifically: S131, generate an assembly instruction set containing block information: before the start of each instruction block, insert a line containing the uppercase block name character, the block number and a line feed character, to improve the readability of the assembly instruction set; S132, append block information to each instruction: append the lowercase block name character, the block number and the loop level of the block to which the instruction belongs to each instruction, to further enrich the block information in the assembly instruction set; S133, fill using the block filling algorithm: fill according to the natural sequence of the instruction block, to ensure that the instructions in the generated assembly instruction set are arranged in ascending order according to the program counter PC address; S134, output the assembly instruction set with block information to a new file: in order to avoid the added block information interfering with the compilation process of the assembly instruction set, output the assembly instruction set with block information to a new file, which is used for static debugging analysis, rather than directly used for compilation and execution; S135, realize the generation of the assembly instruction set containing complete block information; The step S14 is specifically: S141, inserting directed labels and auxiliary information: using a static debugging script, generating directed labels by twice transposition according to the block numbers in the obtained lexicographic list, the format is predecessor block number -> current block number -> successor block number; S142, creating dictionary pairs: creating a dictionary to pair each block number with its corresponding directed label, so that the predecessor and successor block numbers of each block number can be queried; S143, replacing the block number to the right of the uppercase block name character: using a static debugging script, searching for the block number to the right of the uppercase block name character in the generated assembly instruction set, and replacing it with the corresponding directed label; S144, replacing operation is performed in multiple stages: in order to improve processing speed, the replacement operation in the static debugging script is performed in multiple stages; S145, inserting auxiliary information into subroutine call blocks and loop control blocks: for subroutine call blocks, the auxiliary information includes the subroutine return block block number; for loop control blocks, the auxiliary information includes the loop return block block number and the loop reserved block block number; S146, ensuring that the auxiliary information source contains necessary block number information: this information can be directly obtained from the block attribute function.
4. The static debugging method for RISC-V random instruction block of claim 1, wherein, In the subroutine call structure, the block number of the subroutine call block can be updated to the source block number, i.e. the subroutine call block belongs to the quasi-source block, and its block index is recorded at the same time when the block attribute function acts on this block, whether the stack operation is performed or not; for the subroutine entry block, if the number of blocks in the subroutine structure meets the stack operation requirement, since its execution order is earlier than that of other regular blocks in the subroutine structure, its block number is marked in the block attribute function; On the basis of the original block attributes, a new attribute is added, i.e. the number of loops in which the block is located, which can be obtained in the block labeling function, wherein the block attribute function records the number of loops in which all non-quasi-source blocks are located; the block traversal function records the number of loops in which all quasi-source blocks are located, since all non-quasi-source block numbers and quasi-source block numbers constitute all block numbers in the current instruction space, the marking of the number of loops in which each block is located is completed without omission.
5. The static debugging method for RISC-V random instruction block of claim 1, wherein In order to speed up the replacement of the directed label, a multi-stage pipeline is used in the static debugging script; The implementation of the multi-stage pipeline is as follows: Divide the pipeline replacement into several groups, denote the upper limit of the number of pipeline stages in each group as MAX_PIPE, set the number of replacement lines as LINES, and the number of replacement groups as N, if LINES is an integer multiple of MAX_PIPE, then N=LINES / MAX_PIPE if LINES is not an integer multiple of MAX_PIPE, then N=[LINES / MAX_PIPE] wherein "[]" represents rounding down, in the case of non-integer multiple, the number of pipeline stages in the last group is less than MAX_PIPE; if different MAX_PIPE is given, or LINES changes, an exact N can be obtained adaptively, and the multi-stage pipeline adaptive grouping replacement operation is completed according to the above.
6. A method for dynamic debugging of RISC-V random instruction blocks, characterized in that, The method relies on block information and dynamic instruction stream, and obtains the dynamic instruction stream by running the executable file generated by the assembly instruction set with the simulator, wherein the required block information includes the block name, block number and loop layer number where the instruction is located, and can be obtained from the assembly instruction set containing the block information, and the multi-stage pipeline command mode is used to replace the multi-stage pipeline grouping replacement, and the n-stage pipeline can execute n+1 commands.
7. The method of claim 6, wherein, Further comprising: Since the PC address of the instruction uniquely corresponds to an instruction, and the dynamic instruction stream is based on the static assembly instruction set, each instruction in the dynamic instruction stream and its PC address can be found in the static assembly instruction set.
8. The method of claim 6, wherein, Further comprising: The PC address is recorded as key, and the block name, block number and loop layer number where the instruction is located are recorded as value. Only the value needs to be inserted before the key of the dynamic instruction stream, that is, the first line of the dynamic instruction stream log file is replaced with the value, and the dynamic instruction stream containing the block information can be obtained. The dynamic instruction stream more detailedly and completely shows how the block information changes during the running of each instruction.
9. The method of claim 6, wherein the method further comprises: The multi-stage pipeline command mode is as follows: a grouping replacement strategy is used, after each replacement is completed, the result is saved to a temporary file tmp.log through redirection command, and the mv command is used to rename it as insn_tr.log; when the next group is replaced, insn_tr.log is read again and replaced, redirected and renamed; during the replacement process, the number of replacement groups is determined by calculating the quotient of the number of replacement lines and the upper limit of the number of pipeline stages in each group, to realize the adaptive grouping replacement operation of multi-stage pipeline.
10. The dynamic debugging method for RISC-V random instruction blocks according to claim 9, characterized in that, In order to always use the multi-stage pipeline mode during the replacement process, the replacement needs to be divided into several groups, and the upper limit of the number of pipeline stages in each group is denoted as MAX_PIPE, the number of replacement lines is denoted as LINES, and the number of replacement groups is denoted as N. If LINES is an integer multiple of MAX_PIPE, then N=LINES / MAX_PIPE If LINES is not an integer multiple of MAX_PIPE, then N=[LINES / MAX_PIPE]+1 Where "[]" represents rounding down, and in the case of non-integer multiples, the number of pipeline stages in the last group is less than MAX_PIPE. If different MAX_PIPE is given, or LINES changes, an exact N can be obtained adaptively, and the multi-stage pipeline adaptive grouping replacement operation is successfully completed according to the above.