Code analysis method and device, equipment and storage medium
By generating call stacks and trees from the original code, and using large language models to identify the calling process and causes of abnormal code, the problem of low accuracy of manual analysis is solved and more accurate code analysis is achieved.
Patent Information
- Application Number
- CN202410717876.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-04
- Publication Date
- 2024-09-27
AI Technical Summary
In the existing technology, code analysis relies on manual methods, which suffers from low accuracy.
By scanning and processing the original code, a call stack and a call tree are generated, and a large language model is used to identify and process these structures to obtain the calling process and cause of the abnormal code, thereby generating analysis results.
It improves the accuracy of code analysis, reduces manual operations, and improves the readability and accuracy of analysis results.
Smart Images

Figure CN118708472A
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a code analysis method, device, equipment and storage medium. Background Art
[0002] A program consists of code, which is a sequence of instructions written in a specific programming language that directs the program to perform a specific task.
[0003] In actual applications, syntax errors, logic errors, runtime errors, or external input errors can cause exceptions in the code, which in turn lead to program failures and affect user use. Therefore, identifying exceptions in the code and solving them in a targeted manner is of great significance to maintaining the normal operation of the program.
[0004] In the related art, the code is analyzed manually to obtain the analysis result. However, this analysis method is limited by the experience and knowledge of developers and has the problem of low accuracy. Summary of the invention
[0005] The present application provides a code analysis method, apparatus, device and storage medium to improve the accuracy of code analysis.
[0006] In a first aspect, the present application provides a code analysis method, comprising: scanning and processing an original code to obtain a plurality of exception descriptions in the original code; determining a code structure of the original code, and generating a plurality of call stacks and a plurality of call trees based on the code structure and the plurality of exception descriptions, wherein each call tree includes a plurality of exception codes corresponding to an exception description; identifying and processing the plurality of call trees respectively through a first large language model to obtain a plurality of call procedures and a plurality of exception causes; generating a plurality of analysis results of the original code based on the plurality of exception descriptions, the plurality of call stacks, the plurality of call procedures, and the plurality of exception causes.
[0007] In one possible design, for any exception description, a call stack and a call tree are generated according to the code structure and the exception description, including: determining multiple exception codes corresponding to the exception description from the original code; generating the call stack according to the position information of the multiple exception codes in the original code, the call stack including the position information of each exception code in the original code; generating the call tree according to the code structure and the multiple exception codes.
[0008] In a possible design, the call tree is generated according to the code structure and the multiple exception codes, including: determining the call relationship between the multiple exception codes from the code structure; and generating the call tree according to the multiple exception codes and the call relationship.
[0009] In one possible design, the call tree is generated according to the multiple exception codes and the call relationship, including: determining a starting code among the multiple exception codes according to the call relationship; creating the starting code as a vertex, and creating other codes among the multiple exception codes except the starting code as multiple nodes; and connecting the vertices and the multiple nodes according to the call relationship to obtain the call tree.
[0010] In a possible design, for any call tree, the call tree is identified and processed through the first large language model to obtain the call process and the exception cause, including: determining multiple annotation information corresponding to multiple exception codes in the call tree; combining the multiple annotation information according to the call relationship of the call tree to obtain the call process; inputting the call process into the first large language model to obtain the exception cause.
[0011] In a possible design, for any one of the exception codes, determining the comment information corresponding to the exception code in the call tree includes: judging whether there is corresponding comment information for the exception code in the original code; if so, determining the comment information corresponding to the exception code from the original code; if not, inputting the exception code into the first language model to obtain the comment information corresponding to the exception code.
[0012] In a possible design, the method also includes: grouping the multiple analysis results according to the application scenario of the code to obtain multiple groups; determining the correspondence between the application scenario and the second largest language model; determining the second largest language model corresponding to each group according to the multiple groups and the correspondence; training the second largest language model corresponding to each group through the analysis results in each group to obtain a target large language model corresponding to each group.
[0013] In a second aspect, the present application provides a code analysis device, comprising: a scanning module, used to scan and process the original code to obtain multiple exception descriptions in the original code; a generating module, used to determine the code structure of the original code, and generate multiple call stacks and multiple call trees based on the code structure and the multiple exception descriptions, each call tree including multiple exception codes corresponding to an exception description; an identifying module, used to identify and process the multiple call trees respectively through a first large language model to obtain multiple call procedures and multiple exception causes; a combining module, used to generate multiple analysis results of the original code based on the multiple exception descriptions, the multiple call stacks, the multiple call procedures, and the multiple exception causes.
[0014] In one possible design, the generation module is specifically used to determine multiple exception codes corresponding to the exception description from the original code; the generation module is also specifically used to generate the call stack according to the position information of the multiple exception codes in the original code, and the call stack includes the position information of each exception code in the original code; the generation module is also specifically used to generate the call tree according to the code structure and the multiple exception codes.
[0015] In a possible design, the generation module is specifically used to determine the calling relationship between the multiple exception codes from the code structure; the generation module is also specifically used to generate the call tree according to the multiple exception codes and the calling relationship.
[0016] In one possible design, the generation module is specifically used to determine the starting code among the multiple exception codes according to the calling relationship; the generation module is also specifically used to create the starting code as a vertex, and create other codes among the multiple exception codes except the starting code as multiple nodes; the generation module is also specifically used to connect the vertices and the multiple nodes according to the calling relationship to obtain the call tree.
[0017] In one possible design, the device also includes: an execution module, used to determine multiple annotation information corresponding to multiple exception codes in the call tree; the execution module is also used to combine the multiple annotation information according to the call relationship of the call tree to obtain the call process; the execution module is also used to input the call process into the first large language model to obtain the cause of the exception.
[0018] In one possible design, the execution module is specifically used to determine whether the exception code has corresponding comment information in the original code; the execution module is also specifically used to determine the comment information corresponding to the exception code from the original code if yes; the execution module is also specifically used to input the exception code into the first language model if no, to obtain the comment information corresponding to the exception code.
[0019] In a possible design, the device also includes: a training module, used to group the multiple analysis results according to the application scenario of the code to obtain multiple groups; the training module is also used to determine the correspondence between the application scenario and the second largest language model; the training module is also used to determine the second largest language model corresponding to each group based on the multiple groups and the correspondence; the training module is also used to train the second largest language model corresponding to each group through the analysis results in each group to obtain the target large language model corresponding to each group.
[0020] In a third aspect, an embodiment of the present application provides an electronic device, comprising: at least one processor and a memory; the memory stores computer execution instructions; the at least one processor executes the computer execution instructions stored in the memory, so that the at least one processor executes the code analysis method described in the first aspect and various possible designs of the first aspect.
[0021] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer execution instructions are stored. When a processor executes the computer execution instructions, the code analysis method described in the first aspect and various possible designs of the first aspect is implemented.
[0022] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements the code analysis method described in the first aspect and various possible designs of the first aspect.
[0023] The code analysis method, apparatus, device and storage medium provided by the present application include: scanning and processing the original code to obtain multiple exception descriptions in the original code; determining the code structure of the original code, and generating multiple call stacks and multiple call trees according to the code structure and the multiple exception descriptions, each call tree including multiple exception codes corresponding to an exception description; identifying and processing the multiple call trees respectively through the first large language model to obtain multiple call procedures and multiple exception reasons; generating multiple analysis results of the original code according to the multiple exception descriptions, the multiple call stacks, the multiple call procedures, and the multiple exception reasons. The above scheme identifies the call tree generated by the code through the large language model to obtain the analysis result. Since the large language model follows the standardized algorithm logic, it can improve the accuracy of code analysis compared with the manual method. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0025] Figure 1 A schematic diagram of an application scenario of a code analysis method provided in an embodiment of the present application;
[0026] Figure 2 A flowchart of a code analysis method provided in an embodiment of the present application;
[0027] Figure 3 A flowchart of a code analysis method provided in an embodiment of the present application;
[0028] Figure 4 A schematic diagram of generating a call tree provided in an embodiment of the present application;
[0029] Figure 5 A schematic diagram of determining the cause of an abnormality provided in an embodiment of the present application;
[0030] Figure 6 A schematic diagram of model training provided in an embodiment of the present application;
[0031] Figure 7 A schematic diagram of the structure of a code analysis device provided in an embodiment of the present application;
[0032] Figure 8 A schematic diagram of the structure of a code analysis device provided in an embodiment of the present application;
[0033] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0034] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0035] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0036] It should be noted that the collection, storage, use, processing, transmission, provision and disclosure of financial data or user data and other information involved in the technical solution of this application are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals. The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards, and provide corresponding operation portals for users to choose to authorize or refuse.
[0037] Figure 1 This is an application scenario diagram of the code analysis of the prior art. Figure 1 As shown, the application scenario includes: analyzing the original code to obtain the analysis result, which includes the abnormal code in the original code and the corresponding abnormal reason. The analysis result can be used to optimize the code or train the model, and the model can be used to analyze the code.
[0038] In the prior art, the original code is analyzed manually, but this method has the problem of accuracy.
[0039] In response to the above technical problems, the present application proposes the following technical concept: automatically generate a call tree from the abnormal code, and automatically identify the call tree through a large language model to obtain an analysis result.
[0040] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0041] Figure 2 A flowchart of a code analysis method provided in an embodiment of the present application, the method comprises the following steps:
[0042] S201. Scan the original code to obtain multiple exception descriptions in the original code.
[0043] As an example, the execution subject of this embodiment may be a code analysis device, and there are many implementations of the code analysis device. For example, it may be program software, or a medium storing relevant computer programs, such as a USB flash drive, etc.; or, the device may also be a physical device integrated or installed with relevant computer programs, such as a chip, a smart terminal, a computer, a server, etc.
[0044] The exception description is an explanation and interpretation of the unexpected abnormal situation in the original code.
[0045] Optionally, the exception description is stored in a specified code block or statement to clarify the exception information.
[0046] S202: Determine the code structure of the original code, and generate multiple call stacks and multiple call trees according to the code structure and multiple exception descriptions, each call tree including multiple exception codes corresponding to one exception description.
[0047] Among them, the code structure is the way to organize code elements (such as variables, functions, classes, modules, etc.) in the original code, and how these elements interact and organize with each other. The code structure reflects the logical relationship between codes.
[0048] Among them, the call tree is used to describe the call relationship between functions or methods during program execution. A call tree is a data structure, usually represented by a tree graph, where each node represents a function or method call, and the edges represent the call relationship between functions. The root node is usually the entry point of the program, such as the main function or initialization method, while the leaf node is a method that does not further call other functions.
[0049] Combined with the scenario example, the original code includes multiple exception descriptions, each of which corresponds to an exception type. Each exception type corresponds to multiple exception codes, and the multiple exception codes are used to generate an exception call tree.
[0050] Exemplarily, the call stack records the location of the exception call, such as the line number of each exception call in the original code.
[0051] It can be understood that by generating multiple exception call trees separately, the exception codes can be grouped to avoid the problem of low code analysis accuracy caused by confusion of exception codes of different exception types. The exception call tree generated by the exception code of one exception type can reflect the logical relationship between the exception codes, and on this basis, the accuracy of code analysis can be improved.
[0052] S203. Recognize and process the multiple call trees respectively using the first language model to obtain multiple call processes and multiple exception reasons.
[0053] Optionally, the first language model is a natural language recognition model, which is used to recognize and obtain natural language. The calling process and the multiple abnormal reasons are in the form of natural language.
[0054] Exemplarily, the calling process is a series of steps corresponding to the exception description. The exception cause is the reason for generating the exception description.
[0055] Combined with the scenario example, the first language model generates the calling process and multiple exception reasons in natural language, which can reduce user operations and improve readability.
[0056] S204: Generate multiple analysis results of the original code according to multiple exception descriptions, multiple call stacks, multiple call processes, and multiple exception reasons.
[0057] Exemplarily, each analysis result includes a corresponding exception description, a call stack, a call process, and an exception cause.
[0058] Combined with the scenario example, the analysis results are grouped according to the exception description to avoid interference between the analysis results, thereby improving the accuracy of the analysis.
[0059] The code analysis method provided in the embodiment of the present application scans the original code to obtain multiple exception descriptions in the original code; determines the code structure of the original code, and generates multiple call stacks and multiple call trees based on the code structure and multiple exception descriptions, each call tree includes multiple exception codes corresponding to an exception description; identifies and processes the multiple call trees respectively through the first large language model to obtain multiple call procedures and multiple exception reasons; generates multiple analysis results of the original code based on multiple exception descriptions, multiple call stacks, multiple call procedures, and multiple exception reasons. The above scheme identifies the call tree generated by the code through the large language model to obtain the analysis result. Since the large language model follows the standardized algorithm logic, it can improve the accuracy of code analysis compared to the manual method.
[0060] Based on any of the above embodiments, Figure 3, the detailed process of code analysis is explained.
[0061] Figure 3 A flowchart of a code analysis method provided in an embodiment of the present application. Figure 3 As shown, the method includes:
[0062] S301: Scan the original code to obtain multiple exception descriptions in the original code.
[0063] It should be noted that the execution process of S301 refers to S201 and will not be repeated here.
[0064] S302: Determine multiple exception codes corresponding to the exception description from the original code.
[0065] In combination with the scenario example, for multiple exception descriptions, multiple exception codes corresponding to each exception description are determined respectively, and the exception codes are grouped, and multiple exception codes in each group correspond to the same exception description.
[0066] Optionally, determine keywords in the exception description, and search the original code through a text search method to obtain multiple exception codes.
[0067] Optionally, if there is a specific pattern in the exception description, such as a fixed exception message format, you can use regular expressions to perform precise searches to match multiple exception codes corresponding to the specific pattern.
[0068] S303: Generate a call stack according to the location information of the multiple exception codes in the original code, where the call stack includes the location information of each exception code in the original code.
[0069] Optionally, the location information includes the fully qualified name of the class where the exception code is located, and the line number.
[0070] Optionally, the fully qualified name includes the package name and the class name.
[0071] Combined with the scenario example, it can be shown that the accuracy of location information can be improved by representing location information with a variety of information.
[0072] S304: Determine the calling relationship between the multiple abnormal codes from the code structure.
[0073] Combined with the scenario example, the original code comes from the program. The code structure of the original code in the program is modular, that is, a group of codes in the original code is responsible for completing a specific task, and there is a fixed calling relationship between different groups of codes during the execution of the program. For example: direct calling relationship, indirect calling relationship, recursive calling relationship, or cross-layer calling relationship, etc.
[0074] S305: Generate a call tree according to the multiple exception codes and call relationships.
[0075] Combined with the scenario example, the call tree corresponds to the exception description, and multiple exception codes in each call tree correspond to the same exception description. The branches and nodes of the call tree reflect the call relationship between multiple exception codes.
[0076] A feasible implementation method can generate a call tree by the following method: determine the starting code among multiple exception codes according to the call relationship; create the starting code as a vertex, and create other codes other than the starting code among the multiple exception codes as multiple nodes; according to the call relationship, connect the vertex and multiple nodes to obtain a call tree.
[0077] Next, combine Figure 4 Describes generating a call tree.
[0078] Figure 4 A schematic diagram of generating a call tree provided in an embodiment of the present application. Figure 4 As shown, the starting code and other codes other than the starting code in the multiple abnormal codes are determined. The starting code is taken as the vertex and other codes are taken as nodes. The connection relationship and the hierarchical relationship between the vertex and the node are determined according to the call relationship, and the connection is performed according to the connection relationship and the hierarchical relationship to obtain a call tree.
[0079] In conjunction with the scenario example, the start code is the code that starts execution, and the start code is determined as the vertex of the call tree.
[0080] In this feasible implementation, the call tree generated by the call relationship can accurately and intuitively reflect the connection relationship and hierarchical relationship between the exception codes.
[0081] S306: Determine multiple annotation information corresponding to multiple exception codes in the call tree.
[0082] The comment information is non-executable text used to explain the function, purpose or operation mode of the code. The comment information is used to improve the readability and maintainability of the code.
[0083] A feasible implementation method can determine multiple annotation information by the following method: determine whether there is corresponding annotation information for the abnormal code in the original code; if so, determine the annotation information corresponding to the abnormal code from the original code; if not, input the abnormal code into the first language model to obtain the annotation information corresponding to the abnormal code.
[0084] Combined with the scenario example, the annotation information is in natural language form. If the original code has been added with annotation information during the development process, the annotation information can be directly obtained. If the original code has not been added with annotation information during the development process, the abnormal code is identified through the first language model to obtain the annotation information.
[0085] Optionally, if the comment information in the original code fails to reflect the function, purpose or operation method of the abnormal code, the abnormal code is identified by the first language model to obtain the comment information.
[0086] Combined with the scenario example, the annotation information in the original code is manually added by the developer and there are human differences. For inaccurate annotation information, the first language model is used to regenerate the annotation information, thereby improving the accuracy of the annotation information.
[0087] In this feasible implementation, if the original code already has annotation information, directly obtaining the annotation information can reduce operations and improve efficiency. If the original code does not have annotation information, the annotation information generated by the first language model has the advantage of high accuracy.
[0088] S307: According to the calling relationship of the calling tree, multiple annotation information are combined and processed to obtain a calling process.
[0089] The calling process is described in natural language.
[0090] Combined with the scenario example, each annotation information corresponds to an exception code, and the annotation information is combined according to the call relationship of the corresponding exception code to obtain the call process. For example, the call process can be: 1. Transfer file, 2. Check permission, 3. Initiate network connection, 4. Create file.
[0091] S308: Input the calling process into the first language model to obtain the abnormal reason.
[0092] Combined with the scenario example, a document described in natural language is generated according to the calling process, and the document is input into the first language model. The first language model matches the document and obtains the exception reason corresponding to the document. The exception reason is the reason for generating the exception code. For example, the exception reason can be: insufficient disk space, disk damage, etc.
[0093] Next, combine Figure 5 Describe the cause of the abnormality.
[0094] Figure 5 This is a schematic diagram of determining the cause of an abnormality provided in an embodiment of the present application. Figure 5As shown, a call tree is generated according to the exception description. The annotation information in the call tree is used to generate a call process according to the structure of the call tree. The call process is identified and processed by the first language model to obtain the corresponding exception cause.
[0095] S309: Generate multiple analysis results of the original code according to multiple exception descriptions, multiple call stacks, multiple call processes, and multiple exception reasons.
[0096] It should be noted that the execution process of S309 refers to S204 and will not be repeated here.
[0097] A feasible implementation method, the code analysis method also includes: grouping multiple analysis results according to the application scenario of the code to obtain multiple groups; determining the correspondence between the application scenario and the second largest language model; determining the second largest language model corresponding to each group according to the multiple groups and the correspondence; training the second largest language model corresponding to each group through the analysis results in each group to obtain a target large language model corresponding to each group.
[0098] The application scenario of the code is the field of application of the program to which the code belongs, such as the energy field, the automotive field, the mobile phone field, etc.
[0099] Next, combine Figure 6 Explain the model training.
[0100] Figure 6 This is a schematic diagram of the model training provided in the embodiment of the present application. Figure 6 As shown, the analysis results are grouped to obtain multiple groups, each group corresponds to an application scenario, and the second largest language model corresponding to each application scenario is determined as the second largest language model corresponding to each group. The analysis results in the group are used as training data to train the corresponding second largest language model to obtain a target large language model.
[0101] Optionally, the second largest language model is an intelligent question and answer language model, which receives questions in natural language form and outputs natural language answers corresponding to the questions.
[0102] Exemplarily, the second largest language model receives the exception description, and outputs the calling process corresponding to the exception description and the corresponding exception cause.
[0103] Optionally, a solution corresponding to the cause of the exception is determined, and the second largest language model is trained with the cause of the exception and the solution, so that the second largest language model can output both the cause of the exception and the solution.
[0104] In combination with the scenario example, the second largest language model uses the training data of the corresponding application scenario during the training process. When using the second largest language model, the user determines the corresponding second largest language model according to the scenario used.
[0105] In this feasible implementation, the second largest language model is trained separately according to the application scenario, which can avoid interference between training data in different fields, improve the professionalism of the second largest language model in the corresponding application scenario, and thus improve the accuracy of the output results of the second largest language model.
[0106] Figure 7 A schematic diagram of the structure of a code analysis device provided in an embodiment of the present application. Figure 7 As shown, the code analysis device 70 may include: a scanning module 71, a generating module 72, an identifying module 73 and a combining module 74, wherein:
[0107] The scanning module 71 is used to scan the original code to obtain multiple exception descriptions in the original code.
[0108] The generating module 72 is used to determine the code structure of the original code, and generate multiple call stacks and multiple call trees according to the code structure and multiple exception descriptions, each call tree including multiple exception codes corresponding to one exception description.
[0109] The identification module 73 is used to identify and process the multiple call trees respectively through the first large language model to obtain multiple call processes and multiple abnormal reasons.
[0110] The combination module 74 is used to generate multiple analysis results of the original code according to multiple exception descriptions, multiple call stacks, multiple call processes, and multiple exception reasons.
[0111] Optionally, the scanning module 71 may execute Figure 2 S201 in the embodiment.
[0112] Optionally, the generating module 72 may execute Figure 2 S202 in the embodiment.
[0113] Optionally, the identification module 73 may execute Figure 2 S203 in the embodiment.
[0114] Optionally, the combination module 74 may execute Figure 2 S204 in the embodiment.
[0115] It should be noted that the code analysis device shown in the embodiment of the present application can execute the technical solution shown in the above method embodiment, and its implementation principle and beneficial effects are similar, which will not be repeated here.
[0116] In a possible implementation, the generating module 72 is specifically configured to:
[0117] Determine multiple exception codes corresponding to the exception description from the original code;
[0118] Generate a call stack according to the location information of the plurality of exception codes in the original code, the call stack including the location information of each exception code in the original code;
[0119] Generate a call tree based on the code structure and multiple exception codes.
[0120] In a possible implementation, the generating module 72 is specifically configured to:
[0121] Determine the calling relationship between multiple exception codes from the code structure;
[0122] Generate a call tree based on multiple exception codes and call relationships.
[0123] In a possible implementation, the generating module 72 is specifically configured to:
[0124] According to the calling relationship, determine the starting code among multiple abnormal codes;
[0125] A starting code is created as a vertex, and other codes except the starting code among the multiple exception codes are created as multiple nodes;
[0126] According to the calling relationship, the vertices and multiple nodes are connected to obtain a call tree.
[0127] Figure 8 A schematic diagram of the structure of a code analysis device provided in an embodiment of the present application. Figure 7 Based on the embodiment shown, Figure 8 As shown, the code analysis device 80 also includes: an execution module 75 and a scoring module 76, wherein:
[0128] The execution module 75 is used to:
[0129] Determine multiple annotation information corresponding to multiple exception codes in the call tree;
[0130] According to the calling relationship of the call tree, multiple annotation information is combined and processed to obtain the calling process;
[0131] The calling process is input into the first language model to obtain the exception reason.
[0132] In a possible implementation, the execution module 75 is specifically configured to:
[0133] Determine whether there is corresponding comment information for the abnormal code in the original code;
[0134] If so, determine the annotation information corresponding to the abnormal code from the original code;
[0135] If not, the exception code is input into the first language model to obtain annotation information corresponding to the exception code.
[0136] The training module 76 is used to:
[0137] Group multiple analysis results according to the application scenarios of the code to obtain multiple groups;
[0138] Determine the correspondence between the application scenario and the second largest language model;
[0139] According to the multiple groups and the corresponding relationships, determine the second largest language model corresponding to each group;
[0140] The second largest language model corresponding to each group is trained according to the analysis results in each group to obtain the target large language model corresponding to each group.
[0141] It should be noted that it should be understood that the division of the various modules of the above device is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software called by processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software called by processing elements, and some modules can be implemented in the form of hardware. Each module can be a separately established processing element, or it can be integrated in a chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and called and executed by a processing element of the above device. The functions of each module. In addition, all or part of these modules can be integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in the processor element or instructions in the form of software.
[0142] Fig. 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Fig. 9 As shown, the electronic device may include: a transceiver 91 , a processor 92 , and a memory 93 .
[0143] The processor 92 executes the computer execution instructions stored in the memory, so that the processor 92 executes the scheme in the above embodiment. The processor 92 can be a general-purpose processor, including a central processing unit CPU, a network processor (NP), etc.; it can also be a digital signal processor DSP, an application-specific integrated circuit ASIC, a field programmable gate array FPGA or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.
[0144] The memory 93 is connected to the processor 92 via a system bus and completes communication between them. The memory 93 is used to store computer program instructions.
[0145] The transceiver 91 may be used to obtain tasks to be executed and configuration information of the tasks to be executed.
[0146] The system bus can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The system bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The transceiver is used to realize the communication between the database access device and other computers (such as clients, read-write libraries, and read-only libraries). The memory may include random access memory (RAM) and may also include non-volatile memory.
[0147] The electronic device provided in the embodiment of the present application may be the terminal device of the above embodiment.
[0148] An embodiment of the present application also provides a chip for executing instructions, which is used to execute the technical solution of the code analysis method in the above embodiment.
[0149] The embodiment of the present application also provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on a computer, the computer executes the technical solution of the code analysis method of the above embodiment.
[0150] An embodiment of the present application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor can read the computer program from the computer-readable storage medium. When at least one processor executes the computer program, the technical solution of the code analysis method in the above embodiment can be implemented.
[0151] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0152] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to implement the solution of this embodiment.
[0153] In addition, each functional module in each embodiment of the present application can be integrated into one processing unit, or each module can exist physically separately, or two or more modules can be integrated into one unit. The above-mentioned module-composed unit can be implemented in the form of hardware or in the form of hardware plus software functional units.
[0154] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform some steps of the methods of various embodiments of the present application.
[0155] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.
[0156] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.
[0157] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0158] The above storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The storage medium can be any available medium that can be accessed by a general or special purpose computer.
[0159] An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. The storage medium can also be a component of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC). The processor and the storage medium can also exist as discrete components in an electronic control unit or a main control device.
[0160] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0161] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A code analysis method, It is characterized in that include: Scanning the original code to obtain multiple exception descriptions in the original code; Determine the code structure of the original code, and generate multiple call stacks and multiple call trees according to the code structure and the multiple exception descriptions, each call tree including multiple exception codes corresponding to one exception description; Recognize and process the multiple call trees respectively by using the first language model to obtain multiple call processes and multiple exception reasons; A plurality of analysis results of the original code are generated according to the plurality of exception descriptions, the plurality of call stacks, the plurality of call procedures, and the plurality of exception causes.
2. The method according to claim 1, It is characterized in that For any exception description, a call stack and a call tree are generated according to the code structure and the exception description, including: Determine a plurality of exception codes corresponding to the exception description from the original code; Generate the call stack according to the location information of the multiple exception codes in the original code, wherein the call stack includes the location information of each exception code in the original code; The call tree is generated according to the code structure and multiple exception codes.
3. The method according to claim 2, It is characterized in that Generating the call tree according to the code structure and the multiple exception codes includes: Determining the calling relationship between the plurality of abnormal codes from the code structure; The call tree is generated according to the multiple exception codes and the call relationship.
4. The method according to claim 3, It is characterized in that Generating the call tree according to the multiple exception codes and the call relationship includes: Determine, according to the calling relationship, a starting code among the multiple abnormal codes; The starting code is created as a vertex, and other codes other than the starting code in the multiple abnormal codes are created as multiple nodes; According to the calling relationship, the vertex and the multiple nodes are connected to obtain the calling tree.
5. The method according to claim 4, It is characterized in that For any call tree, the call tree is identified and processed by the first language model to obtain the call process and the abnormal reason, including: Determine multiple annotation information corresponding to multiple exception codes in the call tree; Combining and processing the plurality of annotation information according to the calling relationship of the calling tree to obtain the calling process; The calling process is input into the first language model to obtain the abnormal reason.
6. The method according to claim 5, It is characterized in that For any one of the exception codes, determining annotation information corresponding to the exception code in the call tree includes: Determine whether there is corresponding comment information for the abnormal code in the original code; If yes, determining annotation information corresponding to the abnormal code from the original code; If not, the exception code is input into the first language model to obtain annotation information corresponding to the exception code.
7. The method according to any one of claims 1 to 6, It is characterized in that The method further comprises: Grouping the multiple analysis results according to the application scenarios of the code to obtain multiple groups; Determine the correspondence between the application scenario and the second largest language model; Determine, according to the multiple groups and the corresponding relationship, a second largest language model corresponding to each group; The second largest language model corresponding to each group is trained according to the analysis results in each group to obtain the target large language model corresponding to each group.
8. A code analysis device, It is characterized in that include: A scanning module, used for scanning the original code to obtain multiple exception descriptions in the original code; A generating module, configured to determine a code structure of the original code, and generate a plurality of call stacks and a plurality of call trees according to the code structure and the plurality of exception descriptions, each call tree including a plurality of exception codes corresponding to an exception description; An identification module, used to identify and process the multiple call trees respectively through a first language model to obtain multiple call processes and multiple abnormal reasons; The combination module is used to generate multiple analysis results of the original code according to the multiple exception descriptions, the multiple call stacks, the multiple call processes, and the multiple exception reasons.
9. An electronic device, It is characterized in that include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 7 when executed by a processor.
11. A computer program product, It is characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 7 when being executed by a processor.
Citation Information
Cited By
Code processing method and device based on large language model, equipment and medium
CN118964222A
Software code exception handling method and device, equipment, medium and program product
CN121743094A
