Programming method and device

By configuring the tracing function library and prompting timing, a unified tracing code style is automatically inserted, solving the problem of difficulty in vulnerability discovery caused by differences in code style in distributed development, and improving the efficiency and accuracy of collaborative code development.

WO2025245790A1PCT designated stage Publication Date: 2025-12-04SIEMENS AG +1
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/096397
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Filing Date
2024-05-30
Publication Date
2025-12-04

AI Technical Summary

Technical Problem

In distributed applications, differences in code style and format make it difficult for developers to quickly find runtime problems, especially inconsistencies in tracing code during debugging, which affects the efficiency of vulnerability discovery.

Method used

By receiving a configuration file, configuring the tracing function library and prompt timing, uniform tracing code is automatically inserted at preset locations. The tracing function library is used to compile stub code, achieving a uniform tracing code style and prompt timing, reducing manual input, and improving code prompt efficiency and flexibility.

Benefits of technology

In large-scale collaborative code development, a unified code tracing style was implemented, which improved the speed and efficiency of program vulnerability discovery and simplified the code collaboration process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024096397_04122025_PF_FP_ABST
    Figure CN2024096397_04122025_PF_FP_ABST
Patent Text Reader

Abstract

Provided are a programming method and device. The method comprises: receiving a configuration file, which comprises a configuration of a tracking function library and a prompt occasion; prompting whether a tracking code needs to be inserted when the prompt occasion is triggered, and in response to an acknowledgement of the prompt, inserting a stub code of the tracking code; and calling the tracking function library to compile the stub code of the tracking code into the tracking code.
Need to check novelty before this filing date? Find Prior Art

Description

Programming method and device TECHNICAL FIELD

[0001] The present application mainly relates to the field of computer, in particular to a programming method and device. BACKGROUND

[0002] Most of the current codes are manually inputted by programmers. For business codes, code style and code format will vary with programmers. Debugging codes such as tracking and logging are usually contained in business codes, which are designed to help developers find running problems, and different code styles and code formats will make it difficult for developers to quickly find running problems.

[0003] For example, tracking codes in debugging codes include span codes, and span names and start times in span codes can vary with programmers. Usually, a development team has code instructions for developers, but in fact, the content in the instructions is not strictly implemented, especially for distributed development applications, which will lead to difficulty in finding vulnerabilities.

[0004] SUMMARY

[0005] In order to solve the above technical problems, the present application provides a programming method to quickly find vulnerabilities in distributed development applications.

[0006] To achieve the above purpose, the present application provides a programming method, which comprises:

[0007] receiving a configuration file, the configuration file comprising a tracking function library and a prompt timing;

[0008] prompting whether tracking codes need to be inserted when the prompt timing is triggered, and inserting a stub code of tracking codes in response to confirmation of the prompt;

[0009] calling the tracking function library to compile the stub code of tracking codes into tracking codes.

[0010] For this purpose, by configuring a tracking function library and a prompt timing, whether tracking codes need to be inserted is prompted when the prompt timing is triggered, and a uniform style of tracking codes and prompt timing are configured, which automatically prompts at a preset position, and developers do not need to manually input tracking codes, and tracking codes can maintain a uniform style, which can quickly find program vulnerabilities in large-scale code collaborative development.

[0011] Optionally, the prompt timing comprises the start and end of a function call, and the method comprises: prompting whether tracking codes need to be inserted at the start and end of the function call. For this purpose, code prompting is realized when the function is called, and the efficiency of code prompting is improved.

[0012] Optionally, the prompting timing includes error reports or preset business requirements, and the method further includes prompting whether log code needs to be inserted when an error report or preset business requirement occurs. Therefore, code suggestion is implemented when an error report or preset business requirement occurs, improving the flexibility of code suggestion.

[0013] Optionally, the configuration file also includes a pre-compilation configuration. Calling the tracing function library to compile the stub code of the tracing code into tracing code includes: performing a pre-compilation check on the translated stub code according to the pre-compilation configuration; and compiling the translated stub code if it meets the conditions of the pre-compilation configuration. Therefore, by performing a pre-compilation check on the stub code, stub code that does not meet the pre-compilation check is reprogrammed, ensuring that the compiled stub code passes testing, thus improving programming efficiency.

[0014] Optionally, the method further includes: defining topic symbols and topics; adding the topic symbols and matching topics to the tracking code; and publishing the tracking code with added topic symbols and topics in a publish-subscribe manner. Therefore, by publishing the tracking code with added topic symbols and topics in a publish-subscribe manner, tracking information can be quickly filtered by topic, improving tracking efficiency.

[0015] Optionally, the configuration file can be in XML, YML, or JSON format. This expands the configuration file format and thus broadens the application scenarios.

[0016] This application also proposes a programming device, the programming device comprising:

[0017] The configuration module receives a configuration file, which includes configurations for the tracking function library and the timing of alerts.

[0018] The prompting module prompts whether tracing code needs to be inserted when the prompting timing is triggered, and inserts stub code for tracing code in response to confirmation of the prompt;

[0019] The compilation module calls the tracing function library to compile the stub code of the tracing code into tracing code.

[0020] This application also proposes an electronic device including a processor, a memory, and instructions stored in the memory, wherein the instructions, when executed by the processor, implement the method described above.

[0021] This application also proposes a computer-readable storage medium having computer instructions stored thereon, which, when executed, perform the methods described above.

[0022] This application also proposes a computer program product, including a computer program that, when executed by a processor, implements the method described above. Attached Figure Description

[0023] The accompanying drawings are intended only to illustrate and explain this application and do not limit the scope of this application.

[0024] Figure 1 is a flowchart of a programming method according to an embodiment of this application;

[0025] Figure 2 is a schematic diagram of the functional architecture of a plug-in according to an embodiment of this application;

[0026] Figure 3 is a schematic diagram of a programming method according to an embodiment of this application;

[0027] Figure 4 is a schematic diagram of a subscription and publication method according to an embodiment of this application;

[0028] Figure 5 is a schematic diagram of a programming device according to an embodiment of this application;

[0029] Figure 6 is a schematic diagram of an electronic device according to an embodiment of the present application.

[0030] Figure Label Explanation: 100 Programming Method; 110-130 Steps; 21 Configuring the Processor; 22 Code Hint; 23 Stub Code Translator; 24 Pre-compilation Checker; 25 Plugin SDK; 26 Programming Language SDK; 27 IDE SDK; 301-306 Steps; 41 Publisher; 42 Topic; 43 First Subscriber; 44 Second Subscriber; 500 Programming Device; 510 Configuration Module; 520 Hint Module; 520 Compiler Module; 600 Electronic Device; 610 Processor; 620 Memory. Detailed Implementation

[0031] To provide a clearer understanding of the technical features, objectives, and effects of this application, specific embodiments of this application will now be described with reference to the accompanying drawings.

[0032] Many specific details are set forth in the following description in order to provide a full understanding of this application. However, this application may also be implemented in other ways different from those described herein, and therefore this application is not limited to the specific embodiments described below.

[0033] As indicated in this application and claims, unless the context clearly indicates otherwise, the words "a," "an," "an," and / or "the" are not specifically singular and may include plural forms. Generally speaking, the terms "comprising" and "including" only indicate the inclusion of explicitly identified steps and elements, which do not constitute an exclusive list, and the method or apparatus may also include other steps or elements.

[0034] This application proposes a programming method in which programming can be performed in an Integrated Development Environment (IDE). Figure 1 is a flowchart of a programming method 100 according to an embodiment of this application. As shown in Figure 1, the programming method 100 includes:

[0035] Step 110: Receive the configuration file, which includes the configuration of the tracking function library and the timing of prompts;

[0036] Configuration files can be determined by the developers. In some embodiments, the configuration file is in XML, YML, or JSON format. The configuration file may include a tracing function library. A tracing function is a function used to record the execution process of code. It is typically inserted at critical locations in the code to output relevant information during execution. Tracing functions help developers understand the program's execution flow, variable values, and other key information, thus aiding in debugging and code analysis. The specific implementation of tracing functions varies depending on the programming language and development environment; developers can define their own or use existing tracing function libraries as needed. Tracing function libraries can be OpenTelemetry SDKs. Tracing function libraries can include function libraries, interfaces, and specifications. Configuring the tracing function library determines the functions to be used, tracing parameters, and the corresponding code format.

[0037] The configuration file can also include configuration for logging functions. Logging functions can be nested within tracing functions or are independent code segments. Logging functions record the program's runtime status, error messages, debugging information, etc., to facilitate troubleshooting, performance analysis, and code review when needed. Logging functions typically record messages to a log file or output them to the console.

[0038] The configuration file also includes settings for when suggestions appear, i.e., where the suggestion code should appear. In some embodiments, the suggestion timing may include the beginning and end of a function call. For example, if the configuration file includes a `count` function, the suggestion timing may include the beginning and end of the `count` function call. In other embodiments, the suggestion timing may include error reporting or pre-defined business requirements, such as when an error occurs or a `set check` is requested.

[0039] In some embodiments, the configuration file further includes a pre-compilation configuration. Calling the tracing library to compile the stub code of the tracing code into tracing code includes: performing a pre-compilation check on the translated stub code according to the pre-compilation configuration; and compiling the translated stub code if it meets the conditions of the pre-compilation configuration. Therefore, by performing a pre-compilation check on the stub code, stub code that does not meet the pre-compilation check is reprogrammed, ensuring that the compiled stub code passes testing, thus improving programming efficiency.

[0040] Step 120: When the prompt is triggered, prompt whether to insert tracing code. In response to the confirmation of the prompt, insert the stub code of the tracing code.

[0041] The triggering timing can be at the beginning and end of a function call, prompting developers whether to insert tracing code at these times. Alternatively, it can be triggered by an error or a pre-defined business requirement, prompting developers whether to insert tracing code when such an error or requirement occurs. This can be presented as a dialog box, allowing developers to choose to insert or decline. When the developer chooses to insert, the stub code for the tracing code is inserted.

[0042] Step 130: Call the tracing function library to compile the stub code of the tracing code into tracing code.

[0043] Stub code is a simple code snippet used in software development to simulate the behavior of a specific function or object, for testing and debugging other parts of the code. By calling a configured tracing function library, the stub code is compiled into tracing code, enabling the tracing code to record the code execution process. To this end, a unified style and timing for tracing code suggestions are configured through a configuration file, automatically suggesting tracing code at preset locations. Developers do not need to manually enter tracing code, and the tracing code maintains a consistent style. In collaborative development of large codebases, this allows for the rapid discovery of program vulnerabilities.

[0044] In some embodiments, the method further includes: defining topic symbols and topics; adding topic symbols and matching topics to the tracking code, and publishing the tracking code with added topic symbols and topics in a publish-subscribe manner. Figure 4 is a schematic diagram of a publish-subscribe manner according to an embodiment of this application. As shown in Figure 4, the first subscriber 43 and the second subscriber 44 subscribe to topic 42 from the publisher 41. When the publisher 41 reports an error, the publisher 41 will publish the error to the first subscriber 43 and the second subscriber 44, and add topic symbols and related topics.

[0045] For example, the tracking code published by publisher 41 could be "ERROR:@Sub1$userService$serviceA:Unexpected error occurred in sub1->topic.", where the topic symbol "->" points to the topic "topic," which can be a specific predefined topic, such as temperature. Therefore, by publishing tracking codes with added topic symbols and topics using a publish-subscribe approach, tracking information can be quickly filtered by topic, improving tracking efficiency.

[0046] The programming method of this application can be implemented as a plugin. Figure 2 is a schematic diagram of the functional architecture of a plugin according to an embodiment of this application. As shown in Figure 2, the plugin includes a three-layer structure from bottom to top. The bottom layer includes a configuration processor 21, a code prompter 22, a stub code translator 23, and a pre-compilation checker 24. The configuration processor 21 is used to configure the tracing function library, the code prompter 22 is used to prompt for code, the stub code translator 23 is used to translate stub code, and the pre-compilation checker 24 is used for pre-checking the compilation of stub code. The second layer includes a plugin software development kit 25 (plugin SDKs) and a language development kit 26 (language SDKs). The plugin SDK 25 is plugin-oriented, and the language SDK 26 is language-oriented. The top layer includes an integrated development environment (IDE) plugin 26, used to embed the plugin into the IDE.

[0047] Figure 3 is a schematic diagram of a programming method according to an embodiment of this application. As shown in Figure 3, the programming method includes:

[0048] Step 301: Prepare the configuration file;

[0049] Step 302: Insert stub code;

[0050] Step 303: Insert topic symbols and topics;

[0051] Step 304: Translate the stub code;

[0052] Step 305: Has the pre-compilation check passed? If yes, proceed to step 306; otherwise, return to step 302.

[0053] Step 306: Compile.

[0054] The embodiments of this application provide a programming method that, by configuring a tracing function library and prompt timing, prompts whether tracing code needs to be inserted when the prompt timing is triggered. It configures a unified style of tracing code and prompt timing, and automatically prompts at preset locations. Developers do not need to manually enter tracing code, and the tracing code can maintain a consistent style. In the collaborative development of large codebases, program vulnerabilities can be quickly discovered.

[0055] This application also proposes a programming device. Figure 5 is a schematic diagram of a programming device according to an embodiment of this application. As shown in Figure 5, the programming device 500 includes:

[0056] Configuration module 510 receives configuration file, which includes configuration of tracking function library and prompt timing;

[0057] The prompt module 520 prompts whether to insert trace code when the prompt is triggered, and inserts stub code for trace code in response to confirmation of the prompt;

[0058] Compiler module 530 calls the tracing function library to compile the stub code of the tracing code into tracing code.

[0059] This application also proposes an electronic device 600. Figure 6 is a schematic diagram of an electronic device 600 according to an embodiment of this application. As shown in Figure 6, the electronic device 600 includes a processor 610 and a memory 620, wherein the memory 620 stores instructions, wherein the instructions, when executed by the processor 610, implement the method 100 described above.

[0060] This application also proposes a computer-readable storage medium having computer instructions stored thereon, which, when executed, perform the method 100 described above.

[0061] This application also proposes a computer program product, including a computer program that, when executed by a processor, performs the method 100 described above.

[0062] Some aspects of the methods and apparatus of this application can be executed entirely by hardware, entirely by software (including firmware, resident software, microcode, etc.), or by a combination of hardware and software. The aforementioned hardware or software may be referred to as a "data block," "module," "engine," "unit," "component," or "system." The processor may be one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DAPDs), programmable logic devices (PLCs), field-programmable gate arrays (FPGAs), processors, controllers, microcontrollers, microprocessors, or combinations thereof. Furthermore, aspects of this application may manifest as a computer product residing in one or more computer-readable media, including computer-readable program code. For example, computer-readable media may include, but are not limited to, magnetic storage devices (e.g., hard disks, floppy disks, magnetic tapes, etc.), optical discs (e.g., compact discs (CDs), digital multifunction discs (DVDs), etc.), smart cards, and flash memory devices (e.g., cards, sticks, key drives, etc.).

[0063] Flowcharts are used herein to illustrate the operations performed by the method according to embodiments of this application. It should be understood that the preceding operations are not necessarily performed in exact order. Instead, the steps can be processed in reverse order or simultaneously. Furthermore, other operations may be added to these processes, or one or more steps may be removed from them.

[0064] It should be understood that although this specification is described according to various embodiments, not every embodiment contains only one independent technical solution. This way of describing the specification is only for clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment can also be appropriately combined to form other implementation methods that can be understood by those skilled in the art.

[0065] The above description is merely an illustrative embodiment of this application and is not intended to limit the scope of this application. Any equivalent changes, modifications, and combinations made by those skilled in the art without departing from the concept and principles of this application shall fall within the scope of protection of this application.

[0066] In this patent application, nouns and pronouns relating to people are not limited to specific genders.

Claims

1. A programming method (100), characterized in that, The programming method (100) includes: Receive configuration file, which includes configuration of tracking function library and prompt timing (110); When the prompt is triggered, the system prompts whether to insert tracing code. In response to the confirmation of the prompt, the stub code (120) of the tracing code is inserted. The tracing function library is called to compile the stub code of the tracing code into tracing code (130).

2. The method (100) according to claim 1, characterized in that, The prompting timing includes the beginning and end of a function call, and the method (100) includes prompting whether tracing code needs to be inserted at the beginning and end of a function call.

3. The method (100) according to claim 1 or 2, characterized in that, The prompting timing includes error reporting or preset business requirements, and the method (100) further includes prompting whether log code needs to be inserted when an error report or preset business requirement occurs.

4. The method (100) according to claim 1, characterized in that, The configuration file also includes a pre-compilation configuration. Calling the tracing function library to compile the stub code of the tracing code into tracing code includes: performing a pre-compilation check on the translated stub code according to the pre-compilation configuration, and compiling the translated stub code when the translated stub code meets the conditions of the pre-compilation configuration.

5. The method (100) according to claim 1, characterized in that, The method (100) further includes: defining a topic symbol and a topic; adding the topic symbol and the matching topic to the tracking code, and publishing the tracking code with the added topic symbol and topic in a subscription-publishing manner.

6. The method (100) according to claim 1, characterized in that, The configuration file is in XML, YML, or JSON format.

7. A programming device (500), characterized in that, The programming device (500) includes: The configuration module (510) receives a configuration file, which includes a tracking function library and a configuration for the timing of prompts; The prompt module (520) prompts whether tracing code needs to be inserted when the prompt is triggered, and inserts stub code of tracing code in response to confirmation of the prompt; The compilation module (530) calls the tracing function library to compile the stub code of the tracing code into tracing code.

8. An electronic device (600) comprising a processor (610), a memory (620) and instructions stored in the memory (620), wherein the instructions, when executed by the processor (610), implement the method (100) as claimed in any one of claims 1-6.

9. A computer-readable storage medium having stored thereon computer instructions that, when executed, perform the method (100) according to any one of claims 1-6.

10. A computer program product, characterized in that, Includes a computer program, which, when executed by a processor, performs the method (100) of any one of claims 1-6.

Citation Information

Patent Citations

  • Hardware-based program dynamic function call sequence tracking method and device

    CN115269393A

  • Business test method, business test device, electronic equipment and storage medium

    CN116149974A

  • Custom code transformations during compilation process

    US10698668B1

  • Apparatus, system, and method for trace insertion

    US20060200806A1