TESTING AND DEBUGGING OF DYNAMIC BINARY TRANSLATION
A method for testing and debugging of dynamic binary translation wherein a dynamic binary translator allows a target binary to be executed transparently on a host machine having a different computer architecture than the target machine involves selecting a minimum set of target machine states for simulation at run-time. A series of target machine instructions from the target binary is translated into a series of host machine instructions. During translation, a plurality of check points are inserted into the series of host machine instructions. During translation, a plurality of verification points are inserted into the series of host machine instructions. The series of host machine instructions, including the check points and verification points, are executed. Execution of a check point determines a simulated target machine state. Execution of a verification point sends information pertaining to simulated target machine states to an external verifier.
Latest SUN MICROSYSTEMS, INC. Patents:
1. Field of the Invention
The invention relates to a dynamic binary translator or virtual processor with which target binaries may be executed transparently on a host machine of a different computer architecture. The invention further relates to testing and debugging of dynamic binary translation.
2. Background Art
A dynamic binary translator is a virtual processor, implemented in software, that allows a target binary or executable file to be executed transparently on a host machine having a different computer architecture. In more detail, at run-time, the binary translator translates non-native code in the target binary into native code recognized by the host machine to produce the same program behavior as is generated when the target binary is executed on the target platform.
Dynamic binary translation allows the same software binaries to be executed on host machines having different computer architectures. For example, a binary for SPARC architecture may execute natively on a SPARC processor, and dynamic binary translation may be used to execute this same binary on a processor having a different architecture.
When implementing a dynamic binary translator, it is necessary to perform testing and debugging to assure that a program behaves the same way when executing on the target platform as when executing on a host machine of a different architecture that uses the dynamic binary translator at run-time. A commonly-used way to check for the correctness of program behavior is to match the outputs of running the same program on both the host and target machines. Unfortunately, having a matched output does not guarantee that dynamic translation is correct. An error can still exist without affecting the program output.
For the foregoing reasons, there is a desire to develop an improved approach to testing and debugging dynamic binary translation to ensure the preciseness of the translations and to allow debugging to pinpoint the cause when program errors occur.
SUMMARY OF THE INVENTIONIt is an object of the invention to provide a method for testing and debugging of dynamic binary translation.
Each binary executable is generally an instruction flow at run-time. The machine state at the boundary of each execution unit, which for most modern computers is one instruction, is fixed and is deterministic. For correct execution of the binary, the machine state at each boundary must be exactly the same as expected by the designer of the machine's instruction set.
For dynamic binary translation where the target binary is translated at run-time into instructions for a host machine having a different architecture than the target architecture for which the binary was compiled, the target instructions are translated into host machine instructions and rescheduled often times. Accordingly, the execution units and their boundaries are likely to be blurred.
In accordance with the invention, a method for testing and debugging dynamic binary translation comprehends three components.
In one aspect of the invention, a minimum set of target machine states are selected. For this set of target machine states, the dynamic translator must simulate these states at run-time. These states are used to determine the correctness of the translation.
In another aspect of the invention, check points are inserted into the translated code to collect these simulated machine states. A check point is a special piece of code that uses the information saved by the translated code to reconstruct the target machine states in the selected minimum set for run-time simulation. In a base implementation, these machine states are present in the translated code and would not need to be reconstructed.
The check points are inserted at the virtual boundary of a target instruction and can be set up either following every instruction to be translated or only a selected set of the target instructions. If the translation causes overlapping of the actions of two consecutive target instructions (for example, by code coalescence and scheduling), the method may look for the next available check point or the level of translation aggressiveness may be lowered to enforce the establishment of the check points.
In a further aspect of the invention, verification points are inserted into the translated code to communicate with an external verifier to check the correctness of execution. The verification points can be inserted after completion of one or several check points. The verification point pieces together the machine states collected by the prior check points and sends this information out to the external verifier.
The external verifier may be a target machine simulator running on the same host machine or a remote debugger running on a real target machine. In operation of the method, the verifier repeatedly receives the machine states sent from the verification points and compares these with its own data to determine if the execution of the dynamic translation up to that moment is proceeding correctly. The result is communicated back to the verification points so that a log may be written to and execution may be stopped if anything goes wrong.
There are many advantages associated with embodiments of the invention. Conventional compiler testing only compares the output result to determine correctness. A dynamic binary translator needs to produce the correct output result. In addition, the translator cannot relax the precise architecture state model of execution unless instructed to do so by the user. Testing such a system can be troublesome since different users can relax different rules for preciseness. In accordance with embodiments of the invention, by using a separate architecture simulator that has already been utilized for hardware verification as a verifier, the machine states during execution can be stamped as the same as that of the underlying hardware processor. The advantage of the simulator is that all architecture states can be exported at anytime. By establishing the check points and the verification points and by selecting the proper condition of comparison with the translator, proper testing and debugging can be performed.
At run-time, the target binary 30 is translated by dynamic binary translator 32 into instructions for the host machine processor 34. In more detail, dynamic binary translator 32 produces a series of x86 instructions 50. Translation may involve rescheduling of instructions such that the execution units 44 and their boundaries become blurred. An example of blurred execution units and boundaries is indicated at 56.
As mentioned, the target machine states at the execution unit boundaries are fixed and deterministic. A minimum set of target machine states are selected for which the dynamic binary translator 32 must simulate these states at run-time so that these states may be used to determine the correctness of the translation. These simulated machine states are collected by check points 54. A check point 54 is a special piece of code that uses the information saved by the translated code to determine or reconstruct the target machine states at the (virtual) execution unit boundary 52.
During translation, the check points 54 are inserted at the virtual boundary 52 of a target execution unit 44 and can be set up either following every execution unit 44 to be translated or only a selected set of the execution units 44, which in this case are the target instructions. If the translation causes overlapping of the actions of two consecutive target instructions as illustrated at 56 (for example, by code coalescence and scheduling), the method may look for the next available check point 54 or the level of translation aggressiveness may be lowered to enforce the establishment of the check points 54.
In more detail, the architecture accurate simulator/emulator 70 is used to generate cycle accurate architecture state for the host machine. The dynamic binary translator 32 is the target execution library which performs the instruction translation for the target binary. The state comparator 72 takes the architecture states from both the architecture accurate simulator/emulator 70 and the dynamic binary translator 32 (information sent by a verification point) and performs the necessary tasks to determine if any violation of the architecture states occurred. All three components are glued together by the communicator 74, which transmits architecture states and actions to be performed between the components. These four components can be threads within the same process, different processes, or any combination in between. An alternative implementation is not restricted to these four components. Some or all of the components may be combined. Each component may be further divided into subcomponents.
In general, the actions taken by the example implementation illustrated in
1. Synchronize between all the components to a single known architecture state.
2. Simulator 70 and translator 32 (via a verification point) communicate architecture states to the comparator 72.
3. Comparator 72 determines the correctness of the translated states.
4. Take action when state error is discovered.
When action is taken due to discovery of a state error, several actions are possible. One possibility is to stop execution, and print out the error and the states involved. Instead of quitting the execution, another possibility is to try to compensate for the succeeding states. Another possibility is to try to re-synchronize to a future known state.
The example implementation can also be configured to do different types of comparison. One approach is to compare all instructions translated by the translator on the target instruction boundary. Another approach is to compare on a set boundary for a group of target instructions. Another approach is to compare on a preset number of instructions, where the number can be small or large. Another example is to compare on each transfer of flow of control, such as branch instructions. The comparison can involve accurate per target instruction state. Or, the comparison can involve a unique summary of a group of target instructions.
It is appreciated that embodiments of the invention are not limited to any particular target machine or host machine architecture. In general, the invention comprehends the insertion of check and verification points that gather and send state-related information to a verifier for use in testing and debugging dynamic binary translation. The examples described herein illustrate a particular implementation and other implementations are possible.
Further, it is to be appreciated that a dynamic binary translator translates the instructions from a target architecture to a host architecture. The target architecture can be any architecture, including a different architecture than the host architecture, the same architecture as the host architecture with the same implementation, or the same architecture as the host architecture with a different implementation (for example, different extensions).
When the host machine and target machine are the same architecture, dynamic binary translation can be used, for example, to optimize for more performance, use features not available, translate instructions not implemented, or correct a bug in the implementation.
While embodiments of the invention have been illustrated and described, it is not intended that these embodiments illustrate and describe all possible forms of the invention. Rather, the words used in the specification are words of description rather than limitation, and it is understood that various changes may be made without departing from the spirit and scope of the invention.
Claims
1. A method for testing and debugging of dynamic binary translation wherein a dynamic binary translator allows a target binary to be executed transparently on a host machine having a different computer architecture than the target machine, and wherein, at run-time, the dynamic binary translator translates the target binary to produce the same program behavior on the host machine as when the target binary is executed on the target machine, the method comprising:
- selecting a minimum set of target machine states for simulation at run-time;
- translating a series of target machine instructions from the target binary into a series of host machine instructions;
- during translation, inserting a plurality of check points into the series of host machine instructions;
- during translation, inserting a plurality of verification points into the series of host machine instructions;
- executing the series of host machine instructions, including the check points and verification points;
- wherein the execution of a check point determines a simulated target machine state; and
- wherein the execution of a verification point sends information pertaining to simulated target machine states to an external verifier.
2. The method of claim 1 wherein the execution of a check point reconstructs a simulated target machine state.
3. The method of claim 1 wherein inserting the plurality of check points further comprises:
- inserting a check point in the series of host machine instructions at a virtual boundary of a target machine instruction.
4. The method of claim 1 wherein inserting the plurality of check points further comprises:
- inserting a check point in the series of host machine instructions at each virtual boundary of each target machine instruction.
5. The method of claim 1 wherein inserting the plurality of check points further comprises:
- inserting a check point in the series of host machine instructions at each virtual boundary of each target machine instruction in a selected set of target machine instructions.
6. The method of claim 1 wherein inserting the plurality of check points further comprises:
- attempting to insert a check point in the series of host machine instructions at a virtual boundary of a target machine instruction; and
- in the event that the virtual boundary is blurred due to overlapping of the host machine instructions for at least two target machine instructions, omitting the insertion of the check point at the blurred virtual boundary.
7. The method of claim 1 wherein inserting the plurality of check points further comprises:
- attempting to insert a check point in the series of host machine instructions at a virtual boundary of a target machine instruction; and
- in the event that the virtual boundary is blurred due to overlapping of the host machine instructions for at least two target machine instructions, reducing an aggressiveness of the dynamic binary translation.
8. The method of claim 1 wherein inserting the plurality of verification points further comprises:
- inserting a verification point after the insertion of a plurality of check points.
9. The method of claim 1 wherein the external verifier is a target machine simulator running on the host machine.
10. The method of claim 1 wherein the external verifier is a remote debugger running on a real target machine.
11. A system for testing and debugging of dynamic binary translation, the system comprising:
- a dynamic binary translator for translating a target binary to allow the target binary to be executed transparently on a host machine having a different computer architecture than the target machine;
- an architecture accurate emulator for emulating the target machine states;
- an architecture comparator for comparing an architecture state from the dynamic binary translator and an architecture state from the architecture accurate emulator;
- wherein the dynamic binary translator translates a series of target machine instructions from the target binary into a series of host machine instructions, inserts a plurality of check points into the series of host machine instructions, and inserts a plurality of verification points into the series of host machine instructions;
- wherein the execution of a check point determines a simulated target machine state; and
- wherein the execution of a verification point sends information pertaining to simulated target machine states to the architecture comparator.
12. The system of claim 11 wherein the execution of a check point reconstructs a simulated target machine state.
13. The system of claim 11 wherein the dynamic binary translator is configured to insert a check point in the series of host machine instructions at a virtual boundary of a target machine instruction.
14. The system of claim 11 wherein the dynamic binary translator is configured to insert a check point in the series of host machine instructions at each virtual boundary of each target machine instruction.
15. The system of claim 11 wherein the dynamic binary translator is configured to insert a check point in the series of host machine instructions at each virtual boundary of each target machine instruction in a selected set of target machine instructions.
16. The system of claim 11 wherein the dynamic binary translator is configured to attempt to insert a check point in the series of host machine instructions at a virtual boundary of a target machine instruction; and
- in the event that the virtual boundary is blurred due to overlapping of the host machine instructions for at least two target machine instructions, the insertion of the check point at the blurred virtual boundary is omitted.
17. The system of claim 11 wherein the dynamic binary translator is configured to attempt to insert a check point in the series of host machine instructions at a virtual boundary of a target machine instruction; and
- in the event that the virtual boundary is blurred due to overlapping of the host machine instructions for at least two target machine instructions, an aggressiveness of the dynamic binary translation is reduced.
18. The system of claim 11 wherein the dynamic binary translator is configured to insert a verification point after the insertion of a plurality of check points.
Type: Application
Filed: Sep 30, 2007
Publication Date: Apr 2, 2009
Patent Grant number: 8230402
Applicant: SUN MICROSYSTEMS, INC. (Santa Clara, CA)
Inventors: William Y. Chen (Los Altos, CA), Jiwei Lu (Pleasanton, CA), Geetha K. Vallabhaneni (Fremont, CA)
Application Number: 11/865,024
International Classification: G06F 9/44 (20060101);