Method and device for dynamically substituting C/C + + function in main program

A main program and function technology, applied in the field of computer science, can solve the problems of low replacement efficiency, infinite loop, inconvenient use by users, etc., and achieve the effect of improving efficiency and realizing dynamic restoration.

Active Publication Date: 2013-09-11
BAIDU ONLINE NETWORK TECH (BEIJIBG) CO LTD
View PDF6 Cites 12 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

[0004] (1) The method of setting the LD_PRELOAD environment variable under Linux is to load it once when the program starts, so the shared library function cannot be dynamically replaced and restored when the program is running
Every time a function is replaced, it is necessary to reload the shared library and start the program, so the operation time is long and the replacement efficiency is low
[0005] (2) Since the replaced system function will be completely replaced, if the replaced system function is called indirectly inside the replacement function, it will cause the replacement function to call itself repeatedly, resulting in an infinite loop
[0006] (3) The method of setting the LD_PRELOAD environment variable can only load shared library functions, so the existing methods cannot replace non-shared library functions, such as user-defined functions, etc., so it is inconvenient for users to use

Method used

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more

Image

Smart Image Click on the blue labels to locate them in the text.
Viewing Examples
Smart Image
  • Method and device for dynamically substituting C/C + + function in main program
  • Method and device for dynamically substituting C/C + + function in main program
  • Method and device for dynamically substituting C/C + + function in main program

Examples

Experimental program
Comparison scheme
Effect test

Embodiment Construction

[0026] Embodiments of the present invention are described in detail below, examples of which are shown in the drawings, wherein the same or similar reference numerals designate the same or similar elements or elements having the same or similar functions throughout. The embodiments described below by referring to the figures are exemplary only for explaining the present invention and should not be construed as limiting the present invention.

[0027] Refer below figure 1 A flow chart of a method for dynamically replacing C / C++ functions in a main program according to an embodiment of the present invention is described. Such as figure 2 Shown is a schematic diagram of a method for dynamically replacing C / C++ functions in the main program according to a specific embodiment of the present invention. Preferably, the present invention is used in a Linux system, and the following embodiments will use the Linux system as an example for description.

[0028] Step S110: Start the m...

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

PUM

No PUM Login to view more

Abstract

The invention provides a method and a device for dynamically substituting a C / C + + function in a main program. The method includes steps as follows: the main program is started, and a substitution program module used for inquiring and modifying a memory is loaded; the loaded substitution program module is initialized, so that the substitution program module is executed in advance of a main function in the main program; symbol table information of a function in the main program is stored in the memory; after the substitution program module receives a substitution instruction, the substitution program module determines a mapping address of a substituted function in the memory according to symbol table information corresponding to the substituted function; and the substituted function is substituted according to the mapping address. The method and the device can dynamically substitute and restore the function during operation of the program, the program is not required to be recompiled, time is saved, high efficiency is realized, and the infinite loop phenomenon when the substituted function is indirectly called inside a substitution function is avoided.

Description

technical field [0001] The invention relates to the technical field of computer science, in particular to a method and a device for dynamically replacing C / C++ functions in a main program. Background technique [0002] When debugging, mocking and testing C / C++ programs under Linux, function replacement is often required. Function replacement refers to using the replacement function to overwrite the replaced function. The existing technology for replacing C / C++ functions under Linux mainly completes the function replacement by setting the LD_PRELOAD environment variable and loading the shared library once when the program starts. During the loading process, if there is a function with the same name in the shared library, such as malloc, the corresponding system function malloc will be automatically replaced with the replacement function malloc in the shared library. [0003] Although the existing method can realize function replacement, it has the following disadvantages: ...

Claims

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

Application Information

Patent Timeline
no application Login to view more
Patent Type & Authority Applications(China)
IPC IPC(8): G06F9/44G06F9/45
Inventor 禤彪
Owner BAIDU ONLINE NETWORK TECH (BEIJIBG) CO LTD
Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Try Eureka
PatSnap group products