Link abnormality positioning method, computer program product and readable storage medium thereof

By constructing translation units and abstract syntax tree nodes, the problem of inaccurate link exception location is solved, achieving accurate link exception location and improving development efficiency, and it is applicable to a variety of development environments.

CN122195809APending Publication Date: 2026-06-12NANJING QINHENG MICROELECTRONICS CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
NANJING QINHENG MICROELECTRONICS CO LTD
Filing Date
2026-05-18
Publication Date
2026-06-12

AI Technical Summary

Technical Problem

In the software development process, existing technologies cannot accurately locate the source file corresponding to the error symbol when an error occurs during the linking stage, resulting in low development efficiency.

Method used

By constructing translation units of the analysis object, extracting lexical tag sequences and abstract syntax tree nodes, and combining them with source code analysis tools, the link anomaly locations can be accurately located, including preliminary location of candidate locations and selection of target nodes from relevant abstract syntax tree nodes.

Benefits of technology

It enables precise location of linking errors, improves development efficiency, allows developers to directly jump to the source file location of the linking error, optimizes the error reporting mechanism, is suitable for various development environments, and does not change the existing build process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122195809A_ABST
    Figure CN122195809A_ABST
Patent Text Reader

Abstract

The application discloses a kind of linking exception positioning method, computer program product and readable storage medium thereof, first determine analysis object;Linking exception is preliminarily positioned again, including the translation unit corresponding to the analysis object is constructed, the lexical mark sequence is extracted, the lexical unit of identifier type is traversed, is matched with the identifier name of linking exception, and the lexical unit that is matched consistently is screened out, and the position in analysis object is preliminarily positioned as candidate position;Finally, accurate positioning, including extracting relevant abstract syntax tree node according to candidate position, screening out target node from it, as the final linking exception position.The application links exception positioning accurately, so that developer can jump directly to accurate source file position from the error result of linking stage, improve the positioning efficiency of linking exception, improve development efficiency;It is suitable for a variety of development scenarios, does not change existing build process, has no influence on the integration of existing development tool chain, and is convenient for practical engineering application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of software development technology, and in particular relates to a method for locating link anomalies, a computer program product, and a readable storage medium thereof. Background Technology

[0002] In software development, programs need to go through compilation and linking stages to generate executable files. The linking stage mainly integrates the various compilation units based on object files, symbol tables, and address relocation information. Its processing objects no longer directly contain complete source code semantic information. When errors such as undefined symbols, duplicate symbols, or relocation failures occur during the linking stage, the linker can usually only provide error results based on symbol or section-level information, making it difficult to accurately link to the specific source code location.

[0003] In existing technologies, linking error location methods typically determine the location of the erroneous symbol in the object file using a symbol table. Furthermore, widely used mechanisms in development, such as compiler optimization, static library loading, and conditional compilation, further weaken the correlation between linking stage error messages and source code locations. Based on these factors, while existing linking stage error messages can provide the object file and symbol name where the error occurred, they cannot accurately pinpoint the location of the source file corresponding to the erroneous symbol, thus causing inconvenience for software debugging and problem localization. Summary of the Invention

[0004] Purpose of the invention: In order to solve the problem that the existing technology is not accurate enough in locating linking errors during the linking stage, resulting in low development efficiency, this invention provides a linking error location method, a computer program product and its readable storage medium.

[0005] Technical solution: A method for locating link anomalies, comprising the following steps:

[0006] Determine the analysis object: This includes obtaining the identifier name of the link exception and the name of the target file where the link exception identifier is located, and determining the corresponding source file as the analysis object based on the mapping relationship between the source file and the target file;

[0007] Preliminary localization includes: constructing translation units corresponding to the analysis object; extracting lexical tag sequences from the translation units, wherein the lexical tag sequences contain lexical units and their positions in the analysis object; traversing lexical units of identifier type in the lexical tag sequences, matching the text content of the identifiers with the names of identifiers with link anomalies, filtering out matching lexical units, and initially localizing the positions of the filtered lexical units in the analysis object as candidate positions;

