Methods, media, and apparatuses for implementing parameter monitoring
Patent Information
- Application Number
- CN202510813276.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-17
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2045-06-17
AI Technical Summary
[0003]上述程序调试方式不仅耗时(如有时候需要数天时间),而且容易出现排查不彻底的现象,例如,如果遗漏断点或者观测点的设置,则通常会出现不能及时发现程序源代码中的问题的现象
[0009]Based on the above embodiments of this disclosure, a method, storage medium, and electronic device for parameter monitoring are provided. By traversing the AST formed during the compilation process of the program source code of the program to be debugged, it is possible to conveniently obtain all AST nodes in the AST whose node types meet the requirements and whose corresponding parameters belong to the preset monitoring parameter set. This not only allows for convenient and accurate filtering of the positions of all parameters that need to be monitored in the program within the AST, but also, since the preset node types in this disclosure include node types used to set the values of the parameters corresponding to the AST nodes, it is also possible to conveniently and accurately filter the positions of the key trajectories in the lifecycle of all parameters that need to be monitored in the program within the AST. This facilitates the monitoring of the lifecycle of the parameters that need to be monitored, thereby improving the analysis of problems existing in the program. During the problem-solving process, the critical trajectory in the parameter's lifecycle can be referenced, which is beneficial for problem localization. By setting observation node information for all selected AST nodes and using this information to construct observation nodes for each selected AST node, instrumentation can be automatically performed according to the user's actual needs during the program source code compilation process. This avoids the time-consuming and easily overlooked phenomena caused by manually setting breakpoints or observation points. In addition, the observation nodes set in the AST in this disclosure are not dependent on the program's running state. Therefore, the technical solution provided by this disclosure is conducive to quickly and accurately discovering problems in the program source code, thereby improving program debugging efficiency. This, in turn, improves the efficiency of program development and maintenance while ensuring the stability and robustness of the program.
Smart Images

Figure CN120973651B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computers, and more particularly to a method for implementing parameter monitoring, a computer-readable storage medium, and an electronic device. Background Technology
[0002] Currently, debugging tools are commonly used to debug programs. For example, when debugging programs based on the Linux platform, tools such as GDB (GNU Debugger) are typically used. When using debugging tools, debuggers often need to manually set breakpoints or watchpoints at appropriate locations in the program's source code to analyze vulnerabilities. For instance, after initially locating a bug in the program, debuggers manually insert breakpoint or watchpoint code at that location.
[0003] The above-mentioned debugging methods are not only time-consuming (sometimes requiring several days), but also prone to incomplete troubleshooting. For example, if breakpoints or watchpoints are omitted, problems in the program source code often cannot be discovered in a timely manner. Furthermore, debugging tools are often constrained by various factors. For instance, debugging tools like GDB often depend on the program's runtime state. When bugs in the program source code only occur under specific conditions (such as race conditions or concurrency issues), reproducing the bugs can be difficult.
[0004] As described above, how to quickly and accurately identify problems in program source code, improve program debugging efficiency, and thus improve program development and maintenance efficiency while ensuring program stability and robustness is a technical issue worthy of attention. Summary of the Invention
[0005] To address the aforementioned technical problems, this disclosure is proposed. Embodiments of this disclosure provide a method, storage medium, and electronic device for implementing parameter monitoring.
[0006] According to a first aspect of the present disclosure, a method for implementing parameter monitoring is provided. The method is executed during the compilation of the source code of a program to be debugged, and the execution of the method occurs between a preprocessing stage and a target code generation stage in the source code compilation process. The method includes the following steps: traversing nodes of an Abstract Syntax Tree (AST) formed during the source code compilation process; obtaining the node type of the currently traversed AST node; setting observation node information for the AST node when it is determined that the node type of the AST node belongs to a preset node type set and that the parameter corresponding to the AST node belongs to a preset monitoring parameter set; and constructing observation nodes for the AST node in the AST based on the observation node information to instrument the preset monitoring parameters corresponding to the AST node. The preset node type includes a node type used to set the value of the parameter corresponding to the AST node; the preset monitoring parameter set includes at least one parameter whose lifecycle needs to be monitored; and the observation node information includes the position information of the observation node in the AST and the monitoring content of the parameter corresponding to the AST node.
[0007] According to a second aspect of the present disclosure, a computer-readable storage medium is provided, the storage medium storing a computer program for implementing the above-described method.
[0008] According to a third aspect of the present disclosure, an electronic device is provided, comprising: a processor; a memory for storing executable instructions of the processor; the processor being configured to read the executable instructions from the memory and execute the instructions to implement the method described above.
[0009] Based on the above embodiments of this disclosure, a method, storage medium, and electronic device for parameter monitoring are provided. By traversing the AST formed during the compilation process of the program source code of the program to be debugged, it is possible to conveniently obtain all AST nodes in the AST whose node types meet the requirements and whose corresponding parameters belong to the preset monitoring parameter set. This not only allows for convenient and accurate filtering of the positions of all parameters that need to be monitored in the program within the AST, but also, since the preset node types in this disclosure include node types used to set the values of the parameters corresponding to the AST nodes, it is also possible to conveniently and accurately filter the positions of the key trajectories in the lifecycle of all parameters that need to be monitored in the program within the AST. This facilitates the monitoring of the lifecycle of the parameters that need to be monitored, thereby improving the analysis of problems existing in the program. During the problem-solving process, the critical trajectory in the parameter's lifecycle can be referenced, which is beneficial for problem localization. By setting observation node information for all selected AST nodes and using this information to construct observation nodes for each selected AST node, instrumentation can be automatically performed according to the user's actual needs during the program source code compilation process. This avoids the time-consuming and easily overlooked phenomena caused by manually setting breakpoints or observation points. In addition, the observation nodes set in the AST in this disclosure are not dependent on the program's running state. Therefore, the technical solution provided by this disclosure is conducive to quickly and accurately discovering problems in the program source code, thereby improving program debugging efficiency. This, in turn, improves the efficiency of program development and maintenance while ensuring the stability and robustness of the program.
[0010] The technical solutions of this disclosure will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0011] The above and other objects, features, and advantages of this disclosure will become more apparent from the more detailed description of the embodiments thereof in conjunction with the accompanying drawings. The drawings are provided to further illustrate the embodiments of this disclosure and form part of the specification. They are used together with the embodiments of this disclosure to explain the disclosure and do not constitute a limitation thereof. In the drawings, the same reference numerals generally represent the same components or steps.
[0012] Figure 1 This is a flowchart of an embodiment of the method for implementing parameter monitoring disclosed herein;
[0013] Figure 2 This is a schematic diagram of an embodiment of the AST disclosed herein;
[0014] Figure 3 This is a schematic diagram of another embodiment of the method for implementing parameter monitoring disclosed herein;
[0015] Figure 4 This is a flowchart of yet another embodiment of the method for implementing parameter monitoring disclosed herein;
[0016] Figure 5 This is a schematic diagram of an embodiment of the device for implementing parameter monitoring disclosed herein;
[0017] Figure 6 This is a structural diagram of an electronic device provided in an exemplary embodiment of this disclosure. Detailed Implementation
[0018] Example embodiments according to this disclosure will now be described in detail with reference to the accompanying drawings. It is obvious that the described embodiments are merely some embodiments of this disclosure, and not all embodiments of this disclosure, and it should be understood that this disclosure is not limited to the example embodiments described herein.
[0019] It should be noted that, unless otherwise specifically stated, the relative arrangement, numerical expressions, and values of the components and steps set forth in these embodiments do not limit the scope of this disclosure.
[0020] Those skilled in the art will understand that the terms "first," "second," etc., in the embodiments of this disclosure are only used to distinguish different steps, devices, or modules, and do not represent any specific technical meaning, nor do they indicate a necessary logical order between them.
[0021] It should also be understood that in the embodiments disclosed herein, "a plurality of" may refer to two or more, and "at least one" may refer to one, two or more.
[0022] It should also be understood that any component, data or structure mentioned in the embodiments of this disclosure can generally be understood as one or more unless expressly defined or given to the contrary in the context.
[0023] Furthermore, the term "and / or" in this disclosure is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / " in this disclosure generally indicates that the preceding and following related objects have an "or" relationship.
[0024] It should also be understood that the description of the various embodiments in this disclosure emphasizes the differences between the various embodiments, and the similarities or similarities can be referred to each other. For the sake of brevity, they will not be described in detail.
[0025] At the same time, it should be understood that, for ease of description, the dimensions of the various parts shown in the accompanying drawings are not drawn according to actual scale.
[0026] The following description of at least one exemplary embodiment is merely illustrative and is in no way intended to limit this disclosure or its application or use.
[0027] Techniques, methods, and equipment known to those skilled in the art may not be discussed in detail, but where appropriate, such techniques, methods, and equipment should be considered part of the specification.
[0028] It should be noted that similar labels and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be discussed further in subsequent figures.
[0029] The embodiments of this disclosure can be applied to electronic devices such as terminal devices, computer systems, and servers, and can operate with a wide range of other general-purpose or special-purpose computing system environments or configurations. Examples of well-known terminal devices, computing systems, environments, and / or configurations suitable for use with electronic devices such as terminal devices, computer systems, or servers include, but are not limited to: personal computer systems, server computer systems, thin clients, thick clients, handheld or laptop devices, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputer systems, mainframe computer systems, and distributed cloud computing environments that include any of the above systems, etc.
[0030] Electronic devices such as terminal devices, computer systems, and servers can be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, program modules can include routines, programs, object programs, components, logic, data structures, etc., which perform specific tasks or implement specific abstract data types. Computer systems / servers can be implemented in a distributed cloud computing environment. In a distributed cloud computing environment, tasks can be executed by remote processing devices linked through a communication network. In a distributed cloud computing environment, program modules can reside on local or remote computing system storage media, including storage devices.
[0031] Exemplary methods
[0032] Figure 1 This is a flowchart illustrating one embodiment of the parameter monitoring method disclosed herein. The parameter monitoring method of this disclosure can also be referred to as a data monitoring method; that is, the parameters to be monitored in this disclosure refer to the data to be monitored, which may include variables, etc. Figure 1 The method flow shown is executed during the compilation process of the source code of the program to be debugged. The source code in this disclosure can refer to program code written in a high-level programming language (such as C, C++, and Java).
[0033] In one example, the compilation process of the program source code in this disclosure includes multiple stages, such as a preprocessing stage, a lexical analysis stage, a syntax analysis stage, a semantic analysis stage, a stage for generating intermediate code, a code optimization stage, and a stage for generating target code. The intermediate code generated in the intermediate code generation stage includes three-address codes, quadruples, and postfix notation, etc. This intermediate code is independent of the target machine and does not depend on a specific hardware architecture. The target code generated in the target code generation stage can be an intermediate form of code (such as assembly code) or a final form of code (such as machine language code). Compared to the program source code, the target code is closer to the form that the target machine (such as a computer) hardware can directly process.
[0034] In one example, the aforementioned stages for syntax analysis may include a stage for forming an Abstract Syntax Tree (AST), and this AST formation stage is a crucial component of the syntax analysis stages. The aforementioned stages for generating intermediate code or for code optimization may include a stage for generalizing the abstract syntax tree. The aforementioned stages for generating target code may include a stage for generating assembly code.
[0035] The execution process of the method disclosed herein is typically located between the preprocessing stage and the target code generation stage in the program source code compilation process, that is, after the preprocessing stage and before the target code generation stage.
[0036] like Figure 1 The method shown mainly includes the following steps: S100, S101, S102, and S103. The following section details... Figure 1 Each step in the process will be explained separately.
[0037] S100, Perform node traversal on the AST formed during the compilation of the program source code.
[0038] The compilation process of program source code in this disclosure refers to the process of using appropriate compilation tools to convert program code written in a high-level programming language into machine language code that can be recognized / executed by the target machine (such as a computer) and stored and run in binary form.
[0039] In one example, the aforementioned compilation tools may include GCC (GNU Compiler Collection), etc. That is, steps S100, S101, S102, and S103 in this disclosure may be executed during the compilation of the program source code of the program to be debugged using compilation tools such as GCC.
[0040] In one example, steps S100, S101, S102, and S103 of the method disclosed herein can be executed by a registered callback event (such as a callback method), and this callback event can be registered by an extended GCC plugin. That is, the present disclosure can utilize an extended GCC plugin to register a user-defined callback event after the preprocessing stage and before the target code generation stage in the compilation process of the program source code of the program to be debugged using the GCC compiler. Here, the extended GCC plugin can be considered a user-defined plugin, which is a loadable module and a method for extending the functionality of GCC.
[0041] Since extended GCC plugins are loadable modules that can add new functionality to GCC without modifying the original GCC, using callback events registered with extended GCC plugins to execute the steps described above not only helps avoid the impact of extended GCC functionality on the original GCC functionality, but also allows users to choose whether to use the method of this disclosure for program debugging by selecting whether to load or not the extended GCC plugin, thus flexibly meeting the program debugging needs of different application scenarios. Furthermore, since the impact of this disclosure on GCC compilation efficiency is mainly related to the number of parameters that need to be monitored, when the number of parameters to be monitored is small, the impact of this disclosure on GCC compilation efficiency is very small.
[0042] In one example, the extended GCC plugin can register callback events after the stage for forming the Abstract Syntax Tree (AST) during the compilation process of the program source code and before the stage for generalizing the AST. The AST in this disclosure is an abstract representation of the program source code, presenting its syntactic structure in a tree structure. That is, during the compilation process of the program source code to be debugged by GCC, after successful AST generation, the registered callback events can be invoked, thereby executing the steps included in the method of this disclosure. After the steps included in the method of this disclosure are successfully executed, GCC continues to perform subsequent compilation processing according to its original processing logic, such as generalizing the current AST.
[0043] In one example, the extended GCC plugin disclosed herein can also be used to obtain a preset set of monitoring parameters, which is provided to callback events. For instance, the extended GCC plugin can read the preset set of monitoring parameters from a JSON (JavaScript Object Notation) file. Here, the preset set of monitoring parameters refers to the set of all parameters (such as variables) that the user pre-defined need to be monitored throughout their lifecycle. The lifecycle of a parameter can be reflected by important trajectory points in its lifecycle, such as the parameter's lifecycle start point, value change point, and parameter destruction point. Moreover, the parameter's lifecycle start point, value change point, and parameter destruction point can be considered as the complete lifecycle chain of the parameter.
[0044] Since each AST node in the AST represents a structural element in the program's source code, such as parameters, operators, and statements, the AST clearly displays the syntactic hierarchy and logical relationships of the program's source code. By registering callback events after the stage for forming the AST and before the stage for generalizing the AST, the AST used in this disclosure can be the AST before generalization. Because the AST before generalization is closer to the original syntactic structure of the program's source code, the semantic correspondence between AST nodes and syntactic elements in the AST is relatively clear. This not only helps ensure the accuracy of instrumentation operations and maintain semantic consistency, but also helps reduce the complexity of instrumentation and facilitates error debugging in the program to be debugged. Furthermore, the instrumentation processing of this disclosure does not need to consider the target of generalization processing and the generalization processing method used, thus avoiding the phenomenon that instrumentation processing needs to adapt to generalization processing with different targets and methods, thereby improving the applicability of the method of this disclosure. In addition, by enabling the extended GCC plugin to obtain the preset monitoring parameter set from the JSON file, it not only facilitates users to conveniently set the information of the parameters to be monitored, but also facilitates the efficient reading and transmission of the information of the parameters to be monitored.
[0045] An example of the extended GCC plugin disclosed herein can be represented in the form of the following pseudocode:
[0046]
[0047]
[0048] An example of an AST involved in this disclosure is as follows: Figure 2 As shown.
[0049] Figure 2This shows a portion of the AST. The top node is the AST node with identifier 21, which describes a modification expression, `modify_expr`. This modification expression has attributes such as `type`, `op0` (operand 0), and `op1` (operand 1). `op0` points to the AST node with identifier 31, and `op1` points to the AST node with identifier 33.
[0050] The AST node identified as 31 describes a variable declaration, var_dec1, which has attributes such as name (variable name), type (type), and size (size). The name pointer points to the AST node identified as 35.
[0051] The AST node identified as 33 describes an addition expression, plus_expr, which has attributes such as type, op0 (operand 0), and op1 (operand 1). op0 points to the AST node identified as 8, and op1 points to the AST node identified as 14.
[0052] The AST node with the identifier 35 describes an identifier node, namely identifier_node, which represents a string, namely sum.
[0053] The AST node identified as 8 describes a variable declaration, var_dec1, which has attributes such as name (parameter name), type (type), and size (size). The name pointer points to the AST node identified as 12.
[0054] The AST node identified as 14 describes a variable declaration, var_dec1, which has attributes such as name (parameter name), type (type), and size (size). The name attribute points to the AST node identified as 30.
[0055] The AST node with the identifier 12 describes an identifier node, namely identifier_node, which represents a string, namely string 'a'.
[0056] The AST node identified as 30 describes an identifier node, namely identifier_node, which represents a string, namely string b.
[0057] As can be seen from the above description, such as Figure 2 The AST shown can represent the string sum = a + b.
[0058] This disclosure allows for node traversal of the AST in various ways. For example, during the compilation of the program source code, when a registered callback event is invoked, the currently formed AST can be obtained first, that is, the AST formed during the compilation process of the program source code. Then, the nodes of the currently obtained AST can be traversed in a breadth-first traversal order.
[0059] A specific example, targeting Figure 2 The order in which all AST nodes in the AST shown are traversed can be: AST node with identifier 21, AST node with identifier 31, AST node with identifier 33, AST node with identifier 35, AST node with identifier 8, AST node with identifier 14, AST node with identifier 12, and AST node with identifier 30.
[0060] By traversing the AST nodes in a breadth-first order, it is beneficial to cover all AST nodes conveniently and comprehensively, avoiding the omission of AST nodes, thus facilitating the comprehensiveness of instrumentation. In addition, since there are usually no dependencies between AST nodes at the same level, it is beneficial to provide convenient conditions for parallel instrumentation.
[0061] S101. For the currently traversed AST node, obtain the node type of the AST node.
[0062] During node traversal of an AST, the node type of each traversed AST node needs to be obtained. The node type of the AST node in this disclosure can represent the operation involved in the AST node. For example, the node type can include: assignment statement node type, conditional statement node type, loop statement node type, variable declaration node type, method declaration node type, arithmetic operation node type, comparison operation node type, logical operation node type, modification node type, and initialization node type, etc. Additionally, the node type can also include: destruction node type.
[0063] In one example, some AST nodes directly contain node type information, while others, although not directly containing node type information, can have their node type determined through their attributes and methods. This disclosure does not limit the specific representation of node types or the specific implementation method for obtaining the node type of an AST node.
[0064] S102. If it is determined that the node type of the above AST node belongs to the preset node type set and the parameters corresponding to the above AST node belong to the preset monitoring parameter set, set the observation node information for the above AST node.
[0065] The set of preset node types in this disclosure includes at least one preset node type, and a preset node type refers to a node type used to set the value of the parameter corresponding to the AST node (such as the variable corresponding to the AST node). That is, if an AST node is used to set the value of its corresponding parameter, then the type of the AST node is a preset node type. Specifically, the preset node type may include a node type that directly determines the value of the parameter corresponding to the AST node through assignment or other means.
[0066] In one example, the preset node type set may include some or all of the modification node type and initialization node type. The preset node type set may also include destruction node type, etc. The modification node type is used to modify the value of the parameter corresponding to the AST node, that is, to update the value of the parameter corresponding to the AST node. The updated value of the parameter can be different from or the same as the value before the update. The initialization node type is used to set an initial value for the parameter corresponding to the AST node; that is, an AST node of the initialization node type can change its corresponding parameter from having no value to having an initial value. The destruction node type is used to release the resources occupied by the parameter corresponding to the AST node; that is, an AST node of the destruction node type can indicate the end of the lifecycle of its corresponding parameter. In this disclosure, the parameter corresponding to the AST node can be an integer type parameter, a character type parameter, or a pointer type parameter, etc., and this disclosure does not limit this.
[0067] In one example Figure 2 The AST node identified as 21 is a modification node, and it's used to update the value of `sum` to the result of the operation `a+b`, where the parameter `sum` is a character type. Additionally, Figure 2 There are no AST nodes of type initialization or type destruction in this document. If an AST node is used to set the initial value of sum to null (empty) or a default value, then that AST node can be considered an initialization node type. The specific content included in the preset node type set disclosed herein can be set according to the user's actual needs, and this disclosure does not limit it in this regard.
[0068] In the lifecycle of the parameters corresponding to AST nodes, setting an initial value for a parameter can be considered the starting point of its lifecycle, while modifying the value of a parameter can be considered an important trajectory point (i.e., a key point / key trajectory point) in the lifecycle of a parameter. Therefore, by setting modified node types and initialized node types in the preset node type set, and determining whether the node type of the currently traversed AST node belongs to the preset node type set, it is beneficial to filter out all AST nodes that have a critical impact on the lifecycle of parameters. By setting observation node information for such AST nodes, it is beneficial to set instrumentation information at key positions in the lifecycle of the parameters that need to be monitored, thereby gaining a full understanding of the lifecycle of the parameters that need to be monitored, and thus helping to troubleshoot problems in the program.
[0069] In one example, this disclosure provides a preset set of monitoring parameters for callback events. This preset set of monitoring parameters is set according to the parameters that the user actually needs to monitor. For example, the preset set of monitoring parameters includes one or more parameters that need to be monitored throughout their lifecycle, and each parameter in the preset set can be described using its attribute information, etc. The information in the preset set used to describe a parameter can be considered as a record, and each record typically uniquely corresponds to one parameter.
[0070] In one example, a record in the preset monitoring parameter set may include, in addition to the attribute information of the parameters that need to be monitored throughout their lifecycle, descriptive or remark information about the parameters, to make the content of the preset monitoring parameter set easier for users to understand. The attribute information of the parameters in this disclosure may include one or more of the following: the parameter's scope type, the parameter's name, the parameter's data type, and the name of the scope to which the parameter belongs. When the parameter in this disclosure is a variable, the attribute information of the parameter, i.e., the variable's attribute information, may include one or more of the following: the variable's scope type, the variable's name, the variable's data type, and the name of the scope to which the variable belongs. An example of using a JSON file to represent a preset monitoring parameter set in this disclosure can be expressed in the following pseudocode form:
[0071]
[0072]
[0073]
[0074] In one example, the process by which this disclosure determines whether the parameter corresponding to the currently traversed AST node belongs to the preset monitoring parameter set can be as follows:
[0075] First, obtain the attribute information of the variable corresponding to the currently traversed AST node. For example, obtain the scope type, variable name, and the name of the scope to which the variable belongs. Additionally, the variable's data type can optionally be included. Although variables can take many different forms, generally, the scope type, variable name, data type, and the name of the scope to which the variable belongs can uniquely correspond to a variable in the program.
[0076] Secondly, it is determined whether the attribute information of the variables obtained above matches the attribute information of the preset monitoring variables in the preset monitoring parameter set. That is, it is determined whether there is attribute information in the preset monitoring parameter set that matches the attribute information of the variables obtained above. If there is no matching attribute information in the preset monitoring parameter set, it is determined that the variable corresponding to the currently traversed AST node does not belong to the preset monitoring parameter set. If there is matching attribute information in the preset monitoring parameter set, it is determined that the variable corresponding to the currently traversed AST node belongs to the preset monitoring parameter set.
[0077] By utilizing attributes such as the variable's scope type, name, data type, and scope name, it's possible to determine whether the variable corresponding to the currently traversed AST node belongs to the preset monitoring parameter set. This facilitates quick and accurate filtering of AST nodes that require monitoring during traversal, avoiding inappropriate or missed monitoring node settings. Especially when the preset monitoring parameter set comes from a JSON file, users can flexibly set variables whose lifecycles need monitoring according to actual needs, enhancing the flexibility of program debugging.
[0078] In one example, this disclosure can divide the preset monitoring parameter set into a preset global parameter set (such as a preset global variable set), a preset class member parameter set (such as a preset class member variable set), and a preset local parameter set (such as a preset local variable set) according to the scope type of the parameters whose lifecycle needs to be monitored. When the parameter's attribute information includes: the parameter's scope type (such as the variable's scope type), the parameter's name (such as the variable's name), the parameter's data type (such as the variable's data type), and the name of the parameter's scope (such as the variable's scope name), the process by which this disclosure determines whether the parameter corresponding to the currently traversed AST node belongs to the preset monitoring parameter set based on the attribute information of the parameter (such as the variable) corresponding to the AST node can take any of the following forms:
[0079] The system retrieves the attribute information of the variable corresponding to the currently traversed AST node. If the scope type of the variable in the attribute information is global, it checks whether there exists any attribute information in the preset global parameter set that matches the variable name and data type in the attribute information of the variable corresponding to the AST node. If a matching attribute information exists, it determines that the variable corresponding to the currently traversed AST node belongs to the preset monitoring parameter set; otherwise, it determines that the variable corresponding to the currently traversed AST node does not belong to the preset monitoring parameter set. In one example, the data type of the variable may not be included in the matching judgment.
[0080] The system retrieves the attribute information of the variable corresponding to the currently traversed AST node. If the scope type of the variable in the attribute information is a class member variable, it checks whether there exists any attribute information in the preset set of class member variables that matches the class name, variable name, and data type of the variable in the attribute information of the variable corresponding to the AST node. If a matching attribute information exists, it determines that the variable corresponding to the currently traversed AST node belongs to the preset monitoring parameter set; otherwise, it determines that the variable corresponding to the currently traversed AST node does not belong to the preset monitoring parameter set. In one example, the data type of the variable can also be omitted during the matching judgment.
[0081] The system retrieves the attribute information of the variable corresponding to the currently traversed AST node. If the scope type of the variable in the attribute information is a local variable, it checks whether there exists any attribute information in the preset local variable set that matches the local region name, variable name, and data type of the variable in the attribute information of the variable corresponding to the AST node. If a matching attribute information exists, it determines that the variable corresponding to the currently traversed AST node belongs to the preset monitoring parameter set; otherwise, it determines that the variable corresponding to the currently traversed AST node does not belong to the preset monitoring parameter set. In one example, the data type of the variable can also be omitted during the matching judgment.
[0082] By dividing the preset monitoring parameter set into preset global variable set, preset class member variable set, and preset local variable set according to the scope type of the variable, the preset monitoring parameter set can be set in a categorized manner. This allows for the use of different sets and different judgment methods for different scope types of variables, so as to accurately and quickly determine whether the variable corresponding to the AST node belongs to the preset monitoring parameter set.
[0083] In one example, if this disclosure determines that an AST node's node type belongs to a preset node type set and the parameters corresponding to that AST node belong to a preset monitoring parameter set, then that AST node can be designated as a node to be observed. That is, an observation node needs to be set for that AST node. The function of this observation node is to record the current value of the parameters corresponding to that AST node. The observation node information set for the AST node in this disclosure is mainly used to set up the observation node for that AST node. Specifically, the content of the observation node information set for the AST node in this disclosure is determined by the location of the observation node and the monitoring operations that the observation node needs to perform. Specifically, the observation node information set for the AST node in this disclosure may include: the location information of the observation node in the AST and the monitoring content of the parameters corresponding to the AST node. The monitoring content of the parameters may include: key information of the AST node and log recording strategy information. The log recording strategy information is used to describe the information to be recorded (such as the current value of variables) and the output method of the recorded information.
[0084] S103. Based on the observation node information, construct observation nodes for the above AST nodes in the AST to realize the instrumentation operation of the preset monitoring parameters corresponding to the above AST nodes.
[0085] The operation of constructing observation nodes for AST nodes in this disclosure can be considered as setting instrumentation information for corresponding parameters in the program. The observation nodes added to the AST in this disclosure are mainly used to obtain key information of their corresponding AST nodes (such as the current value of variables and other information that needs to be recorded), and output the obtained key information to a target location (such as a log file). The key information of the AST nodes in this disclosure can be set according to the information needed by the user. For example, the key information of the AST nodes may include: the subject that applies the setting and value-taking behavior to the parameter corresponding to the AST node (such as the name of the method to which the variable belongs), the time when the setting and value-taking behavior is applied to the parameter corresponding to the AST node (such as the current time), the specific behavior applied to the parameter corresponding to the AST node (such as addition, multiplication, or negation), and the new and old values of the parameter corresponding to the AST node. This disclosure does not limit the specific content included in the key information of the AST nodes.
[0086] In one example, the monitoring content of the parameters corresponding to the AST node in this disclosure may include logging policy information, and the logging policy information includes at least one of: console log type, log file type, and pipeline log type. The console log type refers to a logging policy that uses console logs to record key information. The log file type refers to a logging policy that uses log files to record key information. The pipeline log type refers to a logging policy that uses pipeline logs to record key information. That is, the observation node can output the key information it obtains to the corresponding console log, the corresponding log file, or the corresponding pipeline log. This disclosure may use one of the log types in the logging policy information as the default logging policy; for example, the log file type may be used as the default logging policy.
[0087] In one example, this disclosure may record the observation node information of all selected AST nodes during the node traversal of the AST, and after the node traversal of the AST is successfully completed, the operation of constructing observation nodes for the selected AST nodes is uniformly executed based on all the recorded observation node information. Of course, this disclosure does not exclude the possibility of constructing observation nodes for the currently selected AST nodes based on the currently set observation node information during the node traversal of the AST.
[0088] In one example, this disclosure can classify observation nodes into three types based on different logging strategy information: console log type observation nodes, log file type observation nodes, and pipeline log type observation nodes. This disclosure can store the observation node information corresponding to each of the selected AST nodes in an observation node information list. After traversing the AST, the observation node information can be read sequentially from the observation node information list, and the logging strategy information in the currently read observation node information can be judged. If the judgment result indicates that the observation node is a console log type observation node, the observation node can be constructed by calling the construction method based on the console log type, and the currently constructed observation node can be set at the corresponding position in the AST based on the position information in the observation node information. If the judgment result indicates that the observation node is a log file type observation node, the observation node can be constructed by calling the construction method based on the log file type, and the currently constructed observation node can be set at the corresponding position in the AST based on the position information in the observation node information. If the judgment result indicates that the observation node is a pipeline log type observation node, the observation node can be constructed by calling the construction method based on the pipeline log type, and the currently constructed observation node can be set at the corresponding position in the AST based on the position information in the observation node information. In some application scenarios, this disclosure allows the observation node to be set as a downstream node of the corresponding AST node in the AST. In other application scenarios, this disclosure allows the observation node to be set as an upstream node of the corresponding AST node in the AST. Furthermore, the number of observation nodes constructed for an AST node can be one or two.
[0089] This disclosure allows for differentiation in the construction methods of observation nodes by setting up observation nodes with different log types. This makes the construction process of observation nodes easier to maintain, and allows the observation nodes to flexibly output key information and other monitoring content they obtain according to actual needs.
[0090] In one example, S100, S101, and S102 in this disclosure can be described in the form of the following pseudocode:
[0091]
[0092]
[0093]
[0094] In one example, S103 in this disclosure can be described in the form of the following pseudocode:
[0095]
[0096]
[0097] A concrete example of the application of the parameter monitoring method disclosed herein in GCC is as follows: Figure 3 As shown.
[0098] Figure 3 First, obtain the source code of the program to be debugged, main.c, which is a C language source file.
[0099] Secondly, GCC preprocesses main.c, for example, it processes directives such as #include and #define to generate the main.i file.
[0100] Next, GCC continues the compilation process on the main.i file, converting its contents into an intermediate representation such as an AST. For example, GCC generates an AST based on the main.i file. Then, callback events registered by an extended GCC plugin after the AST generation phase are invoked. The source file of the extended GCC plugin in this disclosure is customer_plugin.c, which generates a dynamic link library customer_plugin.so. This dynamic link library registers callback events after the AST generation phase and before the AST generalization phase. The invoked callback events traverse the AST nodes to filter out those that require observation nodes, and set observation nodes for all filtered AST nodes, thereby modifying and updating the AST.
[0101] Furthermore, GCC generalizes the modified and updated AST, that is, the modified and updated AST is converted into a GIMPLE intermediate representation.
[0102] Furthermore, GCC converts the GIMPLE intermediate representation into RTL (Register Transfer Level) language.
[0103] Next, GCC performs code generation and other processing on the RTL language to form assembly code, namely the main.s file.
[0104] Next, GCC calls the assembler, which then assembles the main.s file to form the object file main.o.
[0105] Finally, GCC calls the linker to link the object file main.o, such as linking main.o with other necessary library files, in order to generate the final computer executable program, i.e., program.
[0106] In one example, the flow of the method disclosed herein for implementing parameter monitoring is as follows: Figure 4 As shown.
[0107] Figure 4 In the process of compiling the program source code using GCC, after GCC generates the AST, the callback event registered by the extended GCC plugin after the stage used to generate the AST is invoked, and the method disclosed herein begins.
[0108] S401. Following the breadth-first principle, perform AST node traversal on the AST.
[0109] S402. Determine whether the type of the currently traversed AST node belongs to the type of node modification or node initialization. If it is the type of node modification or node initialization, proceed to S403; otherwise, proceed to S405.
[0110] S403. Determine whether the variable corresponding to the currently traversed AST node is a variable whose lifecycle needs to be monitored. If it is a variable whose lifecycle needs to be monitored, proceed to S404; otherwise, proceed to S405.
[0111] S404. Set observation node information for the currently traversed AST node and record the observation node information, for example, add the observation node information to an observation node information list.
[0112] S405. Determine if there are any unvisited AST nodes. If there are, return to S401 and continue traversing the AST according to the breadth-first principle. Otherwise, proceed to S406.
[0113] S406. Based on all the recorded observation node information (such as the observation node information in the observation node information list), set the observation node for the corresponding AST node in the AST.
[0114] S407. The method disclosed herein is now complete.
[0115] Exemplary device
[0116] Figure 5 This is a schematic diagram of a specific embodiment of the device for implementing parameter monitoring according to the present disclosure. The device of this embodiment can be used to implement the present disclosure. Figures 1 to 4The method embodiment shown. The apparatus is run during the compilation of the source code of the program to be debugged, and the process of running the apparatus is located between the preprocessing stage and the target code generation stage of the source code compilation process.
[0117] like Figure 5 The apparatus shown mainly includes: a traversal module 500, a node type acquisition module 501, an observation node information setting module 502, and an observation node construction module 503. In one example, the traversal module 500, the node type acquisition module 501, the observation node information setting module 502, and the observation node construction module 503 can form a callback event, which is invoked during the compilation of the program source code to be debugged using GCC. In this example, the apparatus of this disclosure may further include: an extended GCC plugin 510, which registers the callback event after the preprocessing stage and before the target code generation stage during the program source code compilation process. In one example, the callback event is registered by the extended GCC plugin 510 after the AST formation stage and before the AST generalization stage during the program source code compilation process. The extended GCC plugin 510 is also used to read a preset set of monitoring parameters from a JSON file. The modules included in the apparatus are described below.
[0118] The traversal module 500 is used to traverse the nodes of the Abstract Syntax Tree (AST) formed during the compilation of the program source code. In one example, the traversal module 500 obtains the AST formed during the stage of compiling the program source code to form the AST, and performs node traversal on the obtained AST in a breadth-first traversal order.
[0119] The node type acquisition module 501 is used to acquire the node type of the AST node currently being traversed by the traversal module 500.
[0120] The observation node information setting module 502 is used to set observation node information for AST nodes when it is determined that the node type of the AST node obtained by the node type acquisition module 501 belongs to a preset node type set, and that the parameter corresponding to the AST node belongs to a preset monitoring parameter set. The preset node type set includes node types used to set the values of the parameters corresponding to the AST node. For example, the preset node type set may include at least one of: modifying node type and initializing node type; the modifying node type is used to modify the value of the parameter corresponding to the AST node, and the initializing node type is used to set an initial value for the parameter corresponding to the AST node. The preset monitoring parameter set includes at least one parameter whose lifecycle needs to be monitored. The observation node information includes: the location information of the observation node in the AST and the monitoring content of the parameter corresponding to the AST node. In one example, the method by which the setting observation node information module 502 determines that the parameter corresponding to the AST node belongs to the preset monitoring parameter set can be as follows: The setting observation node information module 502 obtains the attribute information of the variable corresponding to the AST node. If it is determined that the attribute information of the variable matches the attribute information of the preset monitoring variables in the preset monitoring parameter set, it is determined that the variable corresponding to the AST node belongs to the preset monitoring parameter set. The attribute information of the variable may include at least one of the following: the scope type of the variable, the name of the variable, the data type of the variable, and the name of the scope to which the variable belongs. For example, if the scope type of the variable corresponding to the currently traversed AST node is a global variable type, and the name and data type of the variable corresponding to the AST node match the attribute information of the preset monitoring variables in the preset global variable set, then the setting observation node information module 502 determines that the variable corresponding to the AST node belongs to the preset monitoring parameter set. For example, if the scope type of the variable corresponding to the currently traversed AST node is a class member variable type, and the class name, variable name, and data type of the variable corresponding to the AST node match the attribute information of the preset monitoring variables in the preset class member variable set, then the observation node information module 502 determines that the variable corresponding to the AST node belongs to the preset monitoring parameter set. For example, if the scope type of the variable corresponding to the currently traversed AST node is a local variable type, and the local region name, variable name, and data type of the variable corresponding to the currently traversed AST node match the attribute information of the preset monitoring variables in the preset local parameter set, then the observation node information module 502 determines that the variable corresponding to the AST node belongs to the preset monitoring parameter set.
[0121] The observation node construction module 503 is used to construct observation nodes for the corresponding AST nodes in the AST according to the observation node information set by the observation node setting module 502, so as to realize the instrumentation operation of the preset monitoring parameters corresponding to the AST nodes. In one example, the monitoring content of the parameters corresponding to the AST nodes includes: the subject of the setting and value taking behavior applied to the parameters corresponding to the AST nodes (such as the name of the method to which the variable belongs), the time of applying the setting and value taking behavior applied to the parameters corresponding to the AST nodes (such as the current time), the specific behavior applied to the parameters corresponding to the AST nodes (such as addition, multiplication, or negation), and key information such as the new and old values of the parameters corresponding to the AST nodes, as well as logging policy information. If the logging policy information can include at least one of the following: console log type, log file type, and pipe log type, the observation node construction module 503 can construct observation nodes of the corresponding log type for the AST nodes according to the logging policy information, and set observation nodes of the corresponding log type for the AST nodes in the AST according to the position information of the observation nodes in the AST.
[0122] Exemplary electronic devices
[0123] The following is for reference. Figure 6 To describe an electronic device according to embodiments of the present disclosure. Figure 6 A block diagram of an electronic device according to an embodiment of the present disclosure is shown. (As follows) Figure 6 As shown, the electronic device 61 includes one or more processors 611 and memory 612.
[0124] The processor 611 may be a central processing unit (CPU) or other form of processing unit with data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device 61 to perform desired functions.
[0125] The memory 612 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may, for example, include random access memory (RAM) and / or cache memory. The non-volatile memory may, for example, include read-only memory (ROM), hard disk, and flash memory. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 611 may execute the program instructions to implement the methods for parameter monitoring and / or other desired functions described in the various embodiments of this disclosure above.
[0126] In one example, electronic device 61 may further include input device 613 and output device 614, etc., these components being interconnected via a bus system and / or other forms of connection mechanism (not shown). Furthermore, the input device 613 may include, for example, a keyboard, mouse, etc. The output device 614 can output various information to the outside. The output device 614 may include, for example, a display, speaker, printer, and communication networks and their connected remote output devices, etc.
[0127] Of course, for the sake of simplicity, Figure 6 Only some of the components of the electronic device 61 relevant to this disclosure are shown, omitting components such as buses, input / output interfaces, etc. In addition, the electronic device 61 may include any other suitable components depending on the specific application.
[0128] Exemplary computer program products and computer-readable storage media
[0129] In addition to the methods and apparatus described above, embodiments of this disclosure may also be computer program products comprising computer program instructions that, when executed by a processor, cause the processor to perform the steps in the methods for implementing parameter monitoring according to various embodiments of this disclosure as described in the "Exemplary Methods" section of this specification.
[0130] The computer program product can be written in any combination of one or more programming languages to perform the operations of the embodiments of this disclosure. The programming languages include object-oriented programming languages such as Java and C++, as well as conventional procedural programming languages such as C or similar languages. The program source code can be executed entirely on a user's computing device, partially on a user's computing device, as a standalone software package, partially on a user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0131] Furthermore, embodiments of this disclosure may also be computer-readable storage media storing computer program instructions that, when executed by a processor, cause the processor to perform the steps in the methods for implementing parameter monitoring according to various embodiments of this disclosure as described in the "Exemplary Methods" section above.
[0132] The computer-readable storage medium may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may, for example, include, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples (not an exhaustive list) of a readable storage medium may include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0133] The basic principles of this disclosure have been described above with reference to specific embodiments. However, it should be noted that the advantages, benefits, and effects mentioned in this disclosure are merely examples and not limitations, and should not be considered as essential features of each embodiment of this disclosure. Furthermore, the specific details disclosed above are for illustrative and facilitative purposes only, and are not limitations. These details do not limit the scope of this disclosure to the necessity of employing the aforementioned specific details for implementation.
[0134] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For system embodiments, since they largely correspond to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0135] The methods and apparatus of this disclosure may be implemented in many ways. For example, they may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above-described order of steps for the methods is for illustrative purposes only, and the steps of the methods of this disclosure are not limited to the order specifically described above unless otherwise specifically stated. Furthermore, in some embodiments, this disclosure may also be implemented as a program recorded on a recording medium, the program including machine-readable instructions for implementing the methods according to this disclosure. Thus, this disclosure also covers recording media storing programs for performing the methods according to this disclosure.
[0136] The above description has been given for purposes of illustration and description. Furthermore, this description is not intended to limit the embodiments of this disclosure to the forms disclosed herein. Although numerous exemplary aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations thereof.
Claims
1. A method for implementing parameter monitoring, characterized in that, The method is executed during the compilation of the source code of the program to be debugged, and the execution of the method is located between the preprocessing stage and the target code generation stage of the source code compilation process. The method includes the following steps: Perform node traversal on the Abstract Syntax Tree (AST) formed during the compilation of the program source code; For the currently traversed AST node, obtain the node type of the AST node; If it is determined that the node type of the AST node belongs to a preset node type set, and the parameters corresponding to the AST node belong to a preset monitoring parameter set, then observation node information is set for the AST node. Based on the observation node information, an observation node is constructed for the AST node in the AST to realize the instrumentation operation of the preset monitoring parameters corresponding to the AST node; The preset node type includes: a node type used to set the values of the parameters corresponding to the AST node; the preset monitoring parameter set includes: at least one parameter whose lifecycle needs to be monitored; and the observation node information includes: the location information of the observation node in the AST and the monitoring content of the parameters corresponding to the AST node.
2. The method according to claim 1, characterized in that, The method is executed during the compilation of the program source code of the program to be debugged using the GNU compiler, and the steps included in the method are executed by a registered callback event. The callback event is registered by the extended GNU compiler plugin after the preprocessing stage and before the target code generation stage in the program source code compilation process.
3. The method according to claim 2, characterized in that, The callback event is registered by the extended GNU compiler plugin after the stage for forming the AST during the program source code compilation process and before the stage for generalizing the AST. The extended GNU compiler plugin is also used to read a preset set of monitoring parameters from a JavaScript object representation JSON file.
4. The method according to claim 3, characterized in that, The node traversal of the AST (Abstract Syntax Tree) formed during the compilation of the program source code includes: When the registered callback event is invoked during the compilation of the program source code, the AST formed in the stage of the program source code compilation process is obtained, and the nodes of the obtained AST are traversed in a breadth-first traversal order.
5. The method according to any one of claims 1 to 4, characterized in that, The preset node type set includes at least one of: modifying node type and initializing node type; The modified node type is used to modify the value of the parameter corresponding to the AST node, and the initialized node type is used to set the initial value of the parameter corresponding to the AST node.
6. The method according to any one of claims 1 to 4, characterized in that, The parameters corresponding to the AST node are variables, and determining that the parameters corresponding to the AST node belong to a preset monitoring parameter set includes: Obtain the attribute information of the variables corresponding to the AST nodes; If the attribute information of the variable is determined to match the attribute information of the preset monitoring variable in the preset monitoring parameter set, the variable corresponding to the AST node is determined to belong to the preset monitoring parameter set. The attribute information of the variable includes at least one of the following: the variable's scope type, the variable's name, the variable's data type, and the name of the scope to which the variable belongs.
7. The method according to claim 6, characterized in that, The step of determining that the variable corresponding to the AST node belongs to the preset monitoring parameter set when the attribute information of the variable matches the attribute information of the preset monitoring variable in the preset monitoring parameter set includes: If the scope type of the variable corresponding to the currently traversed AST node is a global variable, and the name of the variable corresponding to the AST node matches the attribute information of the preset monitoring variables in the preset global variable set, then it is determined that the variable corresponding to the AST node belongs to the preset monitoring parameter set; and / or If the scope type of the variable corresponding to the currently traversed AST node is a class member variable type, and the class name to which the variable corresponding to the AST node belongs, and the name of the variable, match the attribute information of the preset monitoring variables in the preset class member variable set, then it is determined that the variable corresponding to the AST node belongs to the preset monitoring parameter set; and / or If the scope type of the variable corresponding to the currently traversed AST node is a local variable type, and the name of the method to which the variable corresponding to the currently traversed AST node belongs and the name of the variable match the attribute information of the preset monitoring variables in the preset local parameter set, then it is determined that the variable corresponding to the AST node belongs to the preset monitoring parameter set.
8. The method according to any one of claims 1 to 4, characterized in that, The monitoring content of the parameters corresponding to the AST node includes: log recording policy information, and the log recording policy information includes at least one of: console log type, log file type and pipeline log type; The step of constructing observation nodes for the AST nodes in the AST based on the observation node information includes: Based on the log recording strategy information, construct observation nodes of the corresponding log type for the AST nodes; Based on the location information of the observation node in the AST, an observation node of the corresponding log type is set for the AST node in the AST.
9. A computer-readable storage medium storing a computer program for performing the method according to any one of claims 1-8.
10. An electronic device, the electronic device comprising: processor; Memory used to store the processor's executable instructions; The processor is configured to read the executable instructions from the memory and execute the instructions to implement the method of any one of claims 1-8.
Citation Information
Patent Citations
Protocol fuzz testing method and system based on long life cycle enumeration variable state
CN119676131A
Predicate matching library for complex program analysis
US8881122B1