Code analysis method, electronic device, storage medium and program product

By using a large language model to perform keyword analysis and code positioning of exception information in software programs, the problem of low positioning efficiency in problem location in a huge code library is solved, and fast and accurate code analysis and repair are achieved.

CN119645813APending Publication Date: 2025-03-18KE COM (BEIJING) TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411920210.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-24
Publication Date
2025-03-18

AI Technical Summary

Technical Problem

In the huge software program code base, it is less efficient to locate the root cause of the problem, especially the longer it takes to loop through hundreds of code files.

Method used

By obtaining the exception information and code index of the software program, using a large language model to analyze the exception information to obtain the exception keywords, and analyzing and identifying the code based on these keywords and indexes to accurately locate the abnormal code location.

Benefits of technology

It significantly improves the efficiency of problem location, reduces the inspection of a large number of code files one by one, shortens the time for problem repair, and improves the accuracy and speed of code analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119645813A_ABST
    Figure CN119645813A_ABST
Patent Text Reader

Abstract

The invention provides a code analysis method, electronic equipment, a storage medium and a program product. The code analysis method comprises the steps of obtaining abnormal information of a software program; performing keyword analysis on the abnormal information to obtain an abnormal keyword; obtaining an index of a code of the software program; and analyzing and identifying the code of the software program according to the abnormal keyword and the index to obtain an abnormal code position.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of computers and the like, and in particular to a code analysis method, an electronic device, a storage medium and a program product. Background Art

[0002] As software functions continue to be enriched, the amount of code in software programs is growing exponentially. The code base of a software program may contain millions of lines of code, distributed in numerous files, classes, and modules. For example, a complex Enterprise Resource Planning (ERP) system covers multiple modules such as finance, human resources, and supply chain, and each module has a large amount of code to implement specific business logic. As the code size of software programs continues to expand, it is difficult for developers to have a comprehensive understanding of the entire code base. When a problem occurs, it becomes extremely difficult to locate the root cause of the problem in such a huge ocean of code, which is tantamount to finding a needle in a haystack.

[0003] In the prior art, problem location is usually achieved by looping through all code files in the code base of a software program, that is, each code file in the code base of the software program is accessed in turn in a loop. When traversing to each specific code file, the content of the code file is read, and an attempt is made to analyze the code logic, function calls, variable definitions and other aspects of the code file based on the exception information, until all code files in the code base are traversed and the code file that best matches the exception information is found, thereby achieving problem location.

[0004] However, an actual software program may contain hundreds or thousands of code files. It takes a long time to loop through hundreds or thousands of code files, and the efficiency of problem location is low. Summary of the invention

[0005] The present disclosure provides a code analysis method, an electronic device, a storage medium, and a program product.

[0006] According to one aspect of the present disclosure, a code analysis method is provided, comprising: Obtaining exception information of a software program and an index of a code of the software program; Performing keyword analysis on the abnormal information to obtain abnormal keywords; The code of the software program is analyzed and identified according to the abnormal keyword and the index to obtain the abnormal code position.

[0007] According to the code analysis method of at least one embodiment of the present disclosure, the performing keyword analysis on the abnormal information to obtain abnormal keywords includes: Perform keyword analysis on the abnormal information based on the first language model to obtain abnormal keywords.

[0008] According to the code analysis method of at least one embodiment of the present disclosure, the keyword analysis of the abnormal information based on the first language model includes: Get keyword analysis rules; Perform keyword analysis on the abnormal information based on the first language model and according to the keyword analysis rule.

[0009] According to the code analysis method of at least one embodiment of the present disclosure, the performing keyword analysis on the abnormal information based on the first language model to obtain abnormal keywords includes: Determining, based on the first language model, whether an abnormal code location can be found in the code of the software program according to the abnormal information; If the abnormal code position cannot be found in the code of the software program according to the abnormal information, performing keyword analysis on the abnormal information based on the first language model to obtain abnormal keywords; Optionally, if the abnormal code position can be found from the code of the software program according to the abnormal information, the method further includes: An abnormal code location is obtained from the code of the software program based on the first language model.

[0010] According to at least one embodiment of the code analysis method of the present disclosure, the code of the software program is analyzed and identified according to the abnormal keyword and the index to obtain the abnormal code position, including: Search the index according to the abnormal keyword to obtain an optional code position; The optional code positions are screened based on the second largest language model to obtain the abnormal code positions.

[0011] According to at least one embodiment of the present disclosure, a code analysis method is provided. After obtaining the abnormal code position, the method further includes: repairing the code of the software program according to the abnormal code position to obtain a repaired code; Optionally, repairing the code of the software program according to the abnormal code position includes: supplementing the abnormal code position to the abnormal information to obtain supplemented information; and repairing the code of the software program according to the supplemented information; Optionally, repairing the code of the software program according to the abnormal code position includes: repairing the code of the software program according to the abnormal code position based on a third language model.