[0008] Precise positioning: Extract the relevant abstract syntax tree nodes corresponding to the candidate positions from the translation unit, obtain the node type and semantic attributes of the relevant abstract syntax tree nodes; filter out the target nodes from the relevant abstract syntax tree nodes, and determine the position of the target nodes in the analysis object as the final link anomaly position.

[0009] Furthermore, in the precise positioning step, the target nodes selected from the relevant abstract syntax tree nodes include the first-time reference nodes.

[0010] Furthermore, in the initial localization step, the position of the lexical unit in the analysis object includes one or more localization information in the row number and column number.

[0011] Furthermore, in the preliminary localization step, during the construction of translation units, lexical units are extracted according to the start or end position of the source code in the analysis object, or according to the character offset range, and a lexical tag sequence is generated.

[0012] Furthermore, in the initial positioning step, source code analysis tools are used to parse the analysis object, acquire and analyze the lexical information, abstract syntax tree node information and semantic association information in the source code, and construct the corresponding translation unit.

[0013] Furthermore, the source code analysis tool used is a source code analysis tool implemented with the compiler front-end interface.

[0014] Furthermore, in the step of determining the analysis object, the analysis object includes one or more source files.

[0015] Furthermore, the node types of the abstract syntax tree node include declaration nodes, definition nodes, and reference nodes.

[0016] A computer program product includes a computer program that, when executed by a processor, implements the steps of the link exception location method described above.

[0017] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the link exception location method described above.

[0018] Compared with the prior art, the link anomaly location method, computer program product and its readable storage medium provided by the present invention have the following beneficial effects:

[0019] (1) Accurate linking error location and improved development efficiency: The error reporting mechanism is optimized and is not limited by compilation optimization, static library loading, conditional compilation and other mechanisms. It can accurately locate the linking error. It enables developers to jump directly from the error results in the linking stage to the source file of the linking error, improves the efficiency of linking error location and improves development efficiency.

[0020] (2) Applicable to a variety of development scenarios: It does not depend on a specific hardware platform or a specific linker, and can be applied to a variety of development environments, with strong versatility;

[0021] (3) No change to the existing build process: It can be implemented without changing the existing source code structure and compilation process, and has no impact on the integration of the existing development toolchain. It is convenient for practical engineering applications and can be used as a module in the IDE. After the original error information output by the linker is processed by this method, the precise location of the linking exception in the source file can be obtained for subsequent processing. Attached Figure Description

[0022] Figure 1 A flowchart for link exception localization methods;

[0023] Figure 2 This is a flowchart of the initial positioning steps. Detailed Implementation

[0024] The present invention will be further explained and described below with reference to the accompanying drawings and specific embodiments.

[0025] This linker exception localization method can be applied to a C / C++ software development environment, which may include a compiler toolchain, a linker, and a source code analysis tool. The source code analysis tool is a source code analysis tool implemented based on the Clang front-end interface. This method is applied to the build phase of the C / C++ software development process.

[0026] A method for locating link anomalies includes the following steps:

[0027] The analysis object is defined, including the following:

[0028] During program construction, when an exception occurs during the linking phase, the raw error information output by the linker is obtained. The identifier name of the linking exception and the name of the object file containing the exception identifier are then parsed from the error information. Exception identifiers include undefined symbols, duplicated symbols, etc. Based on the mapping relationship between source files and object files, the corresponding source file is determined as the analysis object. The analysis object may include one source file or multiple source files (compilation units) for subsequent linking exception location.

[0029] Preliminary positioning includes the following:

[0030] A translation unit corresponding to the analysis object is constructed, and a lexical tag sequence is extracted from the translation unit. The lexical tag sequence contains the lexical unit and its position within the analysis object. The lexical unit includes various types such as punctuation marks, keywords, identifiers, and literals. During the construction of the translation unit, the lexical tag sequence can be generated according to the start and end positions of the source code, or according to a character offset range, to achieve targeted analysis of the target code region.

[0031] In the lexical tag sequence, lexical units of identifier type are traversed, and the text content of the identifiers is matched with the names of identifiers with link anomalies. Matching lexical units are then selected, and their actual occurrence positions within the analysis object are preliminarily located as candidate positions. Candidate positions may contain one or more information such as row numbers and column numbers; the location is more accurate when both row and column numbers are included. This step may result in one or more candidate positions, and further precise location is performed within these candidate positions to determine the final result.

[0032] Precise positioning includes the following:

[0033] The relevant abstract syntax tree (AST) nodes corresponding to the candidate positions are extracted from the translation unit. The extracted relevant AST nodes contain semantic association information corresponding to the lexical units obtained from the preliminary location. Further, the node type and semantic attributes of the relevant AST nodes are obtained to distinguish different semantic types such as declaration nodes, definition nodes, and reference nodes. Target nodes that meet preset conditions are selected from the relevant AST nodes. The position of this target node in the analysis object is the final link anomaly position. For example, in this embodiment, the first-appearing reference node is considered the target node. In other embodiments, declaration nodes, definition nodes, or other types of nodes can be selected as the final location basis according to actual needs. Multiple types of nodes can also be selected, and the number of target nodes is not limited.

[0034] After locating the linking error, the original error message output by the linker can be reconstructed. The error message can be supplemented with the source file path corresponding to the symbol and the precise source code line number and column number information. The reconstructed linking error message can be output, which allows users to jump directly to the source code location related to the linking error from the error message, thereby improving the efficiency of linking error location and the development efficiency of developers.

[0035] The source file can be parsed using source code analysis tools to construct corresponding translation units. These translation units include lexical tag sequences corresponding to the source code, abstract syntax tree (AST) node information, source code location mapping information, and semantic attribute information corresponding to the nodes. This information is used to locate and analyze symbols related to link anomalies. For example, the source code analysis tool used in this embodiment is a source code analysis tool implemented through a compiler front-end interface. However, other tools can also be used, as long as they can achieve the same functionality.

[0036] A computer program product includes a computer program that, when executed by a processor, implements the steps of the link exception location method described above.

[0037] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the link exception location method described above.

[0038] The following example will more intuitively illustrate the specific process of the link anomaly location method in this embodiment.

[0039] Suppose the source file contains the following code snippet:

[0040] #include "debug.h"

[0041] void test();

[0042] int main(void)

[0043] {

[0044] NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

[0045] SystemCoreClockUpdate();

[0046] Delay_Init();

[0047] test();

[0048] USART_Printf_Init(115200);

[0049] printf("SystemClk:%d\r\n",SystemCoreClock);

[0050] printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );

[0051] printf("This is printf example\r\n");

[0052] while(1)

[0053] {

[0054] }

[0055] }

[0056] In the source code above, since test() is only declared but not defined, a linking error will occur during compilation. The following is the process of locating the linking error using the linking error locating method in this embodiment:

[0057] (1) In this method, the link exception symbol is 'test', and the source file containing this source code is the object of analysis. The lexical tag sequence of this source code segment is:

[0058] [0] tokenkind=Punctuation text="#" line=1 col=1

[0059] [1] tokenkind=Identifier text="include" line=1 col=2

[0060] [2] tokenkind=Literal text=""debug.h"" line=1 col=10

[0061] [3] tokenkind=Keyword text="void" line=2 col=1

[0062] [4] tokenkind=Identifier text="test" line=2 col=6

[0063] [5] tokenkind=Punctuation text="(" line=2 col=10

[0064] [6] tokenkind=Punctuation text=")" line=2 col=11

[0065] [7] tokenkind=Punctuation text=";" line=2 col=12

[0066] [8] tokenkind=Keyword text="int" line=3 col=1

[0067] [9] tokenkind=Identifier text="main" line=3 col=5

[0068]

[10] tokenkind=Punctuation text="(" line=3 col=9

[0069]

[11] tokenkind=Keyword text="void" line=3 col=10

[0070]

[12] tokenkind=Punctuation text=")" line=3 col=14

[0071]

[13] tokenkind=Punctuation text="{" line=4 col=1

[0072]

[14] tokenkind=Identifier text="NVIC_PriorityGroupConfig" line=5 col=2

[0073]

[15] tokenkind=Punctuation text="(" line=5 col=26

[0074]

[16] tokenkind=Identifier text="NVIC_PriorityGroup_2" line=5 col=27

[0075]

[17] tokenkind=Punctuation text=")" line=5 col=47

[0076]

[18] tokenkind=Punctuation text=";" line=5 col=48

[0077]

[19] tokenkind=Identifier text="SystemCoreClockUpdate" line=6 col=2

[0078]

[20] tokenkind=Punctuation text="(" line=6 col=23

[0079]

[21] tokenkind=Punctuation text=")" line=6 col=24

[0080]

[22] tokenkind=Punctuation text=";" line=6 col=25

[0081]

[23] tokenkind=Identifier text="Delay_Init" line=7 col=2

[0082]

[24] tokenkind=Punctuation text="(" line=7 col=12

[0083]

[25] tokenkind=Punctuation text=")" line=7 col=13

[0084]

[26] tokenkind=Punctuation text=";" line=7 col=14

[0085]

[27] tokenkind=Identifier text="test" line=8 col=2

[0086]

[28] tokenkind=Punctuation text="(" line=8 col=6

[0087]

[29] tokenkind=Punctuation text=")" line=8 col=7

[0088]

[30] tokenkind=Punctuation text=";" line=8 col=8

[0089]

[31] tokenkind=Identifier text="USART_Printf_Init" line=9 col=2

[0090]

[32] tokenkind=Punctuation text="(" line=9 col=19

[0091]

[33] tokenkind=Literal text="115200" line=9 col=20

[0092]

[34] tokenkind=Punctuation text=")" line=9 col=26

[0093]

[35] tokenkind=Punctuation text=";" line=9 col=27

[0094]

[36] tokenkind=Identifier text="printf" line=10 col=2

[0095]

[37] tokenkind=Punctuation text="(" line=10 col=8

[0096]

[38] tokenkind=Literal text=""SystemClk:%d\r\n"" line=10 col=9

[0097]

[39] tokenkind=Punctuation text="," line=10 col=27

[0098]

[40] tokenkind=Identifier text="SystemCoreClock" line=10 col=28

[0099]

[41] tokenkind=Punctuation text=")" line=10 col=43

[0100]

[42] tokenkind=Punctuation text=";" line=10 col=44

[0101]

[43] tokenkind=Identifier text="printf" line=11 col=2

[0102]

[44] tokenkind=Punctuation text="(" line=11 col=8

[0103]

[45] tokenkind=Literal text=""ChipID:%08x\r\n"" line=11 col=10

[0104]

[46] tokenkind=Punctuation text="," line=11 col=27

[0105]

[47] tokenkind=Identifier text="DBGMCU_GetCHIPID" line=11 col=29

[0106]

[48] tokenkind=Punctuation text="(" line=11 col=45

[0107]

[49] tokenkind=Punctuation text=")" line=11 col=46

[0108]

[50] tokenkind=Punctuation text=")" line=11 col=48

[0109]

[51] tokenkind=Punctuation text=";" line=11 col=49

[0110]

[52] tokenkind=Identifier text="printf" line=12 col=2

[0111]

[53] tokenkind=Punctuation text="(" line=12 col=8

[0112]

[54] tokenkind=Literal text=""This is printf example\r\n"" line=12col=9

[0113]

[55] tokenkind=Punctuation text=")" line=12 col=37

[0114]

[56] tokenkind=Punctuation text=";" line=12 col=38

[0115]

[57] tokenkind=Keyword text="while" line=13 col=2

[0116]

[58] tokenkind=Punctuation text="(" line=13 col=7

[0117]

[59] tokenkind=Literal text="1" line=13 col=8

[0118]

[60] tokenkind=Punctuation text=")" line=13 col=9

[0119]

[61] tokenkind=Punctuation text="{" line=14 col=5

[0120]

[62] tokenkind=Punctuation text="}" line=15 col=2

[0121]

[63] tokenkind=Punctuation text="}" line=16 col=1

[0122] (2) In the above lexical tag sequence, traverse the lexical units of type Identifier, match the text content of the identifier with the name of the linked anomaly identifier, and filter out the matching lexical units. That is, filter out the lexical unit of type Identifier named test, and initially locate its position in the source file as a candidate position, thereby filtering out:

[0123] [4] tokenkind=Identifier text="test" line=2 col=6

[0124]

[27] tokenkind=Identifier text="test" line=8 col=2

[0125] (3) Extract relevant AST nodes based on candidate locations, and obtain the node type and semantic attributes of the relevant AST nodes:

[0126] [4] cursorkind=FunctionDecl text="test" line=2 col=6

[0127]

[27] cursorkind=DeclRefExpr text="test" line=8 col=2

[0128] From the two related AST nodes above, select the first occurrence of the reference node, that is:

[0129]

[27] cursorkind=DeclRefExpr text="test" line=8 col=2

[0130] At this point, the link anomaly was accurately located.

Claims

1. A method for locating link anomalies, characterized in that, Includes the following steps: Determine the analysis object: This includes obtaining the identifier name of the link exception and the name of the target file where the link exception identifier is located, and determining the corresponding source file as the analysis object based on the mapping relationship between the source file and the target file; Preliminary localization includes: constructing translation units corresponding to the analysis object; extracting lexical tag sequences from the translation units, wherein the lexical tag sequences contain lexical units and their positions in the analysis object; traversing lexical units of identifier type in the lexical tag sequences, matching the text content of the identifiers with the names of identifiers with link anomalies, filtering out matching lexical units, and initially localizing the positions of the filtered lexical units in the analysis object as candidate positions; Precise positioning: Extract the relevant abstract syntax tree nodes corresponding to the candidate positions from the translation unit, and obtain the node type and semantic attributes of the relevant abstract syntax tree nodes; The target node is selected from the relevant abstract syntax tree nodes, and the position of the target node in the analysis object is determined as the final link anomaly position.

2. The link anomaly location method according to claim 1, characterized in that, In the precise location step, the target nodes selected from the relevant abstract syntax tree nodes include the first-time reference nodes.

3. The link anomaly localization method according to claim 1 or 2, characterized in that, In the initial localization step, the position of a lexical unit in the analysis object includes one or more localization information from the row number and column number.

4. The link anomaly localization method according to claim 1 or 2, characterized in that, In the initial localization step, during the construction of translation units, lexical units are extracted according to the start or end position of the source code in the analysis object, or according to the character offset range, and a lexical tag sequence is generated.

5. The link anomaly localization method according to claim 1 or 2, characterized in that, In the initial localization step, source code analysis tools are used to parse the analysis object, obtain and analyze lexical information, abstract syntax tree node information and semantic association information in the source code, and construct the corresponding translation unit.

6. The link anomaly location method according to claim 5, characterized in that, The source code analysis tool used is a source code analysis tool implemented using the compiler front-end interface.

7. The link anomaly localization method according to claim 1 or 2, characterized in that, In the step of determining the analysis object, the analysis object includes one or more source files.

8. The link anomaly localization method according to claim 1 or 2, characterized in that, The node types of the Abstract Syntax Tree include declaration nodes, definition nodes, and reference nodes.

9. A computer program product, characterized in that, It includes a computer program that, when executed by a processor, implements the steps of the link anomaly localization method as described in any one of claims 1-8.

10. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed by a processor, implements the steps of the link anomaly localization method as described in any one of claims 1-8.