[go: up one dir, main page]

CN102214142A - Instrumentation method for traceless manageable source code manually-defined mark - Google Patents

Instrumentation method for traceless manageable source code manually-defined mark Download PDF

Info

Publication number
CN102214142A
CN102214142A CN2011101985469A CN201110198546A CN102214142A CN 102214142 A CN102214142 A CN 102214142A CN 2011101985469 A CN2011101985469 A CN 2011101985469A CN 201110198546 A CN201110198546 A CN 201110198546A CN 102214142 A CN102214142 A CN 102214142A
Authority
CN
China
Prior art keywords
pitching pile
pitching
source file
code
point
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.)
Pending
Application number
CN2011101985469A
Other languages
Chinese (zh)
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.)
Nanjing University
Original Assignee
Nanjing University
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 Nanjing University filed Critical Nanjing University
Priority to CN2011101985469A priority Critical patent/CN102214142A/en
Publication of CN102214142A publication Critical patent/CN102214142A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Stored Programmes (AREA)

Abstract

一种无痕可管理的源代码手动定义标志插桩方法,包括步骤:10:打开一个工程;11:通过在源代码编辑器上定义插桩标志,进而在整个工程中定义插桩点;12:审查所有插桩点的定义:若发现带有错误的插桩点,则进入步骤13对其进行修改;没有发现带有错误的插桩点,则直接进入步骤14;13:修改插桩的定义至正确;14:将插桩点与原源文件合并生成新源文件;15:对新源文件进行编译生成字节码文件。该方法主要特点为插桩代码可视化、集中管理插入代码、插桩过程无痕化、插桩点自动化定位、自动插桩可扩展、自动插桩高效性。

A traceless and manageable source code manual definition flag insertion method, including steps: 10: open a project; 11: define the insertion point in the entire project by defining the insertion flag on the source code editor; 12 : Review the definitions of all insertion points: if any insertion points with errors are found, proceed to step 13 to modify them; if no insertion points with errors are found, proceed directly to step 14; 13: Modify the insertion points The definition is correct; 14: Merge the instrumentation point with the original source file to generate a new source file; 15: Compile the new source file to generate a bytecode file. The main features of this method are visualization of the instrumentation code, centralized management of the insertion code, traceless instrumentation process, automatic positioning of instrumentation points, automatic instrumentation scalability, and automatic instrumentation efficiency.

Description

无痕可管理的源代码手动定义标志插桩方法Untraceable and manageable source code Manual definition of flag instrumentation method

技术领域technical field

本发明涉及计算机程序动态分析,主要涉及一种无痕可管理的源代码手动定义标志插桩方法。The invention relates to dynamic analysis of computer programs, and mainly relates to a traceless and manageable source code manual definition flag insertion method.

背景技术Background technique

程序分析通常利用静态程序分析和动态程序分析对程序行为进行自动分析,进而提高软件质量。动态程序分析常借助于插桩方法来收集程序动态运行行为,某些与运行环境相关的程序行为只能通过插桩来收集,而静态程序分析无法进行分析。软件开发过程中,代码审查者在代码编写阶段完成后使用源代码插桩方法对代码进行审查,通常审查者拥有阅读源代码权限但不便对代码进行修改。通过对程序运行行为的分析尽早发现代码中的错误,进而提高软件质量。源代码插桩能够充分地利用程序语义、可视化地显示插桩代码、并且不会提高代码逻辑复杂性。Program analysis usually uses static program analysis and dynamic program analysis to automatically analyze program behavior, thereby improving software quality. Dynamic program analysis often collects the dynamic running behavior of programs by means of instrumentation. Some program behaviors related to the operating environment can only be collected through instrumentation, but static program analysis cannot be analyzed. During the software development process, the code reviewer uses the source code instrumentation method to review the code after the code writing stage is completed. Usually, the reviewer has the right to read the source code but is inconvenient to modify the code. By analyzing the running behavior of the program, the errors in the code can be found as early as possible, so as to improve the software quality. Source code instrumentation can make full use of program semantics, visually display instrumented code, and will not increase the complexity of code logic.

程序插桩技术,是在保证被测程序原有逻辑完整性的基础上在程序中插入一些探针,通过探针的执行并抛出程序运行的特征数据,通过对这些数据的分析,可以获得程序的控制流和数据流信息,进而得到逻辑覆盖等动态信息,从而实现测试目的的方法。由于程序插桩技术是在被测程序中插入探针,然后通过探针的执行来获得程序的控制流和数据流信息,以此来实现测试的目的。因此,根据探针插入的时间可以分为目标代码插桩和源代码插桩。The program instrumentation technology is to insert some probes into the program on the basis of ensuring the original logical integrity of the program under test, and throw out the characteristic data of the program operation through the execution of the probes. Through the analysis of these data, we can obtain The control flow and data flow information of the program, and then obtain dynamic information such as logic coverage, so as to achieve the method of testing. The program instrumentation technology inserts probes into the program under test, and then obtains the control flow and data flow information of the program through the execution of the probes, so as to achieve the purpose of testing. Therefore, according to the time of probe insertion, it can be divided into object code instrumentation and source code instrumentation.

现有插桩方法主要包括断言机制、字节码插桩、面向方面插桩等三类方法。断言机制直接在写源文件中添加插桩代码,将会降低代码阅读性。字节码插桩则直接对字节码文件进行修改,被插字节码的源代码无法可视化,且无法保证代码插入过程的正确性。面向方面插桩在程序纵向继承关系的基础上增加了横向方面关系,增加了程序的逻辑复杂性。Existing instrumentation methods mainly include three types of methods: assertion mechanism, bytecode instrumentation, and aspect-oriented instrumentation. The assertion mechanism directly adds instrumentation code to the source file, which will reduce the readability of the code. Bytecode instrumentation directly modifies the bytecode file, the source code of the inserted bytecode cannot be visualized, and the correctness of the code insertion process cannot be guaranteed. Aspect-oriented stubbing increases the horizontal aspect relationship on the basis of the vertical inheritance relationship of the program, which increases the logical complexity of the program.

目前插桩技术主要存在插桩点及其代码可视化、被插代码管理、插桩点自动定位、自动插桩性能较低的问题。At present, the instrumentation technology mainly has the problems of the visualization of the instrumentation point and its code, the management of the inserted code, the automatic positioning of the instrumentation point, and the low performance of the automatic instrumentation.

发明内容Contents of the invention

鉴于上述问题,本发明旨在提供一个源代码插桩方法,该方法不仅支持手动插桩,并且支持批量自动插桩。其主要特点有插桩代码可视化、插入代码集中管理和插桩过程无痕化等。In view of the above problems, the present invention aims to provide a source code insertion method, which not only supports manual insertion, but also supports batch automatic insertion. Its main features include visualization of the instrumentation code, centralized management of the insertion code, and traceless process of instrumentation.

本发明是通过以下技术方案实现的:The present invention is achieved through the following technical solutions:

一种对源代码进行无痕可管理的无痕可管理的源代码手动定义标志插桩方法,步骤包括:A traceless and manageable source code manual definition flag insertion method for source code, the steps include:

步骤10:打开一个工程;Step 10: Open a project;

步骤11:通过在源代码编辑器上定义插桩标志,进而在整个工程中定义插桩点;Step 11: Define the insertion point in the whole project by defining the insertion flag on the source code editor;

步骤12:审查所有插桩点的定义:若发现带有错误的插桩点,则进入步骤13对其进行修改;没有发现带有错误的插桩点,则直接进入步骤14;Step 12: Review the definitions of all insertion points: if any insertion points with errors are found, proceed to step 13 to modify them; if no insertion points with errors are found, proceed directly to step 14;

步骤13:修改插桩的定义直至正确;Step 13: Modify the definition of stub until it is correct;

步骤14:将插桩点与原源文件合并生成新源文件;Step 14: Merge the insertion point with the original source file to generate a new source file;

步骤15:对新源文件进行编译生成字节码文件。Step 15: Compile the new source file to generate a bytecode file.

所述步骤11)中,插桩点定义的步骤包括:In said step 11), the steps of stake point definition include:

步骤20:打开一个工程;Step 20: Open a project;

步骤21:判断是否需要在工程中的源文件上定义插桩点,如果是,则跳转到步骤22,如果不是,则跳转到步骤25;Step 21: Determine whether it is necessary to define a stub point on the source file in the project, if yes, go to step 22, if not, go to step 25;

步骤22:选取所需插桩的源文件,用源代码编辑器打开该源文件;Step 22: Select the source file to be inserted, and open the source file with a source code editor;

步骤23:先定位到插桩点所在代码行,并定义一个标志便于能够及时识别,再在该标志上定义相应的插桩代码;Step 23: Locate the line of code where the insertion point is located first, and define a symbol for timely identification, and then define the corresponding insertion code on the symbol;

步骤24:如果需要在本源文件中继续定义新的插桩点,则跳转到步骤21,如果不需要,则进入步骤25;Step 24: If you need to continue to define a new insertion point in this source file, go to step 21, if not, go to step 25;

步骤25:结束本次插桩定义。Step 25: End this instrumentation definition.

所述步骤13中,可修改信息包括:插桩点所包含的插桩代码和插桩点是否需要编译到字节码文件。In step 13, the modifiable information includes: the instrumentation code included in the instrumentation point and whether the instrumentation point needs to be compiled into a bytecode file.

所述步骤14中,手动插桩中原源文件与插桩点合并生成新源文件的步骤包括:In the step 14, the steps of merging the original source file and the insertion point in the manual insertion to generate a new source file include:

步骤30:原源文件与插桩点合并的开始,此时各个源文件中的插桩点已经定义好;Step 30: the start of merging the original source file and the insertion point, at this time the insertion point in each source file has been defined;

步骤31:先将工程中所有源文件查找出来,并从中选择一个源文件;Step 31: Find out all the source files in the project first, and select a source file from them;

步骤32:查看所选源文件中是否包含插桩点,若有则进入步骤33,若没有则跳转到步骤36;Step 32: Check whether the selected source file contains an insertion point, if yes, go to step 33, if not, go to step 36;

步骤33:首先将原源文件备份,然后查找出源文件中所有插桩点;Step 33: first back up the original source file, and then find out all the insertion points in the source file;

步骤34:对查找出来的所有插桩点进行排序,按照行号进行排序;Step 34: Sort all the found insertion points according to the row number;

步骤35:逐行读取原源文件并写入一个新源文件,生成一个新源文件;Step 35: read the original source file line by line and write a new source file to generate a new source file;

步骤36:查看是否还有源文件需要合并插桩点,如果有,则返回步骤31,如果没有,则进入步骤37;Step 36: Check whether there are still source files that need to be merged with insertion points, if yes, return to step 31, if not, then go to step 37;

步骤37:所有源文件都已经合并过插桩点,结束。Step 37: All source files have been merged with the insertion point, and the end.

所述步骤34中,排序是按照行号由小到大进行排序;对于行号的相同的插桩点,行首类型插桩点排在行末类型插桩点之前。In the step 34, the sorting is performed according to the row number from small to large; for the same insertion point with the same row number, the insertion point of the first type of line is arranged before the insertion point of the end type.

所述步骤35中,逐行读取原源文件,从前往后遍历所有插桩点;在逐行读取源文件时:In the step 35, the original source file is read line by line, and all insertion points are traversed from front to back; when the source file is read line by line:

a)如果行号与插桩点行号不同,则直接写入新源文件中;a) If the line number is different from the line number of the insertion point, write it directly into the new source file;

b)如果行号与插桩点行号相同,此时:b) If the line number is the same as the line number of the insertion point, then:

b.1)若插桩类型是行首类型,则先向新源文件写入插桩代码,再写入原源文件代码,b.1) If the instrumentation type is the line header type, first write the instrumentation code to the new source file, and then write the original source file code,

b.2)若插桩类型是行末类型,则先向新源文件写入原源文件代码,再写入插桩代码;b.2) If the stub type is the end-of-line type, first write the code of the original source file to the new source file, and then write the stub code;

在逐行读取源文件时,取出下一个插桩点,直到所有插桩点全部合并到原源文件中。When the source file is read line by line, the next insertion point is taken out until all the insertion points are merged into the original source file.

所述插桩点管理器,通过查询显示工程中所有插桩点信息、修改插桩点的信息、插桩点分类及过滤、插桩点定位到源文件中具体某一行和插桩点的删除。The insertion point manager displays the information of all insertion points in the project by querying, modifying the information of the insertion points, classifying and filtering the insertion points, locating the insertion points to a specific line in the source file and deleting the insertion points .

所述插桩标志显示在源代码编辑器的左侧垂直标尺上,以不同图标形式表明该行已植入插桩代码以及插桩类型;插桩点的代码可由用户自定义。The instrumentation mark is displayed on the left vertical scale of the source code editor, and different icons are used to indicate that the line has been implanted with instrumentation code and instrumentation type; the code of the instrumentation point can be customized by the user.

所有插桩标志均随工程进行:插桩标志在工程关闭后自动进行保存,在下次打开工程时插桩标志依旧能够在源代码编辑器的标尺上进行还原。All instrumentation flags are carried out with the project: the instrumentation flags are automatically saved after the project is closed, and the instrumentation flags can still be restored on the ruler of the source code editor when the project is opened next time.

本方法借助插桩点集中管理器完成,插桩点集中管理器的功能包括:查询并显示工程中所有插桩点信息、修改插桩点的信息、插桩点分类及过滤显示、插桩点定位到文件中具体某一行和插桩点的删除。This method is completed with the help of the centralized manager of the insertion points. The functions of the centralized manager of the insertion points include: querying and displaying the information of all the insertion points in the project, modifying the information of the insertion points, classifying and filtering the insertion points, and displaying the insertion points. Locate to a specific line in the file and delete the insertion point.

手动定义标志的插桩方案是按行进行插桩的,每行最多包含两种插桩标志类型,一种是在行首植入插桩代码,另一种是在行末植入插桩代码。在源代码编辑器上,定义插桩点的行会左侧垂直标尺上显示一个标志,表明该行已被植入插桩代码同时指明插桩类型。每个插桩点代码均可由用户自定义,并且所有插桩标志均随工程进行持久化。The instrumentation scheme of manually defining flags is instrumented by line, and each line contains at most two types of instrumentation flags, one is to insert instrumentation code at the beginning of the line, and the other is to insert instrumentation code at the end of the line. On the source code editor, the line that defines the instrumentation point will display a flag on the left vertical ruler, indicating that the line has been implanted with instrumentation code and indicating the instrumentation type. Each instrumentation point code can be customized by the user, and all instrumentation flags are persisted with the project.

插桩标志持久化是指插桩标志在工程关闭后自动进行保存,在下次打开工程时插桩标志依旧能够在源代码编辑器的标尺上进行还原。The persistence of the instrumentation flag means that the instrumentation flag is automatically saved after the project is closed, and the instrumentation flag can still be restored on the ruler of the source code editor when the project is opened next time.

所有插桩点在定义完后可以进行集中管理,插桩点的集中管理部分包括:查询并显示工程中所有插桩点信息、修改插桩点信息、插桩点分类及过滤显示、插桩点定位到文件中具体某一行、插桩点的删除。All insertion points can be managed centrally after definition. The centralized management of insertion points includes: query and display all insertion point information in the project, modify insertion point information, classification and filter display of insertion points, insertion point Locate to a specific line in the file and delete the insertion point.

进一步的,查询显示工程中所有插桩点信息,包括查询文件中所有行首和行末插桩点,其所显示的信息包括:插桩点所属工程名、所属文件路径、所在行号、所需植入的代码以及是否需要合并字节码文件中。Further, the query displays information about all insertion points in the project, including all insertion points at the beginning and end of the line in the query file. The displayed information includes: the name of the project to which the insertion point belongs, the path of the file to which it belongs, the line number where it is located, the required The implanted code and whether it needs to be merged into the bytecode file.

步骤13中,修改插桩点信息,包括编辑插桩点中插桩代码以及是否需要合并到字节码文件的选项。插桩分类可按工程名、文件名、插桩类型、合并选择进行排序,排序后同一类别的插桩点集中显示在一起。按工程名进行排序时,工程名相同的插桩点将显示在一起,其它几种分类方式与此类似。In step 13, modify the instrumentation point information, including editing the instrumentation code in the instrumentation point and whether it needs to be merged into the bytecode file. The instrumentation classification can be sorted by project name, file name, instrumentation type, and merge selection. After sorting, the instrumentation points of the same category are displayed together. When sorting by project name, the insertion points with the same project name will be displayed together, and the other classification methods are similar.

插桩点过滤支持在插桩点管理界面显示少量必须的插桩点,避免因插桩点数目巨大而增大用户编辑难度进而提高用户体验指数。插桩点过滤利用正则表达式对工程名及文件名进行过滤,进而使得过滤所得工程(或文件)中的插桩点保留下来并显示在插桩管理界面上。过滤时先查找哪些工程(或文件)名称与正则表达式相匹配,将与之匹配的工程(或文件)保存下来。接着将保留下来工程(或文件)中的插桩点查找出来并显示到插桩管理界面上。Insertion point filtering supports displaying a small number of necessary insertion points on the insertion point management interface, which avoids increasing the difficulty of user editing due to the huge number of insertion points and improves the user experience index. Insertion point filtering utilizes regular expressions to filter project names and file names, so that the insertion points in the filtered project (or file) are retained and displayed on the insertion management interface. When filtering, first find which project (or file) names match the regular expression, and save the matched projects (or files). Then find out the insertion points in the preserved project (or file) and display them on the insertion management interface.

插桩点定位能够方便地定位到插桩点所在文件,使得用户能够及时查看插桩点所处环境,进而分析该部分程序的功能。The location of the insertion point can easily locate the file where the insertion point is located, so that the user can check the environment of the insertion point in time, and then analyze the function of this part of the program.

插桩点删除功能支持在插桩点管理部分统一删除指定(或所有)的插桩点,避免了删除插桩前必须定位到其所在文件的问题,进而提高了软件的易用性。The insertion point deletion function supports the unified deletion of specified (or all) insertion points in the insertion point management part, avoiding the problem that the file where the insertion point must be located before deleting the insertion point, and thus improving the usability of the software.

将定义好的插桩点与原源文件合并成新源文件的过程是对工程中的每一个源文件单独进行操作。对于某具体源文件而言,先将该文件拷贝备份,然后获取该文件中的所有插桩点,按照从行号从小到大进行排序。接着按行读取文件并写入到新文件中,当行号与某一个插桩点行号相等时,根据插桩类型将该插桩点代码和原文件代码写到新文件中然后读下一行。代码写入顺序由插桩类型决定,若是行首插桩类型则先写插桩代码再写原文件代码,若是行末插桩类型则先写原文件代码再写插桩代码。按上述方法逐源文件进行操作,将所有插桩点合并到相应的源文件中并生成新源文件。The process of merging the defined insertion point and the original source file into a new source file is to operate each source file in the project independently. For a specific source file, first copy and back up the file, and then obtain all the insertion points in the file, and sort them from small to large line numbers. Then read the file by line and write it into a new file. When the line number is equal to the line number of a certain insertion point, write the insertion point code and the original file code into the new file according to the insertion type and then read the next line. . The code writing order is determined by the instrumentation type. If the instrumentation type is at the beginning of the line, write the instrumentation code first and then write the original file code. If it is the end-of-line instrumentation type, write the original file code first and then write the instrumentation code. Operate source file by source file by the above method, merge all instrumentation points into the corresponding source file and generate a new source file.

对新源文件进行编译产生新的字节码并运行的过程中,利用事先的备份还原源文件,从合并插桩点到编译并运行字节码文件是一个完整的自动过程。对于外部而言,原源文件未被改变且结果为插桩代码的执行结果,整个过程是一个无痕过程。In the process of compiling a new source file to generate a new bytecode and running it, use the previous backup to restore the source file, from merging instrumentation points to compiling and running the bytecode file is a complete automatic process. For the outside, the original source file has not been changed and the result is the execution result of the instrumented code, and the whole process is a traceless process.

本发明利用标志保存插桩代码,并将插桩代码与原有代码区分开来,提高了插桩代码可视化能力。标志可以在插桩位置显示相应的插桩代码,且不会干扰原文件编辑工作。同时可以集中管理所有插桩标志,进而提高插桩代码的管理能力。为提高自动插桩的效率,本发明还设计了文件过滤和元插桩类型重用框架。以上所有操作均在后台完成且不修改用户原文件,整个过程是一个无痕过程。The invention saves the post-inserting code by using the mark, distinguishes the post-inserting code from the original code, and improves the visualization ability of the post-inserting code. The flag can display the corresponding instrumentation code at the instrumentation position without interfering with the editing work of the original file. At the same time, all instrumentation flags can be managed centrally, thereby improving the management ability of instrumentation codes. In order to improve the efficiency of automatic pile insertion, the present invention also designs a framework for file filtering and meta-instrumentation type reuse. All the above operations are completed in the background without modifying the user's original files, and the whole process is a traceless process.

附图内容Attached content

图1为手动插桩的完整流程图。Figure 1 is a complete flow chart of manual stake insertion.

图2为手动插桩插桩点定义的流程图。Fig. 2 is a flow chart of manual stake insertion point definition.

图3为手动插桩中原源文件与插桩点合并的流程图。Fig. 3 is a flow chart of merging original source files and insertion points in manual insertion.

具体实施方式Detailed ways

下面通过附图对本发明的技术方案做进一步的详细描述。The technical scheme of the present invention will be described in further detail below with reference to the accompanying drawings.

本发明主要包含两种类型插桩方案:一种是手动定义标志插桩类型,另一种是不同应用类型自动插桩。The present invention mainly includes two types of stake insertion schemes: one is manual definition of sign insertion type, and the other is automatic insertion of different application types.

手动插桩方案支持分析人员根据分析需要灵活地在整个工程中定义插桩点,并进行插桩点的管理。所植入的插桩代码不会破坏原有代码,最终可根据需要选择几个插桩点与原文件一起运行。整个手动插桩完整流程图如图1所示,包括如下步骤:The manual insertion scheme supports analysts to flexibly define and manage insertion points throughout the project according to analysis needs. The implanted instrumentation code will not destroy the original code, and finally several instrumentation points can be selected to run together with the original file according to the needs. The complete flow chart of manual pile insertion is shown in Figure 1, including the following steps:

步骤10:整个手动插桩过程的开始,此时打开一个工程并准备通过插桩对其进行分析;Step 10: The start of the entire manual instrumentation process. At this time, open a project and prepare to analyze it through instrumentation;

步骤11:通过在源代码编辑器上定义标志进而在整个工程定义插桩点;Step 11: Define the instrumentation point throughout the project by defining the flag on the source code editor;

步骤12:定义完插桩点后审查一下所有插桩点的定义,若发现带有错误的插桩点,则进入步骤13对其进行修改,否则进入步骤14;Step 12: After defining the insertion point, review the definitions of all insertion points. If you find an incorrect insertion point, go to step 13 to modify it, otherwise go to step 14;

步骤13:修改插桩的定义,可修改信息主要有两种:其一是插桩点所包含的插桩代码,其二是插桩点是否需要编译到字节码文件;Step 13: Modify the definition of the instrumentation. There are two main types of modifiable information: one is the instrumentation code contained in the instrumentation point, and the other is whether the instrumentation point needs to be compiled into a bytecode file;

步骤14:在完成插桩定义以及没有插桩点需要修改时,将插桩点与原源文件合并并产生新文件;Step 14: When the insertion definition is completed and no insertion point needs to be modified, merge the insertion point with the original source file and generate a new file;

步骤15:对所产生的新源文件进行编译进而产生字节码文件;Step 15: Compile the generated new source file to generate a bytecode file;

上述手动插桩点定义流程利用标志保存资源信息,标志须和工程一起持久化便于以后使用,整个手动插桩插桩点定义的流程图如图2所示,包括如下步骤:The above-mentioned manual insertion point definition process uses flags to save resource information, and the logo must be persisted with the project for future use. The flow chart of the entire manual insertion point definition is shown in Figure 2, including the following steps:

步骤20:整个手动插桩插桩点定义的开始,此时需打开一个工程并准备定义插桩点;Step 20: The start of the definition of the entire manual insertion point. At this time, a project needs to be opened and ready to define the insertion point;

步骤21:判断是否需要在文件上定义插桩点,如果是则跳转到步骤22,否则跳转到步骤25;Step 21: Determine whether an insertion point needs to be defined on the file, if so, go to step 22, otherwise go to step 25;

步骤22:选取所需插桩的文件,并用源代码编辑器打开该文件;Step 22: Select the file to be inserted, and open the file with a source code editor;

步骤23:手动插桩须先定位到插桩点所在代码行,并定义一个标志以便以后能够及时识别,在该标志上定义相应的插桩代码;Step 23: For manual insertion, you must first locate the line of code where the insertion point is located, and define a sign so that it can be recognized in time in the future, and define the corresponding insertion code on the sign;

步骤24:判断是否还需在本文件定义新的插桩点,如果需要定义新的插桩点则跳转到步骤21,否则进入步骤25;Step 24: Determine whether a new insertion point needs to be defined in this document. If a new insertion point needs to be defined, go to step 21; otherwise, go to step 25;

步骤25:所有插桩点定义已经完成,结束本次插桩定义;Step 25: The definitions of all the insertion points have been completed, and the definition of this insertion is ended;

在定义好插桩点后,为进一步提高插桩点的正确性,本方案提供了插桩点管理器。通过查询并显示工程中所有插桩点信息、修改插桩点的信息、插桩点分类及过滤显示、插桩点定位到文件中具体某一行、插桩点的删除五种操作进而提高插桩点集中管理能力。After the insertion point is defined, in order to further improve the accuracy of the insertion point, this solution provides an insertion point manager. By querying and displaying the information of all the insertion points in the project, modifying the information of the insertion points, classifying and filtering the insertion points, locating the insertion points to a specific line in the file, and deleting the insertion points to improve the insertion point centralized management capabilities.

所述原源文件与插桩点合并的流程是在定义完插桩点后进行的,该操作将文件中需编译的插桩点与原文件进行合并生成新的文件。手动插桩中原源文件与插桩点合并的流程图如图3所示,包括如下步骤:The process of merging the original source file with the insertion point is performed after the insertion point is defined. This operation merges the insertion point to be compiled in the file with the original file to generate a new file. The flow chart of merging the original source file and the insertion point in manual insertion is shown in Figure 3, including the following steps:

步骤30:原文件与插桩点合并的开始部分,此时各个文件中的插桩点已经定义好,下面将对每个文件进行插桩点合并操作;Step 30: The initial part of merging the original file with the insertion point. At this time, the insertion point in each file has been defined. Next, the insertion point will be merged for each file;

步骤31:先将整个工程中所有源文件查找出来,并从中选择一个文件;Step 31: Find out all the source files in the whole project first, and select a file from them;

步骤32:查看所选文件中是否包含插桩点,若有则进入步骤33,否则跳转到步骤36;Step 32: Check whether the selected file contains an insertion point, if so, go to step 33, otherwise go to step 36;

步骤33:若文件包含插桩点,则首先将原文件备份然后查找出文件中所有插桩点;Step 33: If the file contains an insertion point, first back up the original file and then find out all the insertion points in the file;

步骤34:对查找出来的所有插桩点进行排序,按照行号由小到大进行排序,行号的相同的插桩点,行首类型插桩点排在行末类型插桩点之前;Step 34: Sort all the found insertion points, and sort them according to the line number from small to large. For the insertion points with the same line number, the insertion points of the first type of line are arranged before the insertion points of the end type;

步骤35:逐行读取原文件并写入一个新文件,同时从前往后遍历所有插桩点。在逐行读取文件时,如果行号与插桩点不同则直接写入新文件中;如果行号与插桩点行号相同时,此时若插桩类型是行首类型则先向新文件写入插桩代码再写入原文件代码,若插桩类型是行末类型则先向新文件写入原文件代码再写入插桩代码。同时将取出下一个插桩点,直到所有插桩点全部合并到原文件中。Step 35: Read the original file line by line and write a new file, while traversing all the insertion points from front to back. When reading a file line by line, if the line number is different from the insertion point, it will be directly written into the new file; The instrumentation code is written into the file and then the original file code. If the instrumentation type is the end-of-line type, the original file code is first written to the new file and then the instrumentation code is written. At the same time, the next instrumentation point will be fetched until all instrumentation points are merged into the original file.

步骤36:查看是否还有文件需要合并插桩点;Step 36: Check whether there are still files that need to be merged with the insertion point;

步骤37:所有文件都已经合并过插桩点。Step 37: All files have been merged with instrumentation points.

在本方案中,逐个文件进行插桩点合并后将会对新文件进行编译同时产生新的字节码。运行新字节码,所得结果即为插桩点与原代码共同执行结果。In this solution, after the instrumentation points are merged one by one, the new file will be compiled and a new bytecode will be generated. Run the new bytecode, and the result is the joint execution result of the instrumentation point and the original code.

自动插桩方案是针对某具体应用类型进行的,利用抽象语法树的结构匹配进行插桩点的自动定位,插桩点自动定位自动插桩部分的重点。定位后将代码片段的语法树结构添加到原文件的语法树结构中的相应位置,将产生的新语法树转换成源代码并编译成字节码,所得字节码可以直接进行运行。自动插桩的完整的流程图如图4所示,包括如下步骤:The automatic insertion scheme is carried out for a specific application type, using the structure matching of the abstract syntax tree to automatically locate the insertion point, and the insertion point automatically locates the focus of the automatic insertion part. After positioning, add the syntax tree structure of the code fragment to the corresponding position in the syntax tree structure of the original file, convert the generated new syntax tree into source code and compile it into bytecode, and the resulting bytecode can be run directly. The complete flowchart of automatic pile insertion is shown in Figure 4, including the following steps:

步骤40:整个自动插桩过程的开始,此时打开一个工程并准备通过插桩对其进行分析;Step 40: the start of the entire automatic pile insertion process, at this time open a project and prepare to analyze it through pile insertion;

步骤41:定义一个文件过滤器,文件过滤器使用正则表达式对所需插桩的工程(包、文件、方法)进行匹配,与之匹配的则将保留下来;Step 41: Define a file filter. The file filter uses regular expressions to match the required instrumentation projects (packages, files, methods), and the matched ones will be retained;

步骤42:接着使用上述定义的过滤器对被插桩的文件进行过滤,利用分析者对工程文件已有知识提高了自动插桩性能;Step 42: Then use the filter defined above to filter the inserted files, and use the analyst's existing knowledge of the project files to improve the automatic insertion performance;

步骤43:选择所需插桩的类型,定义相关类型所需插桩的代码;Step 43: Select the type of stub required, and define the code of the stub required for the relevant type;

步骤44:接着利用语法树结构匹配根据不同的插桩类型进行插桩点的位置定位,并在相应位置插入代码最终产生一个新的文件;Step 44: Then use syntax tree structure matching to locate the position of the insertion point according to different insertion types, and insert the code at the corresponding position to finally generate a new file;

步骤45:对上述新的文件进行编译产生新的可执行字节码文件,并将这些文件保存起来;Step 45: Compile the above-mentioned new files to generate new executable bytecode files, and save these files;

步骤46:最终产生可执行文件,整个过程将不会修改原有文件信息,整个过程是一个无痕的过程。Step 46: Finally, an executable file is generated, and the original file information will not be modified in the whole process, and the whole process is a traceless process.

最后应当说明的是:以上步骤仅用于说明本发明的技术方案而非对其限制。尽管上述步骤对本发明进行了详细的说明,相关领域的技术人员应当理解,依然可以对本发明的具体技术进行修改或者对部分技术进行等同替换;而不脱离本发明技术方案的精神,其均应涵盖在Finally, it should be noted that the above steps are only used to illustrate the technical solution of the present invention rather than limit it. Although the above steps have described the present invention in detail, those skilled in the art should understand that the specific technologies of the present invention can still be modified or some technologies can be equivalently replaced; without departing from the spirit of the technical solutions of the present invention, they should cover exist

Claims (9)

1. seamless manageable source code manual definition sign pile pitching method is characterized in that comprising step:
Step 10: open an engineering;
Step 11: by at source code editing machine definition pitching pile sign, and then in whole engineering definition pitching pile point;
Step 12: examine the definition of all pitching pile points:, then enter step 13 it is made amendment if find to have the pitching pile point of mistake; Do not have to find to have the pitching pile point of mistake, then directly enter step 14;
Step 13: revise the definition of pitching pile to correct;
Step 14: pitching pile point and former source file are merged the new source file of generation;
Step 15: new source file is compiled the generation byte code files.
2. seamless manageable source code manual definition sign pile pitching method according to claim 1 is characterized in that in the described step 11), and the step of pitching pile point definition comprises:
Step 20: open an engineering;
Step 21: judge whether and need define the pitching pile point on the source file in engineering, if, then jump to step 22, if not, then jump to step 25;
Step 22: choose the source file of required pitching pile, open this source file with the source code editing machine;
Step 23: navigate to earlier pitching pile point place code line, and define a sign and be convenient to and in time identify, again at the corresponding pitching pile code of this sign definition;
Step 24: if need to then jump to step 21 at the new pitching pile point of the continuous definition of this source file relaying, if do not need, then enter step 25;
Step 25: finish this pitching pile definition.
3. seamless manageable source code manual definition sign pile pitching method according to claim 1 is characterized in that in the described step 13 can modification information comprise: whether pitching pile code and pitching pile point that pitching pile point comprised need to be compiled into byte code files.
4. according to claim 1 or 2 or 3 described seamless manageable source code manual definition sign pile pitching methods, it is characterized in that in the described step 14 that manually the step of the new source file of pitching pile Central Plains source file and pitching pile point merging generation comprises:
Step 30: the beginning that former source file and pitching pile point merge, the pitching pile point in each source file defines at this moment;
Step 31: earlier all source files in the engineering are found out, and therefrom select a source file;
Step 32: check whether comprise the pitching pile point in the selected source file, then enter step 33, if then do not jump to step 36 if having;
Step 33: at first with former source file backup, find out then all pitching pile points in the source file;
Step 34: all pitching pile points that find out are sorted, sort according to line number;
Step 35: read former source file line by line and write a new source file, generate a new source file;
Step 36: check whether also have source file need merge the pitching pile point,, then to return step 31,, then to enter step 37 if do not have if having;
Step 37: all source files had all merged the pitching pile point, finished.
5. seamless manageable source code manual definition sign pile pitching method according to claim 4 is characterized in that in the described step 34 that ordering is to sort according to line number is ascending; For the identical pitching pile point of line number, the first type pitching pile point of row comes before the last type pitching pile point of row.
6. seamless manageable source code manual definition sign pile pitching method according to claim 4 is characterized in that reading former source file line by line in the described step 35, travels through all pitching pile points from front to back; When reading source file line by line:
If a) line number is different from pitching pile point line number, in the new source file that then writes direct;
B) if line number is identical with pitching pile point line number, at this moment:
B.1) if the pitching pile type is the first type of row, then earlier write the pitching pile code, write former source file code again to new source file,
B.2) if the pitching pile type is the last type of row, then earlier write former source file code, write the pitching pile code again to new source file;
When reading source file line by line, take out next pitching pile point, until all pitching pile points all merge in the former source file.
7. seamless manageable source code manual definition sign pile pitching method according to claim 1, it is characterized in that described pitching pile sign is presented on the left vertical scale of source code editing machine, show that with the different icons form this row implanted pitching pile code and pitching pile type; The code of pitching pile point can be by User Defined.
8. seamless manageable source code manual definition sign pile pitching method according to claim 7, it is characterized in that all pitching pile signs all carry out with engineering: the pitching pile sign is preserved after engineering is closed automatically, and the pitching pile sign still can reduce on the scale of source code editing machine when opening engineering next time.
9. seamless manageable source code manual definition sign pile pitching method according to claim 1, it is characterized in that this method concentrates manager to finish by pitching pile point, pitching pile point concentrates the function of manager to comprise: inquiry also shows the specifically deletion of certain delegation and pitching pile point in the file of all pitching pile dot informations in the engineering, the information of revising pitching pile point, pitching pile point classification and filtration demonstration, pitching pile point location.
CN2011101985469A 2011-07-15 2011-07-15 Instrumentation method for traceless manageable source code manually-defined mark Pending CN102214142A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2011101985469A CN102214142A (en) 2011-07-15 2011-07-15 Instrumentation method for traceless manageable source code manually-defined mark

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2011101985469A CN102214142A (en) 2011-07-15 2011-07-15 Instrumentation method for traceless manageable source code manually-defined mark

Publications (1)

Publication Number Publication Date
CN102214142A true CN102214142A (en) 2011-10-12

Family

ID=44745461

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2011101985469A Pending CN102214142A (en) 2011-07-15 2011-07-15 Instrumentation method for traceless manageable source code manually-defined mark

Country Status (1)

Country Link
CN (1) CN102214142A (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103425571A (en) * 2012-05-23 2013-12-04 腾讯科技(深圳)有限公司 Source code completeness detecting method and device
CN104487939A (en) * 2012-07-31 2015-04-01 惠普发展公司,有限责任合伙企业 Instrumented file deployment
CN104881496A (en) * 2015-06-15 2015-09-02 北京金山安全软件有限公司 File name identification and file cleaning method and device
CN105809039A (en) * 2016-03-04 2016-07-27 南京大学 Automatic repair method for buffer overflow vulnerabilities
CN105843661A (en) * 2016-03-24 2016-08-10 中国农业银行股份有限公司 Code relocating method and system oriented to host system
CN111736846A (en) * 2020-06-15 2020-10-02 南京航空航天大学 An Improved Method of Source Code Instrumentation Oriented to Dynamic Analysis
CN111913878A (en) * 2020-07-13 2020-11-10 苏州洞察云信息技术有限公司 Program analysis result-based bytecode instrumentation method, device and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7240335B2 (en) * 1996-08-27 2007-07-03 Compuware Corporation Byte code instrumentation
CN101706750A (en) * 2009-11-16 2010-05-12 西安邮电学院 Detective pole acquiring method based on embedded type simulator
CN101833500A (en) * 2010-04-07 2010-09-15 南京航空航天大学 An Agent-based Intelligent Testing Method for Embedded Software

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7240335B2 (en) * 1996-08-27 2007-07-03 Compuware Corporation Byte code instrumentation
CN101706750A (en) * 2009-11-16 2010-05-12 西安邮电学院 Detective pole acquiring method based on embedded type simulator
CN101833500A (en) * 2010-04-07 2010-09-15 南京航空航天大学 An Agent-based Intelligent Testing Method for Embedded Software

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
CHEN HUAJIE等: "An Instrumentation Tool for Program Dynamic Analysis in Java", 《2011 FIFTH INTERNATIONAL CONFERENCE ON SECURE SOFTWARE INTEGRATION AND RELIABILITY IMPROVEMENT-COMPANION》 *

Cited By (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103425571B (en) * 2012-05-23 2016-04-13 腾讯科技(深圳)有限公司 A kind of source code integrality detection method and device
CN103425571A (en) * 2012-05-23 2013-12-04 腾讯科技(深圳)有限公司 Source code completeness detecting method and device
CN104487939B (en) * 2012-07-31 2018-03-13 慧与发展有限责任合伙企业 The deployment of pitching pile file
CN104487939A (en) * 2012-07-31 2015-04-01 惠普发展公司,有限责任合伙企业 Instrumented file deployment
CN104881496A (en) * 2015-06-15 2015-09-02 北京金山安全软件有限公司 File name identification and file cleaning method and device
CN104881496B (en) * 2015-06-15 2018-12-14 北京金山安全软件有限公司 File name identification and file cleaning method and device
US10705748B2 (en) 2015-06-15 2020-07-07 Beijing Kingsoft Internet Security Software Co., Ltd. Method and device for file name identification and file cleaning
CN105809039A (en) * 2016-03-04 2016-07-27 南京大学 Automatic repair method for buffer overflow vulnerabilities
CN105809039B (en) * 2016-03-04 2018-07-27 南京大学 Buffer-overflow vulnerability self-repairing method
CN105843661A (en) * 2016-03-24 2016-08-10 中国农业银行股份有限公司 Code relocating method and system oriented to host system
CN105843661B (en) * 2016-03-24 2019-03-29 中国农业银行股份有限公司 A kind of code method for relocating and its system towards host system
CN111736846A (en) * 2020-06-15 2020-10-02 南京航空航天大学 An Improved Method of Source Code Instrumentation Oriented to Dynamic Analysis
CN111736846B (en) * 2020-06-15 2021-06-22 南京航空航天大学 An Improved Method of Source Code Instrumentation Oriented to Dynamic Analysis
CN111913878A (en) * 2020-07-13 2020-11-10 苏州洞察云信息技术有限公司 Program analysis result-based bytecode instrumentation method, device and storage medium
CN111913878B (en) * 2020-07-13 2023-09-15 苏州洞察云信息技术有限公司 Byte code instrumentation method, device and storage medium based on program analysis result

Similar Documents

Publication Publication Date Title
CN107622014B (en) Test report generation method and device, readable storage medium and computer equipment
US11514237B2 (en) Spreadsheet and method for updating same
US9971572B2 (en) GUI-driven symbol management and code generator
CN105144088B (en) Metadata is associated with and with source code based on its application and service
CN102214142A (en) Instrumentation method for traceless manageable source code manually-defined mark
US8799859B2 (en) Augmented design structure matrix visualizations for software system analysis
US9075544B2 (en) Integration and user story generation and requirements management
CN111858371A (en) Software testing method, system, storage medium and computer equipment
CN104035772A (en) Static analysis based source code multi-versionfunction call relation difference identification method
US20080313208A1 (en) Apparatus, system, and method for automated context-sensitive message organization
JP6090850B2 (en) Source program analysis system, source program analysis method and program
CN106507686A (en) Method and tool for designing software architecture of complex cyber-physical systems in different technical fields with its various software artifacts
EP3314409B1 (en) Tracing dependencies between development artifacts in a software development project
CN112527587B (en) Verification progress determining method, device, equipment and readable storage medium
CN112597750B (en) Method, editor and medium for designing dynamic detection report template online
US10157057B2 (en) Method and apparatus of segment flow trace analysis
CN113326193A (en) Applet testing method and device
JP2005122407A (en) SPECIFICATION GENERATION PROGRAM, ITS RECORDING MEDIUM, SPECIFICATION GENERATION DEVICE, AND SPECIFICATION GENERATION METHOD
CN103049504A (en) Semi-automatic instrumentation method based on source code inquiring
Nikolaidis et al. Experience with managing technical debt in scientific software development using the exa2pro framework
US9348850B1 (en) Method for large-scale data schema analysis and quality assurance
CN108628606B (en) Method and system for generating WEB network management application program of embedded equipment
Kumar et al. An empirical study of bad smell in code on maintenance effort
Liu et al. Extraction of attribute dependency graph from database applications
US20090204939A1 (en) Methods for visual representation of macros language

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C12 Rejection of a patent application after its publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20111012