CN107168870B - Method for acquiring program information during operation - Google Patents
Method for acquiring program information during operation Download PDFInfo
- Publication number
- CN107168870B CN107168870B CN201710293491.7A CN201710293491A CN107168870B CN 107168870 B CN107168870 B CN 107168870B CN 201710293491 A CN201710293491 A CN 201710293491A CN 107168870 B CN107168870 B CN 107168870B
- Authority
- CN
- China
- Prior art keywords
- program
- source program
- external
- external program
- source
- 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.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3604—Software analysis for verifying properties of programs
- G06F11/3612—Software analysis for verifying properties of programs by runtime analysis
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
- Debugging And Monitoring (AREA)
Abstract
The invention provides a method for acquiring program information during running, which comprises the following steps: step 1, creating an external program, wherein the external program comprises a method pointer registration module; step 2, starting a source program, calling a method pointer registration module of the external program through an operating system library, and transmitting a function address of the source program to the external program; and 3, the external program acquires the internal information of the source program according to the function address. The method avoids the transitional modification and intrusion of the source program, ensures the integrity of the source program and improves the analysis efficiency of the subsequent source program.
Description
Technical Field
The invention relates to the technical field of data analysis, in particular to a method for efficiently acquiring pointers, variables and the like of internal functions of a running-time program.
Background
In the existing software development, operations such as analysis and tuning of a source program are often required, and these operations all require tracking of internal information of a run-time program, for example, in a secondary development process of the source program, the source program needs to be analyzed in advance, acquisition and tracking of the internal information of the source program are involved, and in a software unit test, acquisition of the information of the source program is also involved.
The mainstream method for acquiring internal information in the current source program analysis is as follows: (1) adding a plurality of printing statements in a source program to print out local variables or global variables; (2) and other third-party tools such as gdb are used for operating the source program, so that the local variables and the global variables are observed in a single-step operation mode, and the workload is extremely large in a large project.
For the software unit test, because the internal function information is not easy to obtain, the input parameters are always preset, the expected value is given, and then the return value and the expected value of the method are compared, so that the method needs to establish a test environment, is troublesome to prepare input and output, and is not efficient.
Therefore, there is an urgent need for a method for acquiring internal data of a runtime program, which is efficient and can reduce modifications and intrusions to the source program as much as possible, and improve the analysis efficiency of the source program.
Disclosure of Invention
The technical problem to be solved by the present invention is to provide a method for acquiring runtime program information, which avoids transient modification and intrusion to a source program, ensures integrity of the source program, and improves analysis efficiency of a subsequent source program.
The invention is realized by the following steps: a run-time program information acquisition method comprises the following steps:
step 1, creating an external program, wherein the external program comprises a method pointer registration module;
step 2, starting a source program, calling a method pointer registration module of the external program through an operating system library, and transmitting a function address of the source program to the external program;
and 3, the external program acquires the internal information of the source program according to the function address.
Further, the operating system library is a DLL library of Windows or a libdl.
Further, the internal information includes a thread ID and a global variable.
The invention has the following advantages: the interface of the source program is exposed to the external program, and the external program calls the main program to obtain the internal variable, so that the internal information of the source program is further obtained, a large amount of modification operation on the source program is not needed, the integrity of the source program is ensured, the influence on an analysis result caused by modification and intrusion of the source program is greatly reduced, and the analysis efficiency of the source program is greatly improved.
Drawings
The invention will be further described with reference to the following examples with reference to the accompanying drawings.
Fig. 1 is a flowchart of a runtime program information acquisition method according to the present invention.
Detailed Description
As shown in fig. 1, the method for acquiring runtime program information of the present invention includes the following steps:
step 1, creating an external program, wherein the external program comprises a method pointer registration module and a storage module for storing internal information;
step 2, starting a source program, calling a method pointer registration module of the external program through an operating system library, and transmitting a function address of the source program to the external program, wherein the operating system library is a Windows DLL library or a Linux libdl.so library;
and 3, the external program acquires the internal information of the source program according to the function address, wherein the internal information comprises a thread ID and a global variable.
Example one
In the analysis of the lightweight thread, taking a Linux system as an example, the method for acquiring the lightweight thread ID by adopting the method of the invention comprises the following steps:
creating an external program (library) including a method pointer registration module and a variable (void) for storing a method pointer;
starting a source program, calling a method pointer registration module (register _ profile _ func) of the external program through a dl library (api of libdl. so library) at a program entry (main function), exposing a source program internal method pointer to the external program, and storing the source program internal method pointer into the variable;
after the external program obtains the internal method pointer, the internal thread ID can be called and obtained at any time according to the method pointer.
In the embodiment, the interface of the source program is exposed to the external program, the external program calls the source program to acquire the internal lightweight thread ID, the acquisition of the lightweight thread information can be completed almost without modifying the source program, and an important basis is provided for later-stage source program analysis.
Example two
In the software unit test, the method of the invention is adopted to obtain the function pointer of the source program, and then the main program function is called to execute the test, taking the software unit test under the Windows system as an example, the method specifically comprises the following steps:
writing a test code and an external program in a DLL library, wherein the external program comprises a method pointer registration module for acquiring a function address;
in a source program, obtaining the operation right of a DLL (dynamic link library), calling a method pointer registration module of the external program through the DLL, and exposing an internal function address of the source program to the external program;
and calling the source program function in a DLL library according to the function address to execute the test.
Compared with the test by acquiring the input and output parameters, the test method has the advantages that the test speed is higher, the test efficiency is greatly improved, and the test quality is improved.
In the invention, the thread ID of the source program can be obtained, and the monitoring source program can be tracked by obtaining the internal global variable and the like according to the requirement, thereby being convenient for later analysis.
According to the method and the device, the internal information of the source program is obtained in a mode that the interface of the source program is exposed to the external program and the external program calls the source program, the internal information can be obtained almost without modifying the source program, the integrity of the source program is greatly protected, the internal function obtaining efficiency is improved, and therefore the analysis efficiency of the source program is improved.
Although specific embodiments of the invention have been described above, it will be understood by those skilled in the art that the specific embodiments described are illustrative only and are not limiting upon the scope of the invention, and that equivalent modifications and variations can be made by those skilled in the art without departing from the spirit of the invention, which is to be limited only by the appended claims.
Claims (1)
1. A runtime program information acquisition method characterized by: the following process for obtaining the lightweight thread ID in the lightweight thread analysis for the Linux system is as follows:
so, creating an external program, said external program including a method pointer registration module register _ profile _ func and a variable void holding a method pointer (NULL);
starting a source program, calling a method pointer registration module of the external program through an api of a libdl.
And after the external program obtains the internal method pointer, calling and acquiring the internal thread ID at any time according to the method pointer.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710293491.7A CN107168870B (en) | 2017-04-28 | 2017-04-28 | Method for acquiring program information during operation |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710293491.7A CN107168870B (en) | 2017-04-28 | 2017-04-28 | Method for acquiring program information during operation |
Publications (2)
Publication Number | Publication Date |
---|---|
CN107168870A CN107168870A (en) | 2017-09-15 |
CN107168870B true CN107168870B (en) | 2021-10-29 |
Family
ID=59812410
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201710293491.7A Active CN107168870B (en) | 2017-04-28 | 2017-04-28 | Method for acquiring program information during operation |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107168870B (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108052394B (en) * | 2017-12-27 | 2021-11-30 | 福建星瑞格软件有限公司 | Resource allocation method based on SQL statement running time and computer equipment |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1862511A (en) * | 2006-02-28 | 2006-11-15 | 华为技术有限公司 | Method for testing software unit |
CN1873626A (en) * | 2005-06-01 | 2006-12-06 | 中兴通讯股份有限公司 | Unit test system and method for automatic generating stub and driving function |
CN101853205A (en) * | 2010-06-23 | 2010-10-06 | 山东中创软件商用中间件股份有限公司 | Method and apparatus for monitoring the running of program |
CN103136047A (en) * | 2011-11-30 | 2013-06-05 | 大唐联诚信息系统技术有限公司 | Multithreading management method and framework |
CN103729288A (en) * | 2013-11-01 | 2014-04-16 | 华中科技大学 | Application program debugging method under embedded multi-core environment |
CN104516765A (en) * | 2013-09-30 | 2015-04-15 | 瑞萨电子株式会社 | Computer and compiling method |
CN106133684A (en) * | 2014-03-27 | 2016-11-16 | 微软技术许可有限责任公司 | Support the dynamic behaviour in static compilation program |
Family Cites Families (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8499287B2 (en) * | 2008-06-23 | 2013-07-30 | Microsoft Corporation | Analysis of thread synchronization events |
CN101340314A (en) * | 2008-08-11 | 2009-01-07 | 中兴通讯股份有限公司 | Real-time debugging positioning method of embedded system and apparatus thereof |
US8255633B2 (en) * | 2009-11-13 | 2012-08-28 | International Business Machines Corporation | List based prefetch |
CN102053808B (en) * | 2010-11-30 | 2012-10-10 | Tcl集团股份有限公司 | Method, device for printing software information as well as equipment with network interface |
-
2017
- 2017-04-28 CN CN201710293491.7A patent/CN107168870B/en active Active
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1873626A (en) * | 2005-06-01 | 2006-12-06 | 中兴通讯股份有限公司 | Unit test system and method for automatic generating stub and driving function |
CN1862511A (en) * | 2006-02-28 | 2006-11-15 | 华为技术有限公司 | Method for testing software unit |
CN101853205A (en) * | 2010-06-23 | 2010-10-06 | 山东中创软件商用中间件股份有限公司 | Method and apparatus for monitoring the running of program |
CN103136047A (en) * | 2011-11-30 | 2013-06-05 | 大唐联诚信息系统技术有限公司 | Multithreading management method and framework |
CN104516765A (en) * | 2013-09-30 | 2015-04-15 | 瑞萨电子株式会社 | Computer and compiling method |
CN103729288A (en) * | 2013-11-01 | 2014-04-16 | 华中科技大学 | Application program debugging method under embedded multi-core environment |
CN106133684A (en) * | 2014-03-27 | 2016-11-16 | 微软技术许可有限责任公司 | Support the dynamic behaviour in static compilation program |
Non-Patent Citations (7)
Title |
---|
Fast and Precise Symbolic Analysis of Concurrency Bugs in Device Drivers (T);Pantazis Deligiannis等;《2015 30th IEEE/ACM International Conference on Automated Software Engineering (ASE)》;20160107;第166-177页 * |
How to get thread id of a pthread in linux c program?;Ravi Chandra;《https://stackoverflow.com/questions/21091000/how-to-get-thread-id-of-a-pthread-in-linux-c-program》;20140113;第1-7页 * |
Linux C获取线程ID;云颖;《https://my.oschina.net/u/140714/blog/147987》;20130729;第1页 * |
一种快速定位bug的记录-回放调试系统;江山等;《计算机应用与软件》;20161015;第33卷(第10期);第219-222页 * |
基于推测多线程技术的程序可视化方法与实现;赵永刚等;《西安邮电学院学报》;20100910;第15卷(第5期);第69-74页 * |
嵌入式aCoral多线程调试器的研究与实现;赵俊涛;《中国优秀硕士学位论文全文数据库 信息科技辑》;20160315;第I138-1187页 * |
获取指定程序的所有线程ID号;bamboo_lady;《https://www.cnblogs.com/liuliu-NoGirl/p/3341121.html》;20130926;第1-3页 * |
Also Published As
Publication number | Publication date |
---|---|
CN107168870A (en) | 2017-09-15 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8719791B1 (en) | Display of aggregated stack traces in a source code viewer | |
US20150026664A1 (en) | Method and system for automated test case selection | |
US9946628B2 (en) | Embedding and executing trace functions in code to gather trace data | |
CN111090536A (en) | Method, device, medium and electronic equipment for acquiring memory leakage information | |
US20160154726A1 (en) | Variable tracking in program debugging | |
US9355003B2 (en) | Capturing trace information using annotated trace output | |
TWI684916B (en) | Function selection method and server | |
US20190042233A1 (en) | Application architecture generation | |
CN104102574A (en) | Method and device for testing application program | |
US20130179867A1 (en) | Program Code Analysis System | |
EP3447635A1 (en) | Application architecture generation | |
CN112799940A (en) | Regression testing method, device, computer system and computer readable storage medium | |
CN107122203B (en) | Configuration file setting method and device | |
US9691123B2 (en) | Instrumentation of graphics instructions | |
CN107168870B (en) | Method for acquiring program information during operation | |
CN116627850B (en) | Function debugging method and device, storage medium and electronic equipment | |
CN116432185B (en) | Abnormality detection method and device, readable storage medium and electronic equipment | |
US8752026B2 (en) | Efficient code instrumentation | |
CN110908882A (en) | Performance analysis method and device of application program, terminal equipment and medium | |
CN108197005B (en) | Method, medium, equipment and system for monitoring bottom layer operation performance of IOS application | |
US9436587B2 (en) | Test context generation | |
CN113688031B (en) | Test positioning method based on byte code enhancement technology | |
CN113360373A (en) | Test method for full traversal of Activity page of mobile application | |
CN115185570A (en) | JIRA system-based task flow processing method, system, device, medium, and computer program product | |
CN113934448A (en) | Code quality scanning method and device, storage medium and electronic equipment |
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 | ||
CB02 | Change of applicant information |
Address after: 350000 21 / F, building 5, f District, Fuzhou Software Park, 89 software Avenue, Gulou District, Fuzhou City, Fujian Province Applicant after: FUJIAN SINOREGAL SOFTWARE Co.,Ltd. Address before: Floor 20-21, building 5, area F, Fuzhou Software Park, 89 software Avenue, Gulou District, Fuzhou City, Fujian Province 350000 Applicant before: FUJIAN SINOREGAL SOFTWARE Co.,Ltd. |
|
CB02 | Change of applicant information | ||
GR01 | Patent grant | ||
GR01 | Patent grant |