[0012] According to at least one embodiment of the code analysis method of the present disclosure, the analyzing and identifying the code of the software program according to the abnormal keyword and the index includes: A search method for obtaining the code of the software program; The search method is used to analyze and identify the code of the software program according to the abnormal keywords and the index.

[0013] According to another aspect of the present disclosure, an electronic device is provided, comprising: a memory storing execution instructions; and a processor executing the execution instructions stored in the memory, so that the processor executes the code analysis method of any embodiment of the present disclosure.

[0014] According to another aspect of the present disclosure, a readable storage medium is provided, wherein the readable storage medium stores execution instructions, and when the execution instructions are executed by a processor, the code analysis method of any embodiment of the present disclosure is implemented.

[0015] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the code analysis method of any one of the embodiments of the present disclosure is implemented. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The accompanying drawings illustrate exemplary embodiments of the present disclosure and together with the description serve to explain the principles of the present disclosure. These drawings are included to provide a further understanding of the present disclosure and are incorporated in and constitute a part of this specification.

[0017] Figure 1 This is a code analysis method flow of an embodiment of the present disclosure Figure 1 .

[0018] Figure 2 This is a code analysis method flow of an embodiment of the present disclosure Figure 2 .

[0019] Figure 3 yes Figure 2 The process of the keyword analysis method in the code analysis method shown Figure 1 .

[0020] Figure 4 yes Figure 2 The process of the keyword analysis method in the code analysis method shown Figure 2 .

[0021] Figure 5 yes Figure 2 The process of the keyword analysis method in the code analysis method shown Figure 3 .

[0022] Figure 6 yes Figure 1 The flow of the location search method in the code analysis method shown Figure 1 .

[0023] Figure 7 This is a code analysis method flow of an embodiment of the present disclosure Figure 3 .

[0024] Figure 8 yes Figure 7 The flow of the code repair method in the code analysis method shown Figure 1 .

[0025] Fig. 9 This is a code analysis method flow of an embodiment of the present disclosure Figure 4 .

[0026] Fig.10 yes Figure 1 The flow of the location search method in the code analysis method shown Figure 2 .

[0027] Fig.11 is a schematic flowchart of a code analysis method according to an embodiment of the present disclosure.

[0028] Fig.12 It is a schematic block diagram of the structure of a code analysis device according to an embodiment of the present invention.

[0029] Fig.13 It is a schematic block diagram of the structure of an electronic device according to an embodiment of the present disclosure. DETAILED DESCRIPTION

[0030] The present disclosure is further described in detail below in conjunction with the accompanying drawings and examples. It is understood that the specific examples described herein are only used to explain the relevant content, rather than to limit the present disclosure. It should also be noted that, for ease of description, only the parts related to the present disclosure are shown in the accompanying drawings.

[0031] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in the present disclosure can be combined with each other. The technical solution of the present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0032] Take a large e-commerce platform as an example. Its code base contains thousands of code files, which may involve multiple modules such as user management, product display, order processing, and payment system. One day, a serious payment anomaly occurred on the large e-commerce platform, and some users were unable to complete payment, resulting in revenue loss. In order to find the specific code file that caused the payment anomaly, the system automatically traverses each code file in the code base, reads the content of each code file, and analyzes the code logic and function calls until it finds the code file that best matches the payment anomaly. Since this traversal method of reading and parsing each code file one by one takes a lot of time, the efficiency of problem location is low.

[0033] To this end, the present disclosure proposes a code analysis method, electronic device, storage medium and program product. The method can be implemented by code analysis software set on electronic devices such as mobile phones, tablet computers, computers, servers, etc.

[0034] The technical solution is easier to understand. Before describing the code analysis method implemented in the present disclosure, the technical terms involved in the specific implementation of the present disclosure are explained as follows: Exception information usually refers to error information caused by certain errors or abnormal situations during the operation of a software program.

[0035] Keyword analysis rules refer to the rules and methods used to identify, extract and process keywords when processing and analyzing text, code or log data.

[0036] The exception code location refers to the specific code line that causes the exception in the program and the file where it is located.

[0037] An index is a structured directory of data or information generated to facilitate efficient query, analysis, and code manipulation.

[0038] Figure 1 FIG. 1 is a schematic diagram showing the overall flow of a code analysis method M100 according to an embodiment of the present disclosure. Figure 1 The method shown includes steps S110 to S130. The code analysis method can be executed by electronic devices such as mobile phones and computers.

[0039] Specifically, Figure 1 The code analysis method shown includes: Step S110, obtaining abnormal information of the software program and an index of the code of the software program.

[0040] In some embodiments of the present disclosure, step S110 may obtain exception information of the software program by using logging (capturing and recording exception information through a logging mechanism in the software program (such as log4j, slf4j, logging, etc.)), error codes (when a software program throws an exception, it returns a specific error code, which helps identify and classify errors), exception capture (the software program captures exceptions by using try-catch (or a similar mechanism)), system monitoring (capturing and recording exception information of the software program through system-level monitoring tools (such as operating system logs, database audit logs, etc.)), etc.

[0041] The exception information of the software program is information about situations that occur in the system, process or activity of the software program, and the specific cause or source has not been clearly identified; the exception information is usually used to describe what problem occurred in the software program and the context in which the problem occurred. The exception information may include: exception type (such as NullPointerException, IOException), exception message (such as "Cannot invoke method on null object" or "File not found"), additional context information (such as system status, variable value, environment configuration, etc.), timestamp, request information (such as requested URL, HTTP method, request parameters, etc.).

[0042] In some embodiments of the present disclosure, the process of obtaining the index of the software program code through step S110 can be to build the index in real time according to the software program code; in particular, in order to improve the efficiency of obtaining the index of the software program code, the process of obtaining the index of the software program code through step S110 can also be to obtain the index of the software program code from an index database, and the index stored in the index database is pre-built and stored.

[0043] Among them, the specific process of building an index based on the code of the software program may include: performing text parsing, syntax parsing, semantic parsing, etc. on the code of the software program to obtain parsing results (structured information); extracting key information from the parsing results, including identifiers (such as function names, variable names, class names, constant names, etc.), code structures (such as functions, classes, modules, conditional statements, loop statements, etc.), dependencies (such as function calls, method calls, module dependencies, agenda relationships, etc.); storing the above key information as an index. The structure of the index may include an inverted index (associating code elements with their locations), a hierarchical index (hierarchical storage by file, module, class, function, etc.), a graph structure index (storing calls and dependencies between code elements in the form of a graph), etc.

[0044] The index of the software program code obtained through step S110 may include: the file path of each code file, the name of the class and the file and line number where it is located, the name of the method and the class, file and line number where it is located, the name of the variable and the scope (class, method), file and line number where it is located, the comments in the code, the keywords and syntax elements of the programming language, the calling relationship between classes and methods, the version information of the code, etc.

[0045] When the index of the code of the software program is obtained from the index database, the index in the index database can be automatically updated by monitoring the changes of the code file of the software program.

[0046] Step S120, performing keyword analysis on the abnormal information to obtain abnormal keywords.

[0047] In some embodiments of the present disclosure, for simple exception information, step S120 can scan the predefined information and filter out the exception keywords according to a predefined keyword list; for structured exception information, regular expressions can be used to match the exception information to obtain the exception keywords; in order to improve the ability to process exception information, natural language processing technology can also be used to analyze the content of the exception information and extract the exception keywords.

[0048] Step S130, analyzing and identifying the code of the software program according to the abnormal keywords and indexes to obtain the abnormal code location.

[0049] In some embodiments of the present disclosure, the process of analyzing and identifying the code of the software program in step S130 may include: searching the code of the software program by index for a code region containing the abnormal keyword obtained in step S120 to obtain the abnormal code location.

[0050] The exception code location obtained through step S130 may include: the file name of the source code file indicating where the exception occurred, the line number of the code indicating where the exception occurred, the function or method when the exception occurred, the stack information of the function call when the exception occurred, an exception message indicating the specific exception type and containing a detailed description of the exception, thread information indicating the thread where the exception occurred, etc.

[0051] The code analysis method provided by the present disclosure implements code analysis based on abnormal keywords and indexes. Since the index is an efficient data structure, when analyzing and identifying the code of a software program, the abnormal code position in the code of the software program can be accurately and quickly located without having to check all code files one by one like loop traversal. The method solves the problem in the prior art that an actual software program may contain hundreds or thousands of code files, and it takes a long time to loop through hundreds or thousands of code files, resulting in low efficiency in problem location.

[0052] Regarding step S120, in some embodiments of the present disclosure, it can be replaced by Figure 2 The following steps are shown: Based on the first language model, keyword analysis is performed on the abnormal information to obtain abnormal keywords.

[0053] In some embodiments of the present disclosure, the first large language model in this step may be an existing large language model, such as BERT, GPT series, RoBERTa and other models. When performing keyword analysis on abnormal information based on the first large language model, the input of the first large language model may include abnormal keywords and topic prompts for keyword analysis (such as please perform keyword analysis on abnormal information, etc.). In particular, in order to improve the efficiency of keyword analysis, the input of the first large language model may also be an analysis templated prompt, that is, by inserting the abnormal information into a predefined template, a complete prompt prompt that meets the keyword analysis requirements is generated.

[0054] In particular, in order to improve the personalization and accuracy of keyword analysis, the input or predefined template of the first language model may also include specific requirement specifications related to keyword analysis (such as extraction quantity requirements, keyword type preferences, etc.) and / or software program codes, etc.

[0055] In particular, to improve the performance of keyword analysis of the first language model, Figure 2 The first large language model used in step S120 may also be a fine-tuned large language model. The fine-tuning method may be supervised fine-tuning, unsupervised fine-tuning, domain adaptation fine-tuning, reinforcement learning fine-tuning, etc.

[0056] Taking supervised fine-tuning as an example, the training data can be used as samples in advance to adjust the model parameters of the first language model. The training data is a data pair consisting of training anomaly information and training anomaly keywords; the fine-tuning training process of the first language model is to input the training anomaly information into the first language model, and the first language model outputs the corresponding analysis results; then calculate the loss between the analysis results and the training anomaly keywords, and optimize the model parameters of the first language model with the purpose of reducing the loss. Through multiple rounds of iterations, the analysis results output by the first language model can eventually be close to the expected training anomaly keywords, thereby improving the performance of the first language model.

[0057] This step uses a large language model to perform keyword analysis on the abnormal information, and can understand the keywords in the abnormal information from the perspective of natural language. That is, the keyword analysis does not just stop at simple text matching, but can understand the context and semantics, thereby extracting more meaningful abnormal keywords, which can improve the accuracy of keyword analysis.

[0058] about Figure 2 In some embodiments of the present disclosure, step S120 shown in FIG. 1 may include: Figure 3 Step S121 and step S122 are shown.

[0059] Step S121, obtaining keyword analysis rules.

[0060] In some embodiments of the present disclosure, the keyword analysis rules obtained through step S121 may include one or more rules of keyword type preference (such as the rule that the large language model tends to analyze certain specific types of keywords), keyword quantity preference (such as the rule that the large language model extracts several abnormal keywords), semantic association rules (such as considering the closeness between keywords and the core semantics of the information text), method name extraction rules (such as extracting method names from abnormal information, ignoring their parameters and implementation details), etc.

[0061] Step S122: performing keyword analysis on the abnormal information based on the first language model according to keyword analysis rules.

[0062] By controlling the first language model to perform keyword analysis on the abnormal information according to the keyword analysis rules through steps S121 to S122, the accuracy, completeness, universality, consistency and repeatability of the keyword analysis can be improved, thereby effectively extracting abnormal keywords that can reflect the core content of the abnormal information.

[0063] about Figure 2 In some embodiments of the present disclosure, step S120 shown in FIG. 1 may include: Figure 4 Steps S123 to S124 are shown.

[0064] Step S123 , judging whether the abnormal code position can be found in the code of the software program according to the abnormal information based on the first language model.

[0065] In some embodiments of the present disclosure, the first language model in step S123 can analyze the exception information through multiple dimensions such as the detail of the exception information, the structure of the software program code, and whether there are historical data and common patterns that can be used, to determine whether the exception code location can be found in the software program code based on the exception information.

[0066] If the exception code location cannot be found in the software program code based on the exception information, it means that the exception information is incomplete, the error type is too vague, the code structure is complex, there is a lack of index support, the mapping between the exception and the code is unclear, or there is isolation between the system and the language, etc., and step S124 needs to be executed at this time.

[0067] Step S124: perform keyword analysis on the abnormal information based on the first language model to obtain abnormal keywords.

[0068] By directly entering the keyword analysis step through step S123 to step S124 when the exception information is too vague, etc., it is possible to reduce useless fine-grained analysis and thus improve the efficiency of code analysis.

[0069] about Figure 2 In some embodiments of the present disclosure, if it is determined in step S123 that the abnormal code location can be found in the code of the software program according to the abnormal information, the following steps may also be included: Figure 5 Step S125 shown.

[0070] Step S125 , obtaining an abnormal code position from the code of the software program based on the first language model.

[0071] In some embodiments of the present disclosure, if the exception code location can be found in the code of the software program based on the exception information, it means that the exception information has high accuracy, clarity and traceability, and the first language model can directly locate and find the exception code location quickly through information such as the exception information and index.

[0072] In step S125, when the abnormal code position can be found in the code of the software program according to the abnormal information, the abnormal code position is directly located through index query, etc., which can avoid unnecessary complex analysis process, save tokens and time, and thus improve code analysis efficiency.

[0073] Regarding step S130, in some embodiments of the present disclosure, it may include the following steps: Figure 6 Step S131 and step S132 are shown.

[0074] Step S131, searching the index according to the abnormal keyword to obtain the optional code position.

[0075] In some embodiments of the present disclosure, in order to expand the search scope, the search method used in step S131 according to the abnormal keyword search index can be a fuzzy search. Through the fuzzy search, it is possible to find the optional code position similar or related to the abnormal keyword, rather than being limited to the optional code position that completely matches the abnormal keyword.

[0076] In particular, in order to prevent the fuzzy search from obtaining too many optional code positions, which would affect the code analysis efficiency, the search method used in step S131 according to the abnormal keyword search index can also be a precise search. Through the precise search, the optional code positions that accurately match the abnormal keywords can be found, thereby minimizing the interference of irrelevant information.

[0077] In particular, in order to prevent the process of obtaining optional code positions through step S131, the number of optional code positions obtained in this step can also be limited, such as obtaining a preset number of optional code positions based on an abnormal keyword search index; the preset number can be fixed and can also be adjusted by the user according to the application scenario, etc.

[0078] Step S132, screening the optional code positions based on the second largest language model to obtain abnormal code positions.

[0079] In some embodiments of the present disclosure, the second largest language model in step S132 may be an existing large language model, such as BERT, GPT series, RoBERTa, etc. Figure 2 The first large language model in step S120 may be a large language model of the same type or a large language model of a different type.

[0080] When the second largest language model in step S132 is Figure 2 When the first large language model in step S120 is the same large language model, if the large language model has a dialogue history integration function, that is, in a dialogue scenario, the large language model can integrate the previous dialogue history into the current processing to better understand the context of the dialogue and the user's intention, the input of the large language model for screening the optional code position can include the optional code position and the topic prompt for screening the optional code position. In particular, in order to improve the screening efficiency of the optional code position, the input of the large language model in step S132 can also be a screening template prompt, that is, by inserting the optional code position into a predefined template, one or more abnormal code positions that meet the screening requirements are generated.

[0081] If the large language model does not have a dialogue history integration function, the input or predefined template of the large language model in step S132 may include, in addition to the above information, abnormal information, software program code and other information.

[0082] In order to improve the accuracy of the large language model in screening the optional code position in step S132, the second large language model in step S132 can also be Figure 2 The model after the first large language model or other large language models are fine-tuned in step S120 shown in the figure, the fine-tuning process is the same as Figure 2 The fine-tuning process of the first large language model in step S120 is similar.

[0083] When the second largest language model in step S132 is Figure 2When the first large language model in step S120 is the same large language model, in order to make the large language model have good effects on both the keyword analysis and the optional code position screening process, it is also possible to use steps S132 and S133 as shown in FIG. Figure 2 After the training samples related to step S120 are mixed together to jointly fine-tune the large language model, the training samples are used in steps S132 and Figure 2 In step S120 shown.

[0084] After obtaining the optional code positions by searching the index in step S131, the optional code positions are screened in step S132 to obtain one or more abnormal code positions that are most relevant to the abnormal information, thereby improving the code repair efficiency.

[0085] Further, in some embodiments of the present disclosure, after obtaining the abnormal code position in step S130, the following steps may also be included: Figure 7 Step S140 is shown.

[0086] Step S140, repairing the code of the software program according to the abnormal code position to obtain a repaired code.

[0087] In some embodiments of the present disclosure, step S140 can repair the code of the software program according to the abnormal code location based on the specific abnormal type related to the abnormal information. For example, when the abnormal type related to the abnormal information is a null pointer exception, step S140 can use the Optional class, etc. to repair the code of the software program according to the abnormal code location; when the abnormal type related to the abnormal information is an array or collection out-of-bounds exception, step S140 can use the Size() method, etc. to repair the code of the software program according to the abnormal code location to ensure that the index is legal; if the code corresponding to the abnormal code location is too complex to generate an exception, step S140 can optimize the code structure of the software program according to the abnormal code location to make it more concise and maintainable; if some exceptions are caused by logical errors, step S140 can also re-examine the algorithm or business logic of the software program code according to the abnormal code location and then repair it.

[0088] In particular, after the code of the software program is repaired according to the abnormal code location through step S140, in order to ensure that developers and other relevant personnel can understand the content and background of the repair, the relevant code files, comments and design documents can also be updated; in order to improve the efficiency of handling future problems, the problems encountered in the repair process, solutions, results after repair, etc. can be sorted out through the repair summary to form a document or internal sharing; in order to ensure that the repaired software program functions normally and does not damage other parts of the software program, the repaired code can also be subjected to unit testing, regression testing, integration testing, performance testing, security testing and other tests.

[0089] By repairing the software program code according to the abnormal code location in step S140, the stability and robustness of the software program code can be improved. In addition, repairing the code based on the abnormal code location can also solve the problem of consuming a large number of tokens in the prior art of locating and repairing problems by loop traversal.

[0090] Regarding step S140, in some embodiments of the present disclosure, it may include: Figure 8 Step S141 and step S142 are shown.

[0091] Step S141, supplement the abnormal code position into the abnormal information to obtain supplemented information.

[0092] In some embodiments of the present disclosure, step S141 may supplement the exception code position to the exception information in an appending manner, i.e., attaching the exception code position to the end of the exception information; step S141 may supplement the exception code position to the exception information in an embedding manner, i.e., embedding the exception code position into a specific position of the exception information; step S141 may supplement the exception code position to the exception information in a merging manner, i.e., merging the exception code position and the exception information into a whole.

[0093] Step S142, repairing the code of the software program according to the supplemented information.

[0094] By adding the abnormal code position to the abnormal information through steps S141 to S142 and then performing code repair, it is possible to help the large language model repair the code of the software program more quickly and effectively, and further reduce the consumption of tokens, thereby improving the efficiency of code repair, reducing human errors and omissions, and enhancing later maintainability.

[0095] about Figure 7 In some embodiments of the present disclosure, step S140 shown in FIG. Fig. 9 As shown, it can be replaced by the following steps: The software program code is repaired according to the abnormal code location based on the third language model.

[0096] In some embodiments of the present disclosure, the third largest language model in this step can be an existing large language model, such as BERT, GPT series, RoBERTa and other models. Figure 6 The second largest language model and / or Figure 2 The first large language model in step S120 may be a large language model of the same type or a large language model of a different type.

[0097] When the third largest language model in this step Figure 6 The second largest language model and Figure 2 When the first large language model in step S120 is the same large language model, if the large language model has a dialogue history integration function, the input of the large language model in this step may include a topic prompt for code repair.

[0098] If the large language model does not have the function of integrating the conversation history, the input of the large language model in this step may include, in addition to the above information, abnormal information, software program code and other information.

[0099] In order to improve the accuracy of the code repair by the large language model in this step, the third language model in this step can also be used for Figure 6 The second largest language model and / or Figure 2 The model after the first large language model or other large language models are fine-tuned in step S120 shown in the figure, the fine-tuning process is the same as Figure 2 The fine-tuning process of the first large language model in step S120 is similar.

[0100] When the third largest language model in this step Figure 6 The second largest language model and Figure 2 When the first large language model in step S120 is the same large language model, in order to make the large language model have good effects on keyword analysis, optional code position screening and code repair, it is also possible to use the same large language model based on the step S120. Figure 6 Step S142 and Figure 2 After the training samples related to step S120 are mixed together to jointly fine-tune the large language model, the training samples related to step S120 are mixed together to jointly fine-tune the large language model. Figure 6 Step S142 and Figure 2 In step S120 shown.

[0101] This step uses a large language model to perform code repair, which can significantly improve the efficiency of code repair, especially for simple or medium-complexity errors, and can provide high-quality code repair suggestions.

[0102] Regarding step S130, in some embodiments of the present disclosure, it may include the following steps: Fig.10 Steps S133 to S134 are shown.

[0103] Step S133, a search method for obtaining the code of the software program.

[0104] In some embodiments of the present disclosure, the process of obtaining the search method of the software program code in step S133 can be similar to Figure 1The process of performing keyword analysis on abnormal information in step S120 shown is performed simultaneously or in different time periods.

[0105] When the operations are performed simultaneously, keyword analysis and search method analysis can be performed on the abnormal information based on the first large language model to obtain abnormal keywords and search methods. When the operations are performed in different time periods, keyword analysis and search method analysis can be performed based on the same or different large language models respectively. The above two types of analysis can be performed either by first performing keyword analysis and then performing search method analysis, or by first performing search method analysis and then performing keyword analysis.

[0106] The search method of the software program code obtained in step S133 may be a search based on text matching, a search based on a syntax tree, a search based on symbols and indexes, or a search based on semantic understanding.

[0107] Step S134, using a search method to analyze and identify the code of the software program based on abnormal keywords and indexes.

[0108] In some embodiments of the present disclosure, step S134 of analyzing and identifying the code of the software program may specifically be to use the search method obtained in step S133 to search the index according to abnormal keywords.

[0109] By using a suitable search method to perform code analysis and identification in step S133 and step S134, the efficiency of code analysis can be improved.

[0110] Fig.11 An exemplary flowchart of the code analysis method according to the present disclosure is shown.

[0111] Fig.11 In the flowchart shown, taking a mobile map navigation application that can query routes and implement navigation as an example, the code analysis process may include: 1. Obtain an index of abnormal information of the mobile map navigation application and the code of the software program.

[0112] In some embodiments of the present disclosure, assume that a user reports an abnormal situation, specifically, when the user is using the navigation function and is driving on a specific road section, the application suddenly crashes, and an error message pops up on the screen saying "There is a problem with the navigation, please restart the application"; at the same time, the user also provides the geographic location at the time of the crash (such as latitude and longitude information) and the operation being performed at the time (such as turning according to voice prompts, etc.).

[0113] Code analysis software can obtain relevant log information based on the exception situation. For example, the log shows that there is a "NullPointerException" and contains an error code "ERR-NAV-001" and a timestamp. This timestamp matches the crash time reported by the user.

[0114] The above information can all be used as exception information, or only the log information can be used as exception information.

[0115] 2. Perform keyword analysis on abnormal information based on the large language model to obtain abnormal keywords.

[0116] In some embodiments of the present disclosure, the abnormal keywords obtained by performing keyword analysis on the abnormal information in this step may include: abnormal type related keywords, error code related keywords, log information related keywords, user operation related keywords, function or method related keywords, etc.

[0117] Through keyword analysis, the correlation between exception information and exception code location can be improved, reducing unnecessary token consumption.

[0118] 3. Search the index based on the abnormal keywords to obtain the optional code location.

[0119] In some embodiments of the present disclosure, this step can use each abnormal keyword to search the index separately, and after obtaining the code position related to each abnormal keyword, all the code positions related to the abnormal keyword are combined to obtain the optional code position. For each abnormal keyword, one or more related code positions can be obtained from the index.

[0120] This step can also use all abnormal keywords to combine and obtain the optional code position.

[0121] The search tool in this step can be executed by a code search tool or the like; the code search tool or the like can quickly locate the relevant code area according to the abnormal keywords, thereby reducing the repeated traversal of the entire code base of the software program by the large language model.

[0122] 4. Filter the optional code positions based on the large language model to obtain the abnormal code positions.

[0123] In some embodiments of the present disclosure, this step may screen the optional code positions based on the exception information to obtain one or more exception code positions that are most relevant to the exception information among the optional code positions.

[0124] By filtering optional code locations, the code path most relevant to the exception information can be dynamically selected instead of traversing all optional code locations. This can reduce the amount of code file traversal, further reduce token consumption, and improve positioning accuracy, thereby improving repair efficiency.

[0125] 5. Repair the code of the software program according to the abnormal code location based on the large language model to obtain the repaired code.

[0126] In some embodiments of the present disclosure, in order to implement the above steps, the Prompt template of the large language model may be as follows: “There is a problem with the current mobile map navigation application. The problem is as follows: XXXX Based on the above problems, we want to get the exception code location.

[0127] You can choose to use the code search tool to get the abnormal code location by keyword. If you choose the current method, I will tell you the search results again, and you will get the abnormal code location required to fix the problem again based on the search results.

[0128] Keyword selection rules: 1. Give priority to characteristic class names, method names, and function names. Be sure to have characteristics and avoid using ambiguous words, such as value, key, max, min, etc. 2. According to the characteristics of the words, select up to 3 words. There is no need to force 3 words. If the conditions are not met, they must be discarded; 3. If it is a method, only keep the method name and remove the parameters.

[0129] Please return the result in Json format. If the exception code location can be found directly through the exception information, return it directly. If the exception code location cannot be found directly through the exception information, please return the name of the code search tool used and the keywords.

[0130] For example: {"use_serach": True, "keywords": ["Keyword 1", "Keyword 2"]} {"use_serach": False, "keywords": ["File path 1", "File path 2"]} The code analysis method provided by the present disclosure can repair the code of the software program according to the abnormal code location by using the large language model to accurately locate the problem code in the software program, which can significantly reduce the resource consumption of the large language model when traversing the entire code base, while improving the code analysis efficiency and shortening the problem repair time. This method is more effective when processing software programs with large-scale code repositories.

[0131] Through this code analysis method, only a few large language model API calls are needed to complete the repair. Compared with the existing large language model in the loop traversal process that requires dozens of calls, the repair efficiency is improved by nearly 10 times, and the token consumption for repairing the same problem can also be reduced by nearly 10 times, greatly reducing the repair cost and resource consumption.

[0132] Based on any of the above implementations, the present disclosure also provides a code analysis device.

[0133] Fig.12 It is a schematic block diagram of the structure of a code analysis device according to an embodiment of the present invention.

[0134] like Fig.12 As shown, the code analysis device comprises: The information acquisition module 110 is used to acquire abnormal information of the software program and an index of the code of the software program.

[0135] The keyword analysis module 120 is used to perform keyword analysis on the abnormal information to obtain abnormal keywords.

[0136] The code analysis module 130 is used to analyze and identify the code of the software program according to abnormal keywords and indexes to obtain the abnormal code location.

[0137] The above-mentioned code analysis device can be in the form of computer software, and each module of the above-mentioned code analysis device can be implemented by a computer software module.

[0138] The implementation process of the functions and effects of each module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, which will not be repeated here.

[0139] The execution subject of the code analysis method in the specific implementation manner of the present disclosure may be an electronic device such as a mobile phone or a computer.

[0140] Therefore, based on any one of the above embodiments, the present disclosure further provides an electronic device, which can execute the code analysis method of any one of the embodiments described above in the present disclosure.

[0141] Fig.13 1 is a schematic block diagram of the structure of an electronic device 1000 according to an embodiment of the present disclosure.

[0142] The hardware structure of the electronic device 1000 can be implemented using a bus architecture. The bus architecture can include any number of interconnected buses and bridges, depending on the specific application and overall design constraints of the hardware. The bus 1100 connects various circuits including one or more processors 1200, memory 1300 and / or hardware modules together. The bus 1100 can also connect various other circuits 1400 such as peripherals, voltage regulators, power management circuits, external antennas, etc.

[0143] The bus 1100 may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Component (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the figure only uses one connecting line, but does not mean that there is only one bus or one type of bus.

[0144] The present disclosure also provides a readable storage medium, in which a computer program is stored, and the computer program is used to implement the above method when executed by a processor. "Readable storage medium" can be any device that can contain, store, communicate, propagate or transmit a program for use in an instruction execution system, device or equipment or in combination with these instruction execution systems, devices or equipment. More specific examples of readable storage media include the following: an electrical connection portion (electronic device) with one or more wirings, a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and editable read-only memory (EPROM or flash memory), an optical fiber device, and a portable read-only memory (CDROM), etc.

[0145] The present disclosure also provides a computer program product. The method of the present disclosure can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instruction is loaded and executed, the process or function of the present disclosure is executed in whole or in part.

[0146] The computer program or instructions may be stored in a readable storage medium or transmitted from one readable storage medium to another readable storage medium, for example, the computer program or instructions may be transmitted from one website, computer, server or data center to another website, computer, server or data center by wired or wireless means. The readable storage medium may be any available medium that can be accessed or a data storage device such as a server, data center, etc. that integrates one or more available media. The available medium may be a magnetic medium, such as a floppy disk, a hard disk, or a magnetic tape; it may also be an optical medium, such as a digital video disk; it may also be a semiconductor medium, such as a solid state drive. The computer readable storage medium may be a volatile or non-volatile storage medium, or may include both volatile and non-volatile types of storage media.

[0147] Those skilled in the art will appreciate that the embodiments of the present disclosure may be provided as methods, systems, or computer program products. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present disclosure may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0148] The present disclosure is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the present disclosure. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0149] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0150] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0151] In the description of this specification, the description with reference to the terms "one embodiment / method", "some embodiments / methods", "example", "specific example", or "some examples" etc. means that the specific features, structures, or characteristics described in conjunction with the embodiment / method or example are included in at least one embodiment / method or example of the present disclosure. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment / method or example. Moreover, the specific features, structures, or characteristics described may be combined in any one or more embodiments / methods or examples in a suitable manner. In addition, those skilled in the art may combine and combine different embodiments / methods or examples described in this specification and features of different embodiments / methods or examples, unless they are contradictory.

[0152] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present disclosure, "plurality" means at least two, such as two, three, etc., unless otherwise clearly and specifically defined.

[0153] Those skilled in the art should understand that the above embodiments are only for the purpose of clearly illustrating the present disclosure, and are not intended to limit the scope of the present disclosure. For those skilled in the art, other changes or modifications may be made based on the above disclosure, and these changes or modifications are still within the scope of the present disclosure.

Claims

1. A code analysis method, characterized in that: include: Obtaining exception information of a software program and an index of a code of the software program; Performing keyword analysis on the abnormal information to obtain abnormal keywords; as well as The code of the software program is analyzed and identified according to the abnormal keyword and the index to obtain the abnormal code position.

2. The code analysis method according to claim 1, characterized in that: The performing keyword analysis on the abnormal information to obtain abnormal keywords includes: Perform keyword analysis on the abnormal information based on the first language model to obtain abnormal keywords.

3. The code analysis method according to claim 2, characterized in that: The performing keyword analysis on the abnormal information based on the first language model includes: Obtain keyword analysis rules; and Perform keyword analysis on the abnormal information based on the first language model and according to the keyword analysis rule.

4. The code analysis method according to claim 2, characterized in that: The keyword analysis of the abnormal information based on the first language model to obtain abnormal keywords includes: Determining, based on the first language model, whether the abnormal code location can be found in the code of the software program according to the abnormal information; and If the abnormal code position cannot be found in the code of the software program according to the abnormal information, performing keyword analysis on the abnormal information based on the first language model to obtain abnormal keywords; Optionally, if the abnormal code position can be found from the code of the software program according to the abnormal information, the method further includes: An abnormal code location is obtained from the code of the software program based on the first language model.

5. The code analysis method according to any one of claims 1 to 4, characterized in that: The analyzing and identifying the code of the software program according to the abnormal keyword and the index to obtain the abnormal code position includes: Search the index according to the abnormal keyword to obtain an optional code position; and The optional code positions are screened based on the second largest language model to obtain the abnormal code positions.

6. The code analysis method according to any one of claims 1 to 4, characterized in that: After obtaining the abnormal code position, the method further includes: Repairing the code of the software program according to the abnormal code position to obtain a repaired code; Optionally, repairing the code of the software program according to the abnormal code position includes: Supplementing the abnormal code position into the abnormal information to obtain supplemented information; and Repairing the code of the software program according to the supplemented information; Optionally, repairing the code of the software program according to the abnormal code position includes: The code of the software program is repaired according to the abnormal code location based on the third language model.

7. The code analysis method according to any one of claims 1 to 4, characterized in that: The analyzing and identifying the code of the software program according to the abnormal keyword and the index includes: a search method for obtaining the code of the software program; and The search method is used to analyze and identify the code of the software program according to the abnormal keywords and the index.

8. An electronic device, characterized in that: include: A memory storing execution instructions; as well as A processor, wherein the processor executes the execution instruction stored in the memory, so that the processor executes the code analysis method according to any one of claims 1 to 7.

9. A readable storage medium, characterized in that: The readable storage medium stores execution instructions, which are used to implement the code analysis method according to any one of claims 1 to 7 when executed by a processor.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the code analysis method according to any one of claims 1 to 7 is implemented.