CN115658511A - Method and system for monitoring execution behavior of source code - Google Patents

Method and system for monitoring execution behavior of source code Download PDF

Info

Publication number
CN115658511A
CN115658511A CN202211324987.3A CN202211324987A CN115658511A CN 115658511 A CN115658511 A CN 115658511A CN 202211324987 A CN202211324987 A CN 202211324987A CN 115658511 A CN115658511 A CN 115658511A
Authority
CN
China
Prior art keywords
execution
monitoring
code
source code
language
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202211324987.3A
Other languages
Chinese (zh)
Other versions
CN115658511B (en
Inventor
张永选
余顺琴
洪如霞
孔婷
余宏
来敏健
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Yu Zhang Teachers College
Original Assignee
Yu Zhang Teachers College
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Yu Zhang Teachers College filed Critical Yu Zhang Teachers College
Priority to CN202211324987.3A priority Critical patent/CN115658511B/en
Publication of CN115658511A publication Critical patent/CN115658511A/en
Application granted granted Critical
Publication of CN115658511B publication Critical patent/CN115658511B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a method and a system for monitoring execution behaviors of source codes, and belongs to the field of program analysis. The method comprises the following steps: acquiring a target source code, and analyzing the target source code to acquire a language type; adopting a static parser to convert the target source code from the original language type to a code of C language; executing the code of the C language in a simulation execution environment, and collecting the execution details of each layer of circulation in the simulation execution process to generate a monitoring list; calling a visual interface to display the monitoring list, wherein the monitoring list can be suitable for code monitoring of different languages, and program source codes do not need to be modified; executing the code of the C language in a simulation execution environment, collecting the execution details of each layer of circulation in the simulation execution process to generate a monitoring list, calling a visual interface to display the monitoring list, wherein the visualized monitoring list reflects the business logic and behavior interaction of software.

Description

Method and system for monitoring execution behavior of source code
Technical Field
The invention belongs to the field of program analysis, and particularly relates to a method and a system for monitoring execution behaviors of source codes.
Background
The requirement on increasingly huge software is increased, the complexity of the software is increased, the availability requirement is increased, a software system is more fragile, various problems often occur, and the work and life of people are adversely affected or even huge loss is caused. The monitoring of the software running state has important significance for real-time health state analysis, fault location and the like.
Currently, software analysis is performed manually or automatically by using software as an object through a static or dynamic method. Most of software behavior analysis and verification methods and systems perform behavior monitoring, analysis and verification on software to be verified through static codes, and not only program source codes need to be modified, but also programming burden is heavy, and regulation and control of monitoring and analysis granularity are lacked. In terms of concerns, most monitoring only focuses on the software itself, and there is a lack of effective monitoring and verification of software business logic and behavioral interactions.
Therefore, a method capable of monitoring software business logic and behavior interaction is needed.
Disclosure of Invention
Aiming at the defects of the prior art, the invention aims to provide a method and a system for monitoring the execution behavior of source code, and aims to solve the problem that the prior method lacks effective monitoring and verification on software business logic and behavior interaction.
In order to achieve the above object, in a first aspect, the present invention provides a method for monitoring execution behavior of source code, where the method includes:
acquiring a target source code, and analyzing the target source code to acquire a language type;
adopting a static parser to convert the target source code from the original language type to a code of C language;
executing the code of the C language in a simulation execution environment, and collecting the execution details of each layer of circulation in the simulation execution process to generate a monitoring list;
and calling a visual interface to display the monitoring list.
Preferably, the static parser performs lexical analysis on the target source code according to the keywords and the symbols; constructing an abstract syntax tree according to the syntax characteristics; establishing association between each syntax element according to the semantic features and the abstract syntax tree; and constructing a code of the C language according to the lexical analysis result, the abstract syntax tree and the syntax association.
Preferably, the collecting the execution details of each layer cycle during the simulation execution process to generate the monitoring list includes:
recording the position information of the current execution statement, and determining the position of the current execution statement in a hierarchical structure of a nested loop;
solving the truth of each conditional expression, the value of each variable and the value of the expression in the current execution statement;
generating a monitoring result of the currently executed statement, wherein the monitoring result comprises: location information, hierarchy location, and the current execution statement containing the solution.
Preferably, the simulation is executed starting from the main function or the specified function until execution reaches the exit point of the function or until execution reaches a specified number of steps.
Preferably, the invoking a visual interface displays the monitoring list, including:
and according to the position of the hierarchical structure, each monitoring result is hierarchically indented, so that the indentation amount of the monitoring results in different loop layers is increased along with the depth of loop nesting, and the indentation amount of the monitoring results in the same loop layer is the same.
Preferably, according to the position of the hierarchical structure, different colors are used for displaying each monitoring result, so that the colors of the monitoring results in different circulation layers are different, and the colors of the monitoring results in the same circulation layer are the same.
Preferably, the method further comprises: and collecting the execution details of each function in the simulation execution process to generate a dependency graph of the function.
In order to achieve the above object, in a second aspect, the present invention provides a system for monitoring execution behavior of source code, the system including: a processor and a memory; the memory is used for storing computer execution instructions; the processor is configured to execute the computer-executable instructions to cause the method of the first aspect to be performed.
Generally, compared with the prior art, the technical scheme conceived by the invention has the following beneficial effects:
the invention provides a method and a system for monitoring execution behaviors of source codes, which are applicable to code monitoring of different languages by adopting a static parser to convert target source codes from an original language type into codes of C language without modifying program source codes; executing the code of the C language in a simulation execution environment, collecting the execution details of each layer of circulation in the simulation execution process to generate a monitoring list, calling a visual interface to display the monitoring list, wherein the visualized monitoring list reflects the service logic and behavior interaction of software.
Drawings
Fig. 1 is a flowchart of a method for monitoring execution behavior of source code according to the present invention.
Fig. 2 is a schematic code diagram of the conversion of the target source code into the C language provided in this embodiment.
Fig. 3 is a schematic diagram of a simulation execution result according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and do not limit the invention.
Fig. 1 is a flowchart of a method for monitoring execution behavior of source code according to the present invention. As shown in fig. 1, the method includes:
and acquiring a target source code, and analyzing the target source code to obtain the language type.
And adopting a static parser to convert the target source code from the original language type into the code of the C language.
Preferably, the static parser performs lexical analysis on the target source code according to the keywords and the symbols; constructing an abstract syntax tree according to the syntax characteristics; establishing association between each syntax element according to the semantic features and the abstract syntax tree; and constructing the code of the C language according to the lexical analysis result, the abstract syntax tree and the syntax correlation.
And executing the code of the C language in the simulation execution environment, and collecting the execution details of each layer of loop in the simulation execution process to generate the monitoring list.
Preferably, the collecting the execution details of each layer cycle during the simulation execution process to generate the monitoring list includes: recording the position information of the current execution statement, and determining the position of the current execution statement in the hierarchical structure of the nested loop; solving the truth of each conditional expression, the value of each variable and the value of the expression in the current execution statement; generating a monitoring result of the currently executed statement, wherein the monitoring result comprises: location information, hierarchy location, and the current execution statement containing the solution.
Preferably, the simulation is executed starting with the main function or the specified function until execution reaches the exit point of the function or until execution reaches a specified number of steps.
And calling a visual interface to display the monitoring list.
Preferably, the invoking a visual interface displays the monitoring list, including: and according to the position of the hierarchical structure, each monitoring result is hierarchically indented, so that the indentation amount of the monitoring results in different loop layers is increased along with the depth of loop nesting, and the indentation amount of the monitoring results in the same loop layer is the same.
Preferably, according to the position of the hierarchical structure, different colors are used for displaying each monitoring result, so that the colors of the monitoring results in different circulation layers are different, and the colors of the monitoring results in the same circulation layer are the same.
Preferably, the method further comprises: and collecting the execution details of each function in the simulation execution process to generate a dependency graph of the function.
The invention provides a monitoring system for execution behaviors of source codes, which comprises: a processor and a memory; the memory is used for storing computer execution instructions; the processor is used for executing the computer execution instruction so as to execute the method.
Examples
The embodiment is illustrated by a simple target source code. Fig. 2 is a schematic code diagram of the conversion of the target source code into the C language provided in this embodiment. The monitor list generation process is as follows:
(1) Simulating the execution from the first statement in the function body until the execution reaches the exit point of the function, namely the ending curly brace or return statement of the function, or the execution reaches the specified step number;
(2) Each time a line of C language code is executed, a corresponding monitoring result is generated, for example, "9 flag =1", and 9 represents position information;
(3) The shrinkage amount output by each line is one unit less than that of the corresponding line of C language codes, namely 4 half-angle spaces;
(4) Variables in the expression are all replaced by their current values;
(5) When the expression containing the assignment is executed, a monitoring result is generated, and the monitoring result can be characterized in the form of a line number, a variable = calculation result of the expression, for example, for a C language auto-increment operation expression "factor + +", output "9 factor =11";
(6) When the function call is executed, if the function has a return value and no print statement, the calculation result of the function is directly replaced when the function is output. If the function has a printing statement, entering the function to continue the simulation execution;
(7) When the forced type conversion is executed, the converted value is directly replaced when the output is carried out;
(8) When executing the if statement, a monitoring result is generated, which may be characterized by "line number if (logical expression): a boolean value of the logical expression calculation result" for example, for "if (flag = = 1)" in C language, assuming that the value of flag is 0 at this time, "9;
(9) When executing to the for statement, a monitoring result is generated, which may be characterized by "line number: for (loop control variable = current value: logical expression: boolean value of logical expression result)" such as "9;
(10) When executing the while statement, generating the monitoring result, may be characterized by "line number: while (logical expression): boolean value of the logical expression computation result", for example, for "while (factor < = (int) sqrt (i))", assuming that at this time factor =6 and i =101, "9;
(11) When the do-while statement is executed, the processing method is the same as the while statement;
(12) When executing the switch statement, a monitoring result is generated, which may be represented by "line number: switch (variable = calculation result of expression)", for example, for the C language "switch (trade)", assuming that trade = 'a' at this time, then "9;
(13) Because the programming methodology does not recommend using goto statements, the processing of goto statements is not considered for the time being. When a C language program with goto sentences is encountered, a user is required to rewrite the program to eliminate the goto sentences;
(14) When executing to other non-defined statements and non-comma expression statements, if the statement has a value, the value is directly written out, for example, for the statement "int flag =1" which defines variables and initializes, the value of "9;
(15) When executing to a constant definition statement or a variable definition statement containing initialization, a "constant = value" or a "variable = initial value" is output, for example, for a C language constant definition statement "const int MaxNum =100", a "9;
(16) When the variable definition statement without initialization is executed, output is not needed;
(17) When the comma expression is executed, the rules are applied in turn and output on the same line for each part.
Fig. 3 is a schematic diagram of a simulation execution result according to an embodiment of the present invention. As shown in fig. 3, includes: the program starts execution from the entry point, i.e. the main function (line 4 of fig. 2). Lines 1, 9, 42, 50 and 83 in fig. 3 all begin with line 5 (line 5 in fig. 2), which indicates that the authenticity of the conditional expression, and the change of the variables and the values of the expressions in parentheses in the same for loop layer reflect the evolution of the execution behavior of the source code in the code execution process; lines 4, 12, 15, 18.. 80, all beginning with 8 (line 8 in fig. 2), represent at the same while loop level, and are incrementally indented relative to beginning with 5, reflecting the hierarchy of nested loop levels, and the overall may reflect the software logic and behavior interactions, especially the associations that exist for the inner and outer loop control variables.
It will be understood by those skilled in the art that the foregoing is only an exemplary embodiment of the present invention, and is not intended to limit the invention to the particular forms disclosed, since various modifications, substitutions and improvements within the spirit and scope of the invention are possible and within the scope of the appended claims.

Claims (8)

1. A method for monitoring execution behavior of source code, the method comprising:
acquiring a target source code, and analyzing the target source code to acquire a language type;
adopting a static parser to convert the target source code from the original language type to a code of C language;
executing the code of the C language in a simulation execution environment, and collecting the execution details of each layer of circulation in the simulation execution process to generate a monitoring list;
and calling a visual interface to display the monitoring list.
2. The method of claim 1, wherein the static parser performs lexical analysis on target source code in terms of keywords and symbols; constructing an abstract syntax tree according to the syntax characteristics; establishing association among all syntax elements according to the semantic features and the abstract syntax tree; and constructing the code of the C language according to the lexical analysis result, the abstract syntax tree and the syntax correlation.
3. The method of claim 1, wherein collecting execution details for each layer cycle during simulation execution to generate a watch list comprises:
recording the position information of the current execution statement, and determining the position of the current execution statement in a hierarchical structure of a nested loop;
solving the truth of each conditional expression, the value of each variable and the value of the expression in the current execution statement;
generating a monitoring result of the currently executed statement, wherein the monitoring result comprises: location information, hierarchy location, and the current execution statement containing the solution.
4. The method of claim 3, wherein the simulation executes starting from the main function or the specified function until execution reaches an exit point of the function or until execution reaches a specified number of steps.
5. The method of claim 1, wherein said invoking a visual interface to display said watch list comprises:
and according to the position of the hierarchical structure, each monitoring result is hierarchically indented, so that the indentation amount of the monitoring results in different loop layers is increased along with the depth of loop nesting, and the indentation amount of the monitoring results in the same loop layer is the same.
6. The method of claim 5, wherein the monitoring results are displayed in different colors according to the position of the hierarchical structure, so that the monitoring results in different loop layers have different colors, and the monitoring results in the same loop layer have the same color.
7. The method of claim 1, further comprising: and collecting the execution details of each function in the simulation execution process to generate a dependency graph of the function.
8. A system for monitoring execution behavior of source code, the system comprising: a processor and a memory;
the memory is used for storing computer execution instructions;
the processor, configured to execute the computer-executable instructions to cause the method of any one of claims 1 to 7 to be performed.
CN202211324987.3A 2022-10-27 2022-10-27 Method and system for monitoring execution behavior of source code Active CN115658511B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211324987.3A CN115658511B (en) 2022-10-27 2022-10-27 Method and system for monitoring execution behavior of source code

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211324987.3A CN115658511B (en) 2022-10-27 2022-10-27 Method and system for monitoring execution behavior of source code

Publications (2)

Publication Number Publication Date
CN115658511A true CN115658511A (en) 2023-01-31
CN115658511B CN115658511B (en) 2023-08-29

Family

ID=84993275

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211324987.3A Active CN115658511B (en) 2022-10-27 2022-10-27 Method and system for monitoring execution behavior of source code

Country Status (1)

Country Link
CN (1) CN115658511B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130042221A1 (en) * 2011-08-12 2013-02-14 Tata Consultancy Services Limited System and method for automatic impact variable analysis and field expansion in mainframe systems
CN104331364A (en) * 2014-10-21 2015-02-04 江苏通付盾信息科技有限公司 Detection method for mobile-platform application software
CN106557396A (en) * 2015-09-25 2017-04-05 北京计算机技术及应用研究所 Virtual machine program running state monitoring method based on qemu
CN109086193A (en) * 2017-06-13 2018-12-25 阿里巴巴集团控股有限公司 Monitoring method, apparatus and system
CN109739512A (en) * 2018-12-28 2019-05-10 江苏极光网络技术有限公司 A kind of analytical type language text formula analysis conversion method

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130042221A1 (en) * 2011-08-12 2013-02-14 Tata Consultancy Services Limited System and method for automatic impact variable analysis and field expansion in mainframe systems
CN104331364A (en) * 2014-10-21 2015-02-04 江苏通付盾信息科技有限公司 Detection method for mobile-platform application software
CN106557396A (en) * 2015-09-25 2017-04-05 北京计算机技术及应用研究所 Virtual machine program running state monitoring method based on qemu
CN109086193A (en) * 2017-06-13 2018-12-25 阿里巴巴集团控股有限公司 Monitoring method, apparatus and system
CN109739512A (en) * 2018-12-28 2019-05-10 江苏极光网络技术有限公司 A kind of analytical type language text formula analysis conversion method

Also Published As

Publication number Publication date
CN115658511B (en) 2023-08-29

Similar Documents

Publication Publication Date Title
Konrad et al. Real-time specification patterns
EP3005089B1 (en) Resolution of textual code in a graphical hierarchical model of a technical computing environment
US6959432B2 (en) Process and system for developing mathematically validated object-oriented software
Collier et al. Reflecting on agent programming with AgentSpeak (L)
Avanzini et al. TcT: Tyrolean complexity tool
US20200210158A1 (en) Automated or machine-enhanced source code debugging
Śmiałek et al. From Requirements to Java in a Snap
US11921621B2 (en) System and method for improved unit test creation
Mooney Issues in the specification and measurement of software portability
US20240086310A1 (en) What-if analysis for notebooks
Sheriyev et al. Automation of HCI engineering processes: System architecture and knowledge representation
Aucher Dynamic epistemic logic in update logic
Gotti et al. IFVM Bridge: A Model Driven IFML Execution.
CN115658511A (en) Method and system for monitoring execution behavior of source code
US11429358B2 (en) Representing asynchronous state machine in intermediate code
CN113392003A (en) Evaluation method and device of programming code
Darvas et al. What is special about PLC software model checking
Arruda et al. Automation and consistency analysis of test cases written in natural language: An industrial context
Sarstedt et al. A New Approach to Combine Models and Code in Model Driven Development.
Parizi et al. Declarative Preferences in Reactive BDI Agents
Darvas et al. JACoW: What is special about PLC software model checking?
US20130007763A1 (en) Generating method, scheduling method, computer product, generating apparatus, and information processing apparatus
McCabe Towards the Humanisation of Programming Tool Interactions
JPH0689177A (en) Method and system for rewinding state of expert system
McGehearty et al. Execution of common lisp programs in a parallel environment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant