CN113805928A - Hot patch file generation and consistency detection method, device, equipment and medium - Google Patents

Hot patch file generation and consistency detection method, device, equipment and medium Download PDF

Info

Publication number
CN113805928A
CN113805928A CN202010534121.XA CN202010534121A CN113805928A CN 113805928 A CN113805928 A CN 113805928A CN 202010534121 A CN202010534121 A CN 202010534121A CN 113805928 A CN113805928 A CN 113805928A
Authority
CN
China
Prior art keywords
file
dynamic library
main program
source
thread
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
CN202010534121.XA
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.)
ZTE Corp
Original Assignee
ZTE Corp
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 ZTE Corp filed Critical ZTE Corp
Priority to CN202010534121.XA priority Critical patent/CN113805928A/en
Priority to PCT/CN2021/099526 priority patent/WO2021249518A1/en
Publication of CN113805928A publication Critical patent/CN113805928A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • G06F8/658Incremental updates; Differential updates
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/194Calculation of difference between files
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/72Code refactoring

Abstract

The embodiment of the invention discloses a hot patch file generation method, a hot patch file consistency detection method, a hot patch file generation device, a hot patch file consistency detection device and a hot patch file consistency detection medium. The hot patch file comprises identification information, whether each patch function corresponds to a main program or a dynamic library can be obtained, the patched function can be accurately obtained, and the usability is high. The embodiment of the invention also provides a consistency detection method, a consistency detection device, a hot patch file generation device, equipment and a medium, and the reliability of the hot patch technology is improved.

Description

Hot patch file generation and consistency detection method, device, equipment and medium
Technical Field
The embodiment of the invention relates to the technical field of hot patching of linux user state software written in C/C + + language, in particular to a method, a device, equipment and a medium for generating hot patching files and detecting consistency.
Background
In the field of communications, it is important to ensure service continuity, and when a program fails, the failure needs to be repaired online rather than the program being restarted. The technique of repairing a fault online is generally called a hot patching technique, and replaces a patch function (a function after repairing a fault) which is running with a patch function (a function after repairing a fault) in order to repair the fault without restarting the program. The hot patching technology basically adopts the mode that an instruction at an inlet of a patched function is modified into a jump instruction for jumping to the inlet of the patched function, so that the purpose of function replacement is achieved.
Because a general program consists of a main program and a dependent dynamic library, the main program and the dynamic library may have homonymous functions, and how to accurately acquire a patched function is the premise of correctly patching the program. For example, to patch function a, more than one function named a may be defined in the dynamic library on which the program depends, and a function is found to be faulty, which may cause the program to crash. At present, a common practice in the industry is to require that the attribution information (a main program or a dynamic library) of a patched function is specified during patching, or require that the attribution information of the patched function is recorded in a patch file during patch making, so that neither patching personnel nor patching personnel are necessarily developers, and the attribution information of the patched function may not be clear, so that the method is not easy to use and easy to make mistakes, and the reliability of the hot patching technology is not high.
Disclosure of Invention
The embodiment of the invention mainly aims to provide a method, a device, equipment and a medium for generating a hot patch file and detecting consistency, and aims to solve the problem that a patched function in a hot patch technology cannot be accurately acquired, so that the hot patch technology is poor in usability, easy to make mistakes and low in reliability.
In order to achieve the above object, an embodiment of the present invention provides a hot patch file generation method, where the hot patch file generation method includes:
acquiring a first target file in a first project before modification and a second target file in a second project after modification, wherein the first target file and the second target file are files with difference on corresponding storage nodes of the first project and the second project respectively;
acquiring a first source file name for generating the first target file and a second source file name for generating the second target file;
acquiring a first main program source file list of a first main program, a first dynamic library source file list of a first dynamic library, a second main program source file list of a second main program and a second dynamic library source file list of a second dynamic library, wherein the first main program and the first dynamic library belong to the first project, and the second main program and the second dynamic library belong to the second project;
determining attribution information of the first target file and the second target file, wherein the attribution information is determined according to the first source file name, the second source file name, the first main program source file list, the second main program source file list, the first dynamic library source file list and the second dynamic library source file list, and the attribution information comprises any one of the following information: belonging to a first dynamic library, belonging to a second dynamic library, belonging to a first main program and belonging to a second main program;
acquiring a main program difference function, and generating a first intermediate hot patch file, wherein the first intermediate hot patch file comprises identification information, the identification information comprises a main program identifier, and the main program difference function comprises a function which is different between a first target file belonging to a first main program and a second target file belonging to a second main program on a corresponding node;
acquiring a dynamic library difference function, and generating a second intermediate hot patch file, wherein the second intermediate hot patch file comprises identification information, the identification information comprises a dynamic library identifier, and the dynamic library difference function comprises a function of a difference between a first target file belonging to a first dynamic library and a second target file belonging to a second dynamic library on a corresponding node;
and packaging the first intermediate hot patch file and the second intermediate hot patch file to generate a hot patch file.
In order to achieve the above object, an embodiment of the present invention further provides a consistency detection method, where the consistency detection method includes:
acquiring identification information of a full path and a patched function of a hot patch file;
acquiring source program call stack information of a source program;
according to the source program call stack information, each thread of the current process of the source program backtracks the current function call chain of each thread in parallel;
traversing thread functions in each layer in the current function call chain, and performing consistency detection, wherein the consistency detection comprises determining thread states of the threads according to the identification information, and the thread states comprise a blocking state or continuous operation;
determining a result of the coherency detection based on the thread states of the threads.
In order to achieve the above object, the present invention provides a hot patch file generating apparatus, including:
the system comprises a first acquisition module, a second acquisition module and a third acquisition module, wherein the first acquisition module is used for acquiring a first target file in a first project before modification and a second target file in a second project after modification, and the first target file and the second target file are files with difference on corresponding storage nodes of the first project and the second project respectively;
a second obtaining module, configured to obtain a first source file name for generating the first target file and a second source file name for generating the second target file;
a third obtaining module, configured to obtain a first main program source file list of a first main program, a first dynamic library source file list of a first dynamic library, a second main program source file list of a second main program, and a second dynamic library source file list of a second dynamic library, where the first main program and the first dynamic library belong to the first project, and the second main program and the second dynamic library belong to the second project;
a first determining module, configured to determine attribution information of the first target file and the second target file, where the attribution information is determined according to the first source file name, the second source file name, the first main program source file list, the second main program source file list, the first dynamic library source file list, and the second dynamic library source file list, and the attribution information includes any one of: belonging to a first dynamic library, belonging to a second dynamic library, belonging to a first main program and belonging to a second main program;
a fourth obtaining module, configured to obtain a main program difference function, and generate a first intermediate hot patch file, where the first intermediate hot patch file includes identification information, the identification information includes a main program identifier, and the main program difference function includes a function that is different between a first target file belonging to a first main program and a second target file belonging to a second main program on a corresponding node;
a fifth obtaining module, configured to obtain a dynamic library difference function, and generate a second intermediate hot patch file, where the second intermediate hot patch file includes identification information, the identification information includes a dynamic library identifier, and the dynamic library difference function includes a function that a difference exists between a first target file belonging to the first dynamic library and a second target file belonging to the second dynamic library on a corresponding node;
and the packaging module is used for packaging the first intermediate hot patch file and the second intermediate hot patch file to generate a hot patch file.
To achieve the above object, the present invention provides a consistency detection apparatus, comprising:
a sixth obtaining module, configured to obtain identification information of a full path and a patched function of a hot patch file;
a seventh obtaining module, configured to obtain source program call stack information of a source program;
the parallel backtracking module is used for backtracking the current function call chain of each thread according to the call stack information of the source program by each thread of the current process of the source program in parallel;
a detection module, configured to traverse thread functions in each layer in the current function call chain, and perform consistency detection, where the consistency detection includes determining a thread state of the thread according to the identification information, and the thread state includes a blocking state or continuous operation;
a second determining module, configured to determine a result of the consistency detection according to the thread state of each thread.
To achieve the above object, the present invention provides a first device including a first memory, a first processor, a first program stored on the first memory and executable on the first processor, and a first data bus for implementing connection communication between the first processor and the first memory, wherein the first program, when executed by the first processor, implements the steps of the hot patch file generation method according to any one of the above embodiments.
To achieve the above object, the present invention provides a second device, which includes a second memory, a second processor, a second program stored on the second memory and executable on the second processor, and a second data bus for implementing connection communication between the second processor and the second memory, wherein the second program, when executed by the second processor, implements the steps of the consistency detection method according to any one of the above embodiments.
To achieve the above object, the present invention provides a medium for a computer readable storage, the storage medium storing one or more first programs, the one or more first programs being executable by one or more first processors to implement the steps of the hot patch file generation method according to any one of the above embodiments;
or the like, or, alternatively,
the storage medium stores one or more second programs, which are executable by one or more second processors to implement the steps of the consistency detection method according to any one of the above embodiments.
The invention provides a hot patch file generation method, a hot patch file consistency detection device, a hot patch file generation device and a hot patch file consistency detection medium. A first source file name for generating a first target file and a second source file name for generating a second target file are obtained. The method comprises the steps of obtaining a first main program source file list of a first main program, a first dynamic library source file list of a first dynamic library, a second main program source file list of a second main program and a second dynamic library source file list of a second dynamic library, wherein the first main program and the first dynamic library belong to a first project, and the second main program and the second dynamic library belong to a second project. Determining attribution information of the first target file and the second target file, wherein the attribution information is determined according to the first source file name, the second source file name, the first main program source file list, the second main program source file list, the first dynamic library source file list and the second dynamic library source file list, and the attribution information comprises any one of the following information: belonging to a first dynamic library, belonging to a second dynamic library, belonging to a first main program and belonging to a second main program. Acquiring a main program difference function, and generating a first intermediate hot patch file, wherein the first intermediate hot patch file comprises identification information, the identification information comprises a main program identifier so as to identify that the first intermediate hot patch file corresponds to a main program, and the main program difference function comprises a function which has difference between a first target file belonging to the first main program and a second target file belonging to a second main program on a corresponding node; acquiring a dynamic library difference function to generate a second intermediate hot patch file, wherein the second intermediate hot patch file comprises identification information, the identification information comprises a dynamic library identifier to identify that the second intermediate hot patch file corresponds to a dynamic library, and the dynamic library difference function comprises a function of difference between a first target file belonging to the first dynamic library and a second target file belonging to the second dynamic library on a corresponding node; and packaging the first intermediate hot patch file and the second intermediate hot patch file to generate a hot patch file. Obtaining attribution information of the first target file and the second target file by comparing the source file names of the first target file and the second target file with a first main program and a second main program or a source file list corresponding to a first dynamic library and a second dynamic library, classifying the first target file and the second target file according to the attribution information, comparing the first target file and the second target file with attribution information of the first main program and the second main program to obtain a main program difference function, comparing the first target file and the second target file with attribution information of the first dynamic library and the second dynamic library to obtain a dynamic library difference function, generating a first intermediate hot patch file according to the main program difference function, recording an identifier in the first intermediate hot patch file, generating a second intermediate hot patch file according to the dynamic library difference function, and recording a dynamic library identifier in the second intermediate hot patch file, so that the identification information of the patched function is the same as the identification information of the file where the patched function is located in the hot patch file obtained by packaging, according to the file where the patch function is located, whether the patch function belongs to the main program or the dynamic library can be further known, that is, the information that whether each patched function belongs to the main program or the dynamic library can be clearly and accurately obtained. When the hot patch is patched, an operator only needs to designate the hot patch file, and because the identification information of the patch function in the hot patch file is known, the patched function can be accurately acquired, so that the risk of patching failure or patching error caused by incapability of accurately determining the patched function due to the fact that the identification information of the patch function is unknown when the main program and the dynamic library of the source file have the same function is reduced. The operation can be realized in an automatic mode, at the moment, an operator does not need to know the details of the program and the patch, the usability is high, the error caused by the reason of the operator is effectively avoided, and the reliability of the hot patch technology is improved.
Drawings
Fig. 1 is a flowchart of a hot patch file generation method according to an embodiment of the present invention;
fig. 2 is a flowchart of a specific application example of a hot patch file generation method according to an embodiment of the present invention;
FIG. 3 is a flowchart of a consistency detection method according to a second embodiment of the present invention;
fig. 4 is a flowchart of a specific application example of a consistency detection method according to a second embodiment of the present invention;
fig. 5 is a block diagram of a hot patch file generation apparatus according to a third embodiment of the present invention;
fig. 6 is a block diagram of a consistency detection apparatus according to a fourth embodiment of the present invention;
fig. 7 is a block diagram of a first device according to a fifth embodiment of the present invention;
fig. 8 is a block diagram of a second device according to a sixth embodiment of the present invention.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
In the following description, suffixes such as "module", "part", or "unit" used to denote elements are used only for facilitating the explanation of the present invention, and have no peculiar meaning in itself. Thus, "module", "component" or "unit" may be used mixedly.
Example one
As shown in fig. 1, the present embodiment provides a hot patch file generation method, which includes, but is not limited to, the following steps:
step S10: and acquiring a first target file in the first project before modification and a second target file in the second project after modification.
It should be noted that the first target file and the second target file are files having differences on the storage nodes corresponding to the first project and the second project, respectively. The second project is obtained by modifying the first project according to a certain rule, so that under normal conditions, the storage nodes of each modified file in the second project and the storage nodes of each unmodified file in the first project have a certain corresponding relationship, and therefore, a file with a difference on the corresponding storage nodes can be understood as a modified file in the second project obtained by modifying the file before modification in the first project, and if the content of the file before modification and the content of the modified file are different, the file before modification is the first target file, and the file after modification is the second target file.
In some embodiments, before acquiring the first target file in the first project before modification and the second target file in the second project after modification, the method further includes:
respectively constructing a first project before modification and a second project after modification in the same directory according to the compiling parameters of the debugging information,
the first target file and the second target file are files with difference in the binary files with the same name of the first project and the second project respectively.
It should be noted that the compiling paths of the binary files with the same name of the first project and the second project are the same.
In some embodiments, assume that a hot patch is made for project P. Suppose that the project P build will result in a main program and several dependent dynamic libraries. Adding a project before compiling and modifying the-g parameter, and after compiling is completed, modifying the whole project into P; and then, adding a-g parameter to compile the project with the modified source code under the same directory, and renaming the project to be P'. Therefore, the compiling paths in the binary files with the same name in the engineering directory of P' are the same, and the influence on the subsequent patch making due to different compiling paths is avoided. At this time, the first and second target files include files having a difference in the homonymous binary files of the first project and the second project. Specifically, it can be understood that a binary file named X exists in both the first project and the second project, but if the contents of the file X in the first project and the file X in the second project are different, the two files named X are the first target file of the first project and the second target file of the second project.
In some embodiments, obtaining the first and second object files further comprises: and comparing the project directory of the first project with the project directory of the second project to generate a target file list, wherein each node in the target file list comprises the full path names of the first target file and the second target file with the same name.
In some embodiments, the method for acquiring the first and second target files may be: and comparing the project directories of the first project and the second project by using a diff tool to obtain a target file list O of the same-name different target files under the two project directories, wherein each node in the target file list O records the full path names of the first target file and the second target file with the same name. For example, a diff tool is used to compare the project directories of projects P ' and P, find the files X and X ' with the same name and different file contents stored under the same path, then X and X ' are used as a pair of target file pairs, and the full path name of the target file pair is recorded in the target file list.
Step S11: a first source file name for generating a first target file and a second source file name for generating a second target file are obtained.
In some embodiments, obtaining a first source file name that generates the first destination file, and a second source file name that generates the second destination file comprises:
analyzing debugging information of the first target file to obtain a first source file name;
and analyzing the debugging information of the second target file to obtain a second source file name.
In some embodiments, the first and second source file names may be generated by parsing the debugging information of the first and second target files one by one.
In some embodiments, when the target file list is obtained, the first source file name and the second source file name for generating the first target file and the second target file may be obtained by analyzing debugging information of each of the first target file and the second target file in the target file list.
Step S12: and acquiring a first main program source file list of a first main program, a first dynamic library source file list of a first dynamic library, a second main program source file list of a second main program and a second dynamic library source file list of a second dynamic library.
The first main program and the first dynamic library belong to a first project, and the second main program and the second dynamic library belong to a second project.
In some embodiments, the obtaining of the first main program and the first dynamic library may be obtained by obtaining a full path name of the main program and the dynamic library corresponding to the first project. The obtaining of the second main program and the second dynamic library may be obtained by obtaining a full path name of the main program and the dynamic library corresponding to the second project.
In some embodiments, the compilation path of the homonymous binary files of the first project and the second project are the same. The first and second main programs and the first and second dynamic libraries can be obtained by respectively obtaining full path names of the main program and the dynamic libraries corresponding to the first project and the second project from the binary file with the same name. In some embodiments, by scanning binary files under the engineering targets of the first engineering and the second engineering, respectively, the full path names of the first main program and the first dynamic library corresponding to the first engineering, and the full path names of the second main program and the second dynamic library corresponding to the second engineering can be obtained and recorded. The specific process of acquiring the full pathname may be obtained by using a related technology, and is not described herein again.
It should be noted that the dynamic library in the embodiment of the present invention is a dynamic library on which the main program depends.
In some embodiments, obtaining a first main program source file list of a first main program, a first dynamic library source file list of a first dynamic library, a second main program source file list of a second main program, a second dynamic library source file list of a second dynamic library comprises:
analyzing debugging information of the first main program to obtain a first main program source file list;
analyzing debugging information of the second main program to obtain a second main program source file list;
analyzing debugging information of the first dynamic library to obtain a source file list of the first dynamic library;
and analyzing the debugging information of the second dynamic library to obtain a source file list of the second dynamic library.
Step S13: and determining attribution information of the first target file and the second target file.
The attribution information is determined according to a first source file name, a second source file name, a first main program source file list, a second main program source file list, a first dynamic library source file list and a second dynamic library source file list, and the attribution information comprises any one of the following information: belonging to a first dynamic library, belonging to a second dynamic library, belonging to a first main program and belonging to a second main program;
by comparing the first and second source file names obtained in S11 with the first and second main program source file lists and the first and second dynamic library source file lists respectively corresponding to the first and second main programs and the first and second dynamic libraries obtained in S12, it can be obtained whether the first target file belongs to the first main program or the first dynamic library, and whether the second target file belongs to the second main program or the second dynamic library. Specifically, for example, if the first source file name of the first target file X in the first project is N, and the first main program source file list of the first main program of the first project includes a file with the source file name of N, it may be determined that the first target file X belongs to the first main program.
It should be known that, when determining the attribution information of the target file, since the first target file belongs to the first project, the first main program of the first project is adopted to compare with the first main program corresponding to the first dynamic library and the dynamic library source file list; and comparing the second target file belongs to the second project by adopting a second main program of the second project and a second main program and a dynamic library source file list corresponding to the second dynamic library.
Step S14: acquiring a main program difference function, and generating a first intermediate hot patch file;
step S15: and acquiring a dynamic library difference function, and generating a second intermediate hot patch file.
It should be noted that the first intermediate hot patch file includes identification information, the identification information includes a main program identifier, and the main program difference function includes a function that a difference exists between a first target file belonging to a first main program and a second target file belonging to a second main program on a corresponding node; the second intermediate hot patch file includes identification information including a dynamic library identifier, and the dynamic library difference function includes a function in which a difference exists between a first target file belonging to the first dynamic library and a second target file belonging to the second dynamic library on the corresponding node. The dynamic library identification shows that the first intermediate hot patch file corresponds to a dynamic library, and the main program identification shows that the second intermediate hot patch file corresponds to a main program.
In some embodiments, obtaining the main program difference function, generating a first intermediate hot patch file, obtaining the dynamic library difference function, and generating a second intermediate hot patch file comprises:
according to the attribution information, the first target file is respectively linked to generate a first main program intermediate file and a first dynamic library intermediate file;
according to the attribution information, respectively linking the second target file to generate a second main program intermediate file and a second dynamic library intermediate file;
extracting a function with difference in the same-name binary files in the first main program intermediate file and the second main program intermediate file as a main program difference function, and generating a first intermediate hot patch file according to the main program difference function;
and extracting a function with difference in the same-name binary files in the first dynamic library intermediate file and the second dynamic library intermediate file as a dynamic library difference function, and generating a second intermediate hot patch file according to the dynamic library difference function.
In some embodiments, the generating a first main program intermediate file and a first dynamic library intermediate file by linking the first target file respectively according to the attribution information, and generating a second main program intermediate file and a second dynamic library intermediate file by linking the second target file respectively according to the attribution information comprises:
comparing the project directories of the first project and the second project to generate a target file list, wherein each node in the target file list comprises a full path name of a first target file and a full path name of a second target file which are of the same name;
according to the attribution information, the first target file is linked step by step according to the path information recorded by the target file list to generate a first main program intermediate file and a first dynamic library intermediate file;
and according to the attribution information, linking the second target file step by step according to the path information recorded in the target file list to generate a second main program intermediate file and a second dynamic library intermediate file.
It should be noted that, depending on the linking manner, there may be one or more first main program intermediate files. Correspondingly, there may be one or more second main program intermediate files. The first dynamic library intermediate file may be one or more. The second dynamic library intermediate file may be one or more. Since the dynamic library difference function is obtained, the first dynamic library intermediate file needs to be compared with the file (the binary file with the same name) on the corresponding node in the second dynamic library intermediate file, at this time, if a plurality of first dynamic library intermediate files and a plurality of second dynamic library intermediate files exist, the comparison process is complicated, and the workload is large. Similarly, since the main program difference function is obtained, the first main program intermediate file and the file (the binary file with the same name) on the corresponding node in the second main program intermediate file need to be compared, at this time, if a plurality of first main program intermediate files and a plurality of second main program intermediate files exist, the comparison process is complicated, and the workload is large. If the first main program intermediate file, the second main program intermediate file, the first dynamic library intermediate file and the second dynamic library intermediate file are obtained in a step-by-step connection mode, the comparison between the first main program intermediate file and a file (a homonymous binary file) on a node corresponding to the second main program intermediate file can be realized to obtain a main program difference function, correspondingly, the comparison between the first dynamic library intermediate file and a file (a homonymous binary file) on a node corresponding to the second dynamic library intermediate file is realized to obtain a dynamic library difference function, the process is simpler, more convenient and faster, and the user experience is higher.
Step S16: and packaging the first intermediate hot patch file and the second intermediate hot patch file to generate a hot patch file.
In some embodiments, the first and second intermediate hot patch files are packaged by the objcopy tool to generate a hot patch file.
In some embodiments, the first intermediate hot patch file and the second intermediate hot patch file are each stored as a separate section in the hot patch file.
In some embodiments, the hot patch file includes main program information. Therefore, subsequent management and verification can be facilitated, and the hot patch file for which main program is can be known more accurately.
It should be noted that the execution sequence of steps S11 and S12 is not limited in this embodiment, that is, step S12 may be executed after step S11 is executed, or both of them may be executed simultaneously, as long as the source file name and the source file list are obtained before step S13 is executed.
In some embodiments, the steps are all realized in an automatic mode, at this time, the hot patch is manufactured without depending on manual setting of the attribution of the patch function, the method is more convenient and faster, and the accuracy is higher after human errors are eliminated.
Referring to fig. 2, the practical application of the hot patch file generation method is specifically described below by taking the example of creating a hot patch file for a project P.
Step S20: and adding-g parameters to construct projects before and after modification.
Suppose that the project P build will result in a main program and several dependent dynamic libraries. Adding a project before compiling and modifying the-g parameter, and renaming the obtained whole project as P after compiling is completed; and adding-g parameters under the same directory to compile and modify the project after the source codes to obtain a project P'. Therefore, compiling paths in binary files with the same name in the two engineering directories P and P' are completely the same, and the influence on subsequent patch making due to different compiling paths is avoided.
Step S21: and acquiring the full paths of the main program and the dynamic library under the engineering catalog.
Specifically, a binary file under the project P directory is scanned, and full path names of a first main program and a first dynamic library are recorded. And scanning the binary file under the project P' directory, and recording the full path names of the second main program and the second dynamic library.
Step S22: and acquiring a source file list of the main program and the dynamic library.
And obtaining a first main program, a first dynamic library, a second main program and a second dynamic library which respectively correspond to the project P and the project P' through the full path names of the first main program and the second main program and the first dynamic library and the full path names of the second dynamic library.
Specifically, debugging information of a first main program and a first dynamic library of the project P is analyzed, and a first main program and a dynamic library source file list which form the first main program and the first dynamic library are obtained respectively. And analyzing debugging information of the second main program and the second dynamic library of the project P' to respectively obtain a second main program and a dynamic library source file list which form the second main program and the second dynamic library.
Step S23: and acquiring a target file list.
Specifically, two engineering catalogs P' and P are compared by using diff tool to obtain the same data under the two engineering catalogs
The addresses of the first target file and the second target file with different names form a target file list O, wherein each node in the target file list O comprises the full path names of the first target file before modification and the second target file after modification with the same name.
Step S24: and analyzing the target file list and determining attribution information.
Specifically, the debugging information of the first and second object files in each node in the list O is analyzed one by one to obtain the first and second source file names for generating the first and second object files, and the first and second object files can be determined to belong to the first and second dynamic libraries or the first and second main programs, that is, the attribution information of the first and second object files, by the first and second source file names, the first and second main program source file lists and the first and second dynamic library source file lists obtained in step S22.
Step S25: and comparing the first target file and the second target file, extracting the difference, generating an intermediate hot patch file and recording the identification information.
Specifically, for a first target file and a second target file of which the attribution information is a first main program and a second main program, the first target file and the second target file are respectively linked into a first main program intermediate file and a second main program intermediate file step by step, then the two first main program intermediate files and the second main program intermediate file are compared, a difference function is extracted to generate a first intermediate hot patch file, and meanwhile, the identification information of the first intermediate hot patch file is recorded as a main program identifier; for a first target file and a second target file of which the attribution information is a first dynamic library and a second dynamic library, the first target file and the second target file are respectively linked into a first dynamic library intermediate file and a second dynamic library intermediate file step by step, then the homonymous binary files in the two first dynamic library intermediate files and the second dynamic library intermediate file are compared, a function with difference is extracted to generate a second intermediate hot patch file, and meanwhile, the identification information of the second intermediate hot patch file is recorded as a dynamic library identifier. At this time, it can be obtained that the patch function in the first intermediate hot-patch file corresponds to the main program, and the patch function in the second intermediate hot-patch file corresponds to the dynamic library.
Step S26: and encapsulating the first and second intermediate hot patch files into hot patch files.
Specifically, the first and second intermediate hot patch files are packaged into one hot patch file by an objcopy tool, wherein the first and second intermediate hot patch files can be stored as an independent section respectively.
The hot patch file can also record the information of the main program, so that subsequent management and verification are facilitated.
In some embodiments, the hot patch file generation method provided by the embodiment of the present invention may be applied to the hot patch technology field of linux user mode software written in C/C + + language.
In some embodiments, the hot patch file generation method provided by the embodiment of the present invention is applied to the hot patch technology field of linux user-state software written in the C/C + + language of the X8664 architecture. In some embodiments, the hot patch file generation method provided by the present embodiment provides a linux user-state program hot patch solution.
By the hot patch file generation method provided by the embodiment, a hot patch file is finally generated, the hot patch file is formed by packaging a second intermediate hot patch file belonging to a dynamic library and a first intermediate hot patch file belonging to a main program, the attribution information of the first and second target files can be obtained by comparing the first and second source file names of the first and second target files with the first and second main program source file lists or the first and second dynamic library source file lists corresponding to the first and second main programs or the first and second dynamic libraries, and according to the attribution information, the identification information can be recorded in the first and second intermediate hot patch files, so that whether each patch function in the first and second intermediate hot patch files corresponds to a source program or a dynamic library can be obtained. On one hand, all steps of the hot patch generation process can be automatically completed without a manufacturer knowing details of a program, only the manufacturer needs to know how to construct a target project, and after constructing the first project and the second project before and after modification, the rest steps are realized in an automatic mode, so that the hot patch file generation efficiency is improved, the steps of manual operation are simplified, the user experience is improved, and an operator only needs to specify a patch file during hot patch making, and does not need to know details of the program and the patch. The usability is very high, errors cannot be caused due to the reason of operators, and the reliability of the hot patching technology is improved; on the other hand, the identification information of each function is recorded in the generated hot patch file, so that whether the function corresponds to the main program or the dynamic library of the source program to be patched can be known, and the risk that patching failure or patching error is caused because the identification information of the patching function is not known when the main program and the dynamic library of the source program have the same function and the patched function cannot be accurately determined is reduced.
Example two
The reliability of the hot patching technology also depends on whether the consistency of the program state can be ensured, namely, the program is executed by the original patched function before the patching operation is finished, the program is executed by the patched function after the patching operation is finished, and an intermediate state cannot exist, namely, part of tasks after the patching operation is finished cannot be allowed to execute the old codes in the patched function, so that the program data and the state are possibly disordered, the correctness of the program function is influenced, and the program is even crashed. This requires that, when patching is performed, it is necessary to determine whether each task of the program is executing a patched function, and if so, the function replacement is postponed, and the function replacement must be performed until all tasks do not execute the patched function. How to determine whether the current tasks of the program are executing the patched function is called a consistency detection technique.
The hot patch consistency detection technology in the related art is typically implemented by the following two schemes:
the first scheme is as follows: only the current programmer PC for each task is checked for being in the patched function when hot patching. The scheme is obviously imperfect, for example, to replace a function a in a program, and a function call chain of a certain thread is a- > B- > C when a hot patch is applied, a code of the C is currently executed, if only a current PC is detected, the PC does not belong to the function a in the function C, the detection is passed, and then the original a is replaced by a new a ', but in this way, after the hot patch is applied, the thread returns from the B and continues to execute the residual code in the original a, and threads of other new calls a execute the new a', which causes inconsistent program states and may cause program function abnormality.
Scheme II: and tracking the process by using ptrace debugging technology provided by a Linux kernel, suspending all threads, acquiring function call chains of the threads one by one, and checking whether a patched function exists in the function call chains. According to the scheme, the problem of inconsistent program states in the first scheme can be solved, but on one hand, in the checking process, data of the detected program needs to be read frequently through ptrace system call, and the kernel state and the user state need to be switched frequently, so that the performance is low; on the other hand, the checking process needs to be executed on each thread one by one, and if the number of threads of the program is large, the time is consumed; and all threads in the program are in a pause state in the detection process, so that the influence on the program is large. This may be unacceptable for communication service programs that are sensitive to latency requirements, and may even result in the programs no longer functioning properly.
It can be seen that consistency detection schemes in the related art all have some defects, or are unreliable and seriously degraded in performance, which may cause that a program cannot normally run after hot patching.
As shown in fig. 3, the present embodiment provides a consistency detection method, which includes, but is not limited to, the following steps:
step S30: and acquiring the identification information of the full path and the patched function of the hot patch file.
In some embodiments, the full path of the hot patch file may be user-specified, or may be set by a system preset or the like. And after the setting of the full path of the hot patch file is finished, acquiring the full path of the hot patch file.
In some embodiments, obtaining identification information of the patched function comprises: searching a homonymous function of a patch function in a hot patch file in a source program; if the homonymous function is found, the homonymous function is the patched function; and acquiring the identification information of the patched function. In some embodiments, the identification information includes start address and size information of the patched function.
In some embodiments, the hot patch file may be loaded through the hot patch management thread, all the patch function information in the hot patch file is obtained, and then the homonymous function is searched in the source program, and if the homonymous function is searched, the function is a patched function. The start address and size information of the patched function is recorded. In some embodiments, there may be a department patch function that cannot find a hot patch file in the source program, which indicates that the patch function is a new function.
It should be noted that the hot patch file in the consistency detection method in the embodiment of the present invention may be a hot patch file generated by using the hot patch file generation method provided in the above embodiment, or a hot patch file obtained by using a method of the related art, which is not limited herein.
Step S31: and acquiring the call stack information of the source program.
The source program call stack information is auxiliary information generated by a compiler and used for backtracking the function call chain.
In some embodiments, the main program of the process that needs hot patching (the current process) and the source program call stack information of the dependent dynamic library can be loaded at program initialization. Of course, the method may also be performed to obtain the call stack information of the source program and the dynamic library when hot patching is needed. Those skilled in the art can also reasonably set other times for acquiring the stack information called by the main program of the source program and the source program of the dynamic library according to needs.
Step S32: and according to the calling stack information of the source program, each thread of the current process of the source program backtracks the current function calling chain of each thread in parallel.
In some embodiments, the current process of the source program, that is, each thread of the process of the source program that needs to be patched, may execute a backtracking process in parallel, so that the backtracking efficiency is high. Of course, those skilled in the art may also specify that part of the threads are traced back one by one in parallel, or each thread is traced back one by one.
Step S33: and traversing thread functions in each layer in the current function call chain, and carrying out consistency detection.
It should be noted that the consistency detection includes determining a thread state of the thread according to the identification information, where the thread state includes a blocking state or a continuous operation.
In some embodiments, by performing consistency detection on a thread and detecting whether a patched function is included in a thread function, whether the patched function is in a called state of the thread may be obtained.
In some embodiments, the thread uses the source program call stack information to trace back the current function call chain of each thread, and each layer of functions in the current function call chain is traced back to further determine whether each layer of functions includes a patched function, instead of only detecting the first layer, so that the consistency detection for the thread is complete. Further, if the consistency detection of each thread of the current process is successful, theoretically, it can be ensured that the program states after subsequent patching are consistent.
In some embodiments, determining the thread state of the thread from the identification information comprises:
when the thread function is detected not to include the patched function, the thread enters a blocking state.
In some embodiments, determining the thread state of the thread from the identification information comprises:
detecting that the thread function comprises a patched function, and continuing running the thread;
and carrying out consistency detection on the threads again at preset time intervals.
It should be noted that the preset time may be a time that is reasonably set by a person skilled in the art according to needs. The preset time may also refer to the time when a thread completes detection, for example, 20 ms is required for completing detection of a thread, and then the check time interval may be set to 30 ms in consideration of the issue of multi-thread scheduling.
In some embodiments, if there is a thread that has not entered the blocking state in each thread of the current process of the source program, the step of consistency detection is repeated until the consistency detection of the source program succeeds when each thread of the current process of the source program enters the blocking state, and the process is ended.
Step S34: and determining the consistency detection result according to the thread state of each thread.
In some embodiments, determining the result of the coherency detection based on the thread states of the threads comprises:
and all threads enter a blocking state, and the consistency detection of the source program is successful.
It should be noted that, if the patched function is not included in the thread function, it indicates that the thread passes the consistency check, and the thread is currently patched safely. And if all threads in the current process of the source program pass the consistency detection, the consistency detection of the source program is successful. It should be noted that the current process of the source program includes a process that needs hot patching.
In some embodiments, the thread entering the blocked state includes, but is not limited to, the thread entering a wait lock state.
In some embodiments, determining whether each thread of the current process (the process requiring hot patching) of the source program enters a blocking state comprises: acquiring the thread number of the current process of the source program; when the thread enters a blocking state, adding 1 to a global mark atom; when the number of the global flag atoms is equal to that of the threads, all the threads of the current process of the source program enter a blocking state. In some embodiments, if the global flag atom is smaller than the number of threads, the number of times of detection of currently completed consistency detection of any thread which has not entered the blocking state is obtained, and if the number of times of detection is larger than a preset detection time threshold, normal operation of each thread in the blocking state is resumed. Wherein the global flag atom initialization position is 0. It should be noted that the global flag atom initialization position may also be another position set by a person skilled in the art as needed, and accordingly, whether each thread of the current process of the source program enters the blocking state may be determined by a relationship between the global flag atom and the number of threads currently performed by the source program. For example, the initialization position of the global flag atom is 5, the number of threads of the current process is 10, each thread enters a blocking state, and the global flag atom is incremented by 1, so that when the global flag atom is 15, each thread of the current process of the source program can enter the blocking state.
In some embodiments, each thread enters a blocking state, and after the consistency detection of the source program is successful, the method further includes:
performing hot patching operation on the source program;
and after the operation of hot patching is finished, the running of all threads is recovered.
That is, after the consistency of the source program is successfully detected, the hot patching operation is performed on the source program, so that the consistency of the program state after patching can be ensured, and the reliability of the hot patching technology is improved.
It should be noted that, the operation of completing hot patching includes at least one of the following: the patched functions in all threads of the current process complete function replacement; and adding a function to complete the function addition. In some embodiments, the completion of the hot patching operation prompts successful patching.
In some embodiments, determining the result of the coherency detection based on the thread states of the threads comprises:
if the thread is not in the blocking state, acquiring the detection times of the consistency detection of the thread;
if the detection times are larger than a preset detection time threshold value, restoring the normal operation of each thread in the blocking state;
the consistency check of the source program fails.
In some embodiments, sometimes, due to heavy program traffic, when at least one thread undergoes consistency detection for a number of times of a preset detection time threshold, a patched function is still included in a thread function in the thread, so as to improve user experience, a user may be prompted to fail consistency detection, retry later, and resume normal operation of other threads in a process that has been blocked.
In some embodiments, if the current process consistency detection of a source program fails, the consistency detection may be performed again after receiving the instruction of hot patching next time. The issuing mode of the next hot patching instruction includes but is not limited to: the data is automatically sent after a certain time interval and is sent by a user through related equipment.
The preset detection time threshold may be a reasonable value set by one skilled in the art in combination with the actual usage scenario.
In some embodiments, if the consistency check of the source program fails, resources that are no longer in use are cleaned up, including call stack information.
In some embodiments, after determining the result of the consistency detection according to the thread state of each thread, the method further includes:
and clearing the call stack information of the source program.
In some embodiments, the consistency detection method further comprises: and after the operation of hot patching is finished, cleaning the resources which are not used any more, wherein the resources which are not used any more comprise the calling stack information of the source program.
In some embodiments, after failure of the consistency check, resources that are no longer in use, including source program call stack information, are cleaned up.
In some embodiments, after obtaining the source program call stack information of the source program, the method further includes:
sending signals to each thread, wherein the signals are non-special signals;
after the threads receive the signals, according to the calling stack information of the source program, all threads of the current process of the source program backtrack the current function calling chains of all threads in parallel.
It should be noted that the signals are non-specific signals, and the non-specific signals include SIGUSR1, SIGUSR2, and real-time signals. .
It should be noted that the current process includes a process of a source program that needs hot patching.
In some embodiments, the signal is a common signal or a real-time signal, such as a sigsri, SIG44, or a common and non-dedicated signal.
In some embodiments, determining the thread state of the thread from the identification information comprises:
acquiring identification information of a patched function, wherein the identification information comprises a main program identifier or a dynamic library identifier;
the source program call stack information comprises main program call stack information of the source program and dynamic library call stack information of the source program;
according to the calling stack information of the main program, each thread of the main program of the current process of the source program backtracks the current function calling chain of each thread in parallel;
according to the dynamic library call stack information, each thread of a dynamic library of the current process of the source program backtracks the current function call chain of each thread in parallel;
determining the thread state of the thread of the main program according to the identification information of the patched function of which the identification information comprises the main program identification;
and determining the thread state of the thread of the dynamic library according to the identification information of the patched function of which the identification information comprises the dynamic library identification.
The identification information of the patched function is used for distinguishing whether the patched function corresponds to a main program of the source program or a dynamic library of the source program. The identification information of the patched function is the same as the identification information of the patch function. For example, if the identification information of the patch function corresponding to the patched function is the main program identifier, the identification information of the patched function is also the main program identifier. Similarly, the identification information of the patch function corresponding to the patched function is the dynamic library identifier, and the identification information of the patched function is also the dynamic library identifier
Because the identification information of the patched function can classify the patched function into the patched function corresponding to the main program and the patched function corresponding to the dynamic library, the comparison range can be reduced when the thread state is determined, and the speed and the accuracy of determining the thread state are improved.
Referring to fig. 4, the following specifically describes a practical application of the consistency detection method for the source program C.
Step S40: and acquiring the identification information of the patched function and the full path of the hot patch file.
Specifically, the user specifies the full path of the hot patch file to be printed, and then the full path of the hot patch file is obtained. And the hot patch management thread loads the hot patch file and acquires all the patch function information. And searching the homonymous function of each patch function in the source program, wherein if the homonymous function is found, the homonymous function in the source program is a patched function, and if the homonymous function of the patch function cannot be found, the patch function is a newly added function. The start address and size information of the patched function is recorded.
Step S41: and loading the calling stack information of the process main program and the main program of the dynamic library and the calling stack information of the dynamic library.
Specifically, main program call stack information of a main program of the process and dynamic library call stack information of a dependent dynamic library are loaded during program initialization, and the main program call stack information and the dynamic library call stack information are auxiliary information generated by a compiler and used for backtracking a function call chain. The main program call stack information and the dynamic library call stack information constitute source program call stack information of the source program.
Step S42: and acquiring the current thread number and sending signals to each thread.
Specifically, the hot patch management thread acquires the number of threads of the current process, and sends a signal to each thread, where the signal is a common signal or a real-time signal, such as SIGUSR1, SIG44, or other common and non-dedicated signals.
Step S43: and each thread receives the signal and then backtracks the current function call chain of the thread, and detects whether a patched function exists in the current function call chain. Detecting that there is no patched function, the thread blocking wait; the presence of a patched function is detected and the thread continues to run.
Specifically, after receiving the signal, each thread backtracks its own current function call chain according to the source program call stack information, then traverses the thread function in each layer of the backtracked current function call chain, detects whether the patched function obtained in step S40 exists in the current function call chain according to the identification information, if the patched function does not exist, the detection is passed, adds one to a global flag atom, and then enters a waiting lock state; if the patched function exists, the detection fails, and the thread continues to execute.
In some embodiments, the identification information of the patched function may be obtained, where the identification information includes a main program identifier or a dynamic library identifier, the identification information of the patched function whose identification information is the main program identifier is obtained, after the thread of the main program receives a signal, the current function call chain of the main program is traced back by using the main program call stack information, then each thread of the main program traverses the thread function in each layer of the current function call chain, whether the patched function obtained in step S40 exists in the current function call chain is detected according to the identification information of the patched function whose identification information is the main program identifier, if the patched function does not exist, the detection is passed, one global flag atom is added, and then the patched function enters a lock waiting state; if the patched function exists, the detection fails, and the thread continues to execute. Obtaining identification information of a patched function with identification information as a dynamic library identification, tracing a current function call chain of a dynamic library by using dynamic library call stack information after a thread of the dynamic library receives a signal, traversing thread functions in each layer of the current function call chain by each thread of the dynamic library, detecting whether the patched function obtained in the step S40 exists in the current function call chain according to the identification information of the patched function with identification information as the dynamic library identification, if the patched function does not exist, adding one to a global mark atom, and entering a waiting lock state; if the patched function exists, the detection fails, and the thread continues to execute.
Step S44: judging whether all threads are in a waiting lock state, if so, executing the step S45; if not, go to step S46.
Step S45: function replacement is performed and the execution of all threads is resumed, and step S47 is performed.
Step S46: judging whether the number of the detected booklets is larger than a preset detection frequency threshold value, if not, executing the step S42; if yes, go to step S47.
Step S47: and (6) ending.
In some embodiments, the hot patch management thread detects whether the value of the global flag is equal to the number of other threads except the current hot patch management thread at preset intervals, if so, the detection is passed, the function replacement is performed, the success of patching is prompted, the running of all other threads is recovered, and resources which are not used any more, such as source program call stack information, are cleaned. If the value of the global flag is not equal to the number of other threads except the current hot patch management thread, the detection is not passed, whether the value of the global flag is larger than the preset detection frequency threshold is judged, and if the value of the global flag is not larger than the preset detection frequency threshold, the next detection is continuously waited. And if the detection time is larger than the preset detection time threshold, ending the process. And prompting that the patching fails and recovering the operation of other threads. And cleaning resources which are not used any more, such as calling stack information of a source program. The preset time can be selected by referring to the time when one thread completes detection, and if it takes 20 milliseconds to complete detection of one thread, the preset time can be set to 30 milliseconds in consideration of scheduling problems of multiple threads. And after prompting that the patching fails, prompting a user to retry consistency detection at certain time intervals.
In some embodiments, the consistency detection method provided by the embodiments of the present invention may be applied to the technical field of hot patching of linux user mode software written in C/C + + language, and provides a linux user mode program hot patching solution.
In some embodiments, the consistency detection method provided by the embodiment of the present invention is applied to the technical field of hot patching of linux user-state software written in C/C + + language of an X8664 architecture.
According to the consistency detection method provided by the embodiment of the invention, each thread automatically backtracks the current function call chain, so that on one hand, the ptrace debugging technology provided by a kernel is not required to be relied on, and the frequent switching between a user state and a kernel state is avoided; in another aspect, threads may perform the backtracking process in parallel rather than sequentially backtracking one by one. Compared with the scheme using the ptrace debugging technology, the comprehensive performance is improved qualitatively, the backtracking time is reduced, and the influence on the program is relatively small. In addition, the consistency detection method in the embodiment of the invention detects whether the thread function in each layer in each thread function calling chain is the patched function or not, and does not detect only the first layer, so the consistency detection is complete, and as long as each thread passes the detection, the consistency of the program state after patching can be ensured, thereby improving the reliability of the hot patching technology.
EXAMPLE III
As shown in fig. 5, an embodiment of the present invention further provides a hot patch file generating apparatus, where the hot patch file generating apparatus 500 includes:
a first obtaining module 501, configured to obtain a first target file in a first project before modification and a second target file in a second project after modification, where the first target file and the second target file are files in which a difference exists between corresponding storage nodes of the first project and the second project;
a second obtaining module 502, configured to obtain a first source file name for generating the first target file and a second source file name for generating the second target file;
a third obtaining module 503, configured to obtain a first main program source file list of a first main program, a first dynamic library source file list of a first dynamic library, a second main program source file list of a second main program, and a second dynamic library source file list of a second dynamic library, where the first main program and the first dynamic library belong to the first project, and the second main program and the second dynamic library belong to the second project;
a first determining module 504, configured to determine attribution information of the first target file and the second target file, where the attribution information is determined according to the first source file name, the second source file name, the first main program source file list, the second main program source file list, the first dynamic library source file list, and the second dynamic library source file list, and the attribution information includes any one of: belonging to a first dynamic library, belonging to a second dynamic library, belonging to a first main program and belonging to a second main program;
a fourth obtaining module 505, configured to obtain a main program difference function, and generate a first intermediate hot patch file, where the first intermediate hot patch file includes identification information, the identification information includes a main program identifier, and the main program difference function includes a function that a difference exists between a first target file belonging to a first main program and a second target file belonging to a second main program on a corresponding node;
a fifth obtaining module 506, configured to obtain a dynamic library difference function, and generate a second intermediate hot patch file, where the second intermediate hot patch file includes identification information, the identification information includes a dynamic library identifier, and the dynamic library difference function includes a function that a difference exists between a first target file belonging to the first dynamic library and a second target file belonging to the second dynamic library on a corresponding node;
an encapsulating module 507, configured to encapsulate the first intermediate hot patch file and the second intermediate hot patch file, and generate a hot patch file.
It should be noted that the hot patch file generation apparatus provided in this embodiment includes other modules to implement the steps of the hot patch file generation method described in each embodiment, and specific functions of each module may refer to the description in the above hot patch file generation method embodiment, which is not described herein again.
The hot patch file generation apparatus provided in this embodiment finally generates a hot patch file, where the hot patch file is formed by encapsulating a second intermediate hot patch file belonging to the dynamic library and a first intermediate hot patch file belonging to the main program, and identification information is recorded in the first and second intermediate hot patch files. Whether the patch functions in the first and second intermediate hot patch files correspond to the main program or the dynamic library of the source program can be obtained. On one hand, the hot patch generation process can be automatically completed, a manufacturer does not need to know the details of a program, only needs to know how to construct a target project, and after the first project and the second project before and after construction and modification are completed, the rest steps are realized in an automatic mode, so that the hot patch file generation efficiency is improved, the steps of manual operation are simplified, the user experience is improved, and an operator only needs to specify a patch file during hot patch making without knowing the details of the program and the patch. The usability is very high, errors cannot be caused due to the reason of operators, and the reliability of the hot patching technology is improved; on the other hand, the generated hot patch file records the identification information of each patch function, so that whether the function corresponds to the main program or the dynamic library of the source program to be patched can be known, and the risk of patching failure or patching error caused by the fact that the patched function cannot be accurately determined due to the fact that the identification information of the patch function is unknown when the main program and the dynamic library of the source program have the same function is reduced. .
Example four
As shown in fig. 6, an embodiment of the present invention further provides a consistency detection apparatus, where the consistency detection apparatus 600 includes:
a sixth obtaining module 601, configured to obtain the identification information of the full path and the patched function of the hot patch file;
a seventh obtaining module 602, configured to obtain source program call stack information of a source program;
a parallel backtracking module 603, configured to perform parallel backtracking on current function call chains of each thread according to the source program call stack information, where each thread of a current process of the source program is a current process of the thread;
a detecting module 604, configured to traverse thread functions in each layer in the current function call chain, and perform consistency detection, where the consistency detection includes determining a thread state of the thread according to the identification information, and the thread state includes a blocking state or a continuous operation;
a second determining module 605, configured to determine a result of the consistency detection according to the thread status of each of the threads.
It should be noted that the consistency detection apparatus provided in this embodiment includes other modules to implement the steps of the consistency detection method described in each embodiment, and specific functions of each module may refer to the description in the above consistency detection method embodiment, and are not described herein again.
According to the consistency detection device provided by the embodiment of the invention, as each thread automatically backtracks the current function call chain, on one hand, the ptrace debugging technology provided by the kernel is not required to be relied on, and the frequent switching between the user state and the kernel state is avoided; in another aspect, threads may perform the backtracking process in parallel rather than sequentially backtracking one by one. Compared with the scheme using ptrace debugging technology, the comprehensive performance is improved substantially. In addition, the consistency detection device in the embodiment of the invention detects whether the thread function in each layer in each thread function calling chain is the patched function or not, and does not detect only the first layer, so that the consistency detection is complete, and as long as each thread passes the detection, the consistency of the program state after patching can be ensured, thereby improving the reliability of the hot patching technology.
EXAMPLE five
As shown in fig. 7, an embodiment of the present invention further provides a first device 700, where the first device 700 includes a first memory 701, a first processor 702, a first program stored on the first memory 701 and executable on the first processor 702, and a first data bus 703 for implementing connection communication between the first processor 702 and the first memory 701, and the first program, when executed by the first processor 702, implements the steps of the hot patch file generation method according to any one of the above embodiments.
The first device provided by this embodiment finally generates a hot patch file, where the hot patch file is formed by packaging a second intermediate hot patch file belonging to the dynamic library and a first intermediate hot patch file belonging to the main program, and identification information is recorded in the first and second intermediate hot patch files, so that it can be known whether the function corresponds to the main program or the dynamic library of the source program to be patched, and therefore, when the main program and the dynamic library of the source file have the same function, the risk of patching failure or patching error due to the fact that the patched function cannot be accurately determined because the identification information of the patched function is unknown is reduced. The hot patch generation process can be automatically completed, a manufacturer does not need to know the details of a program, only needs to know how to construct a target project, and after the project before and after modification is constructed, the rest steps are realized in an automatic mode, so that the hot patch file generation efficiency is improved, the manual operation steps are simplified, the user experience is improved, the attribution information of each patched function is recorded in the generated hot patch file, an operator only needs to specify the patch file during hot patch application, and the details of the program and the patch do not need to be known. The usability is very high, errors cannot be caused due to the reason of operators, and the reliability of the hot patching technology is improved.
EXAMPLE six
As shown in fig. 8, the embodiment of the present invention further provides a second device 800, where the second device includes a second memory 801, a second processor 802, a second program stored on the second memory 801 and operable on the second processor 802, and a second data bus 803 for implementing connection communication between the second processor 802 and the second memory 801, and the second program, when executed by the second processor 802, implements the steps of the consistency detection method according to any one of the embodiments described above.
According to the second device provided by the embodiment of the invention, as each thread automatically backtracks the current function call chain, on one hand, the ptrace debugging technology provided by the kernel is not required to be relied on, and the frequent switching between the user mode and the kernel mode is avoided; in another aspect, threads may perform the backtracking process in parallel rather than sequentially backtracking one by one. Compared with the scheme using ptrace debugging technology, the comprehensive performance is improved substantially. In addition, the consistency detection method in the embodiment of the invention detects whether the thread function in each layer in each thread function calling chain is the patched function or not, and does not detect only the first layer, so the consistency detection is complete, and as long as each thread passes the detection, the consistency of the program state after patching can be ensured, thereby improving the reliability of the hot patching technology.
The embodiment of the present invention further provides a storage medium for computer-readable storage, where the storage medium stores one or more first programs, and the one or more first programs are executable by one or more first processors to implement the steps of the hot-patch file generation method according to any one of the above embodiments;
or the like, or, alternatively,
the storage medium stores one or more second programs, which are executable by one or more second processors to implement the steps of the consistency detection method of any of the above embodiments.
One of ordinary skill in the art will appreciate that all or some of the steps of the methods, systems, functional modules/units in the devices disclosed above may be implemented as software, firmware, hardware, and suitable combinations thereof.
In a hardware implementation, the division between functional modules/units mentioned in the above description does not necessarily correspond to the division of physical components; for example, one physical component may have multiple functions, or one function or step may be performed by several physical components in cooperation. Some or all of the physical components may be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on computer readable media, which may include computer storage media (or non-transitory media) and communication media (or transitory media). The term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data, as is well known to those of ordinary skill in the art. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, Digital Versatile Disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can accessed by a computer. In addition, communication media typically embodies computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism and includes any information delivery media as known to those skilled in the art.
The preferred embodiments of the present invention have been described above with reference to the accompanying drawings, and are not to be construed as limiting the scope of the invention. Any modifications, equivalents and improvements which may occur to those skilled in the art without departing from the scope and spirit of the present invention are intended to be within the scope of the claims.

Claims (21)

1. A hot patch file generation method includes:
acquiring a first target file in a first project before modification and a second target file in a second project after modification, wherein the first target file and the second target file are files with difference on corresponding storage nodes of the first project and the second project respectively;
acquiring a first source file name for generating the first target file and a second source file name for generating the second target file;
acquiring a first main program source file list of a first main program, a first dynamic library source file list of a first dynamic library, a second main program source file list of a second main program and a second dynamic library source file list of a second dynamic library, wherein the first main program and the first dynamic library belong to the first project, and the second main program and the second dynamic library belong to the second project;
determining attribution information of the first target file and the second target file, wherein the attribution information is determined according to the first source file name, the second source file name, the first main program source file list, the second main program source file list, the first dynamic library source file list and the second dynamic library source file list, and the attribution information comprises any one of the following information: belonging to a first dynamic library, belonging to a second dynamic library, belonging to a first main program and belonging to a second main program;
acquiring a main program difference function, and generating a first intermediate hot patch file, wherein the first intermediate hot patch file comprises identification information, the identification information comprises a main program identification, and the main program difference function comprises a function which is different between a first target file belonging to a first main program and a second target file belonging to a second main program on a corresponding node;
acquiring a dynamic library difference function, and generating a second intermediate hot patch file, wherein the second intermediate hot patch file comprises identification information, the identification information comprises a dynamic library identification, and the dynamic library difference function comprises a function of a difference between a first target file belonging to a first dynamic library and a second target file belonging to a second dynamic library on a corresponding node;
and packaging the first intermediate hot patch file and the second intermediate hot patch file to generate a hot patch file.
2. The method for generating a hot patch file according to claim 1, wherein before the acquiring the first target file in the first project before modification and the second target file in the second project after modification, the method further comprises:
respectively constructing a first project before modification and a second project after modification under the same directory according to compiling parameters of debugging information, wherein compiling paths of homonymous binary files of the first project and the second project are the same;
the first target file and the second target file are files with difference in the binary files with the same name of the first project and the second project respectively.
3. A hot patch file generation method as claimed in claim 2, wherein said obtaining a first source file name for generating said first target file and a second source file name for generating said second target file comprises:
analyzing debugging information of the first target file to obtain a name of the first source file;
and analyzing the debugging information of the second target file to obtain the name of the second source file.
4. The method for generating a hot patch file according to claim 2, wherein the obtaining a first main program source file list of a first main program, a first dynamic library source file list of a first dynamic library, a second main program source file list of a second main program, and a second dynamic library source file list of a second dynamic library comprises:
analyzing debugging information of the first main program to obtain a first main program source file list;
analyzing debugging information of the second main program to obtain a second main program source file list;
analyzing debugging information of the first dynamic library to obtain a source file list of the first dynamic library;
and analyzing the debugging information of the second dynamic library to obtain a source file list of the second dynamic library.
5. The method of claim 2, wherein obtaining a main program difference function to generate a first intermediate hot patch file and obtaining a dynamic library difference function to generate a second intermediate hot patch file comprises:
according to the attribution information, the first target file is respectively linked to generate a first main program intermediate file and a first dynamic library intermediate file;
according to the attribution information, the second target file is respectively linked to generate a second main program intermediate file and a second dynamic library intermediate file;
extracting a function with difference in the same-name binary files in the first main program intermediate file and the second main program intermediate file as a main program difference function, and generating a first intermediate hot patch file according to the main program difference function;
and extracting a function with difference in the same-name binary files in the first dynamic library intermediate file and the second dynamic library intermediate file as the dynamic library difference function, and generating the second intermediate hot patch file according to the dynamic library difference function.
6. The method as claimed in claim 5, wherein the generating a first main program intermediate file and a first dynamic library intermediate file by linking the first target file according to the attribution information, and generating a second main program intermediate file and a second dynamic library intermediate file by linking the second target file according to the attribution information respectively comprises:
comparing the project directories of the first project and the second project to generate a target file list, wherein each node in the target file list comprises a full path name of the first target file and a full path name of the second target file with the same name;
according to the attribution information, the first target file is linked step by step according to the path information recorded by the target file list to generate a first main program intermediate file and a first dynamic library intermediate file;
and according to the attribution information, linking the second target file step by step according to the path information recorded by the target file list to generate a second main program intermediate file and a second dynamic library intermediate file.
7. A method for generating a hotpatch file as claimed in any one of claims 1 to 6, wherein said method further comprises at least one of:
in the hot patch file, the first intermediate hot patch file and the second intermediate hot patch file are respectively stored as an independent section;
the hot patch file includes main program information.
8. A consistency detection method, characterized in that the consistency detection method comprises:
acquiring the identification information of the full path and the patched function of the hot patch file;
acquiring source program call stack information of a source program;
according to the source program call stack information, each thread of the current process of the source program backtracks the current function call chain of each thread in parallel;
traversing thread functions in each layer in the current function call chain, and performing consistency detection, wherein the consistency detection comprises determining thread states of the threads according to the identification information, and the thread states comprise a blocking state or continuous operation;
determining a result of the coherency detection based on the thread states of the threads.
9. The coherency detection method of claim 8 wherein said determining a thread state of the thread in accordance with the identification information comprises:
and detecting that the patched function is not included in the thread function, and enabling the thread to enter a blocking state.
10. The coherency detection method according to claim 9, wherein the determining the result of the coherency detection in dependence on the thread state of each of the threads comprises:
and each thread enters a blocking state, and the consistency detection of the source program is successful.
11. The consistency detection method according to claim 10, wherein each of the threads enters a blocking state, and after the consistency detection of the source program is successful, the method further comprises:
performing hot patching operation on the source program;
and after the operation of hot patching is finished, the running of all the threads is recovered.
12. The coherency detection method of claim 8 wherein said determining a thread state of the thread in accordance with the identification information comprises:
detecting that the thread function comprises a patched function, and continuing running the thread;
and carrying out the consistency detection on the thread again at preset time intervals.
13. The coherency detection method according to claim 12, wherein the determining the result of the coherency detection in dependence on the thread state of each of the threads comprises:
if the thread is not in the blocking state, acquiring the detection times of the consistency detection of the thread;
if the detection times are larger than a preset detection time threshold value, restoring the normal operation of each thread in the blocking state;
the consistency check of the source program fails.
14. The consistency detection method according to any one of claims 8 to 13, wherein after obtaining the source program call stack information of the source program, the method further comprises:
sending a signal to each thread, wherein the signal is a non-dedicated signal;
after receiving the signal, the threads call stack information according to the source program, and the threads of the current process of the source program backtrack the current function call chains of the threads in parallel.
15. The coherency detection method of any one of claims 8 to 13 wherein said determining a thread state of the thread in dependence on the identification information comprises:
acquiring identification information of the patched function, wherein the identification information comprises a main program identifier or a dynamic library identifier;
the source program call stack information comprises main program call stack information of the source program and dynamic library call stack information of the source program;
according to the calling stack information of the main program, each thread of the main program of the current process of the source program backtracks the current function calling chain of each thread in parallel;
according to the dynamic library call stack information, each thread of a dynamic library of the current process of the source program backtracks the current function call chain of each thread in parallel;
determining the thread state of the thread of the main program according to the identification information of the patched function of which the identification information comprises a main program identification;
determining a thread state of the thread of the dynamic library according to the identification information of the patched function of which the identification information comprises dynamic library identification.
16. The coherency detection method according to any one of claims 8 to 13, wherein, after determining the result of the coherency detection according to the thread state of each of the threads, further comprising:
and clearing the call stack information of the source program.
17. A hot-patch file generation apparatus, characterized by comprising:
the system comprises a first acquisition module, a second acquisition module and a third acquisition module, wherein the first acquisition module is used for acquiring a first target file in a first project before modification and a second target file in a second project after modification, and the first target file and the second target file are files with difference on corresponding storage nodes of the first project and the second project respectively;
a second obtaining module, configured to obtain a first source file name for generating the first target file and a second source file name for generating the second target file;
a third obtaining module, configured to obtain a first main program source file list of a first main program, a first dynamic library source file list of a first dynamic library, a second main program source file list of a second main program, and a second dynamic library source file list of a second dynamic library, where the first main program and the first dynamic library belong to the first project, and the second main program and the second dynamic library belong to the second project;
a first determining module, configured to determine attribution information of the first target file and the second target file, where the attribution information is determined according to the first source file name, the second source file name, the first main program source file list, the second main program source file list, the first dynamic library source file list, and the second dynamic library source file list, and the attribution information includes any one of: belonging to a first dynamic library, belonging to a second dynamic library, belonging to a first main program and belonging to a second main program;
a fourth obtaining module, configured to obtain a main program difference function, and generate a first intermediate hot patch file, where the first intermediate hot patch file includes identification information, the identification information includes a main program identifier, and the main program difference function includes a function that is different between a first target file belonging to a first main program and a second target file belonging to a second main program on a corresponding node;
a fifth obtaining module, configured to obtain a dynamic library difference function, and generate a second intermediate hot patch file, where the second intermediate hot patch file includes identification information, the identification information includes a dynamic library identifier, and the dynamic library difference function includes a function that a difference exists between a first target file belonging to the first dynamic library and a second target file belonging to the second dynamic library on a corresponding node;
and the packaging module is used for packaging the first intermediate hot patch file and the second intermediate hot patch file to generate a hot patch file.
18. An agreement detection apparatus, characterized by comprising:
a sixth obtaining module, configured to obtain identification information of a full path and a patched function of a hot patch file;
a seventh obtaining module, configured to obtain source program call stack information of a source program;
the parallel backtracking module is used for backtracking the current function call chain of each thread according to the call stack information of the source program by each thread of the current process of the source program in parallel;
a detection module, configured to traverse thread functions in each layer in the current function call chain, and perform consistency detection, where the consistency detection includes determining a thread state of the thread according to the identification information, and the thread state includes a blocking state or continuous operation;
a second determining module, configured to determine a result of the consistency detection according to the thread state of each thread.
19. A first device, characterized in that the first device comprises a first memory, a first processor, a first program stored on the first memory and executable on the first processor, and a first data bus for enabling connection communication between the first processor and the first memory, the first program, when executed by the first processor, implementing the steps of the hot patch file generation method as claimed in any one of claims 1 to 7.
20. A second device, characterized in that the second device comprises a second memory, a second processor, a second program stored on the second memory and executable on the second processor, and a second data bus for enabling connection communication between the second processor and the second memory, the second program, when executed by the second processor, implementing the steps of the consistency detection method as claimed in any one of claims 8 to 16.
21. A medium for computer-readable storage, characterized in that,
the storage medium storing one or more first programs executable by one or more first processors to perform the steps of the method of generating a hotpatch file according to any one of claims 1 to 7;
or the like, or, alternatively,
the storage medium stores one or more second programs executable by one or more second processors to implement the steps of the consistency detection method of any one of claims 8 to 16.
CN202010534121.XA 2020-06-12 2020-06-12 Hot patch file generation and consistency detection method, device, equipment and medium Pending CN113805928A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202010534121.XA CN113805928A (en) 2020-06-12 2020-06-12 Hot patch file generation and consistency detection method, device, equipment and medium
PCT/CN2021/099526 WO2021249518A1 (en) 2020-06-12 2021-06-10 Hotfix file generation and consistency detection methods and apparatuses, and device and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010534121.XA CN113805928A (en) 2020-06-12 2020-06-12 Hot patch file generation and consistency detection method, device, equipment and medium

Publications (1)

Publication Number Publication Date
CN113805928A true CN113805928A (en) 2021-12-17

Family

ID=78846885

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010534121.XA Pending CN113805928A (en) 2020-06-12 2020-06-12 Hot patch file generation and consistency detection method, device, equipment and medium

Country Status (2)

Country Link
CN (1) CN113805928A (en)
WO (1) WO2021249518A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115687159A (en) * 2022-12-29 2023-02-03 飞腾信息技术有限公司 Debugging method, debugging device and computer readable storage medium

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8607208B1 (en) * 2008-10-01 2013-12-10 Oracle International Corporation System and methods for object code hot updates
US8468516B1 (en) * 2008-12-19 2013-06-18 Juniper Networks, Inc. Creating hot patches for embedded systems
US9569199B2 (en) * 2015-01-22 2017-02-14 Futurewei Technologies, Inc. Systems and methods to update source code files
CN105159738A (en) * 2015-08-20 2015-12-16 上海斐讯数据通信技术有限公司 Hot patch implementation method and system
CN105630557B (en) * 2015-12-24 2018-12-28 迈普通信技术股份有限公司 Hot patch method and apparatus
CN110851168A (en) * 2019-11-15 2020-02-28 腾讯科技(深圳)有限公司 Data processing method and device and computer readable storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115687159A (en) * 2022-12-29 2023-02-03 飞腾信息技术有限公司 Debugging method, debugging device and computer readable storage medium
CN115687159B (en) * 2022-12-29 2023-03-21 飞腾信息技术有限公司 Debugging method, debugging device and computer readable storage medium

Also Published As

Publication number Publication date
WO2021249518A1 (en) 2021-12-16

Similar Documents

Publication Publication Date Title
CN105630463B (en) For detecting the method and device of JAR packet conflict
US20080282229A1 (en) Apparatus and method of detecting errors in embedded software
CN105988798B (en) Patch processing method and device
US8327191B2 (en) Automatically populating symptom databases for software applications
US20060107121A1 (en) Method of speeding up regression testing using prior known failures to filter current new failures when compared to known good results
US9892017B2 (en) Automatic repair of scripts
CN109032838B (en) Automatic verification method for consistency of backup and recovery data of virtual machine
CN109840194B (en) Method and system for detecting configuration file
US11422920B2 (en) Debugging multiple instances of code using thread patterns
US20140208297A1 (en) Validation of revised computer programs
CN112965913A (en) Method for automatically repairing dependency conflict problem of Java software
WO2021249518A1 (en) Hotfix file generation and consistency detection methods and apparatuses, and device and medium
CN108804239B (en) Platform integration method and device, computer equipment and storage medium
CN111984524A (en) Fault injection method, fault simulation method, fault injection device, and storage medium
US20040117780A1 (en) Method and system for detecting and resolving unnecessary source module dependencies
CN111240987A (en) Migration program detection method and device, electronic equipment and computer readable storage medium
CN113392006B (en) Method and equipment for monitoring automatic test logs by using capsules
CN112631599B (en) Compiling method, compiling device and storage medium
CN113568834A (en) SDK code compatibility detection method, device, computer equipment and medium
CN115469844A (en) Code processing method, system, computer cluster, medium, and program product
CN110990261A (en) Test management system, method and platform
CN113760340B (en) Hot patching method and device applied to Linux system
CN116149707B (en) Method and device for detecting and avoiding upgrading risk of distributed system
CN114356643B (en) Automatic task discovery failure and recovery method in remote sensing satellite processing system
CN114675735A (en) Configuration and power management interface table debugging method, chip debugging method, equipment and medium

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