Method and apparatus for debugging of optimized code using emulation
First Claim
1. A method for debugging a machine code of a program that has been subjected to an optimizing action, wherein the machine code may have been reordered, duplicated, eliminated or transformed so as not to correspond with the program'"'"'s source code order, said method comprising the steps of:
- a) deriving a table which associates each machine code instruction with a source construct for which it was generated;
b) setting one or more breakpoints in said source code;
c) determining at least one corresponding location for a breakpoint in said machine code through use of said table;
d) executing, by emulation, only machine code instructions which correspond to source constructs that precede said breakpoint in said source code order to provide for a user, execution of a sequence of said machine code instructions in accordance with a sequence of corresponding source constructs;
e) emulating the machine code instructions in the order in which instructions appear in the machine code; and
f) comparing results of steps d) and e) and if a difference is detected in an effect produced by any emulated instruction, indicating a bug or an optimizer error.
3 Assignments
0 Petitions
Accused Products
Abstract
The invention is a method for debugging a machine code of a program that has been subjected to an optimizing action, wherein the machine code may have been reordered, duplicated, eliminated or transformed so as not to correspond with the program'"'"'s source code order. The method derives a table which associates each machine code instruction with a source construct for which it was generated. The user sets a breakpoint at a breakpoint P in the source code where execution is to stop. Then the method determines at least one corresponding location for the breakpoint in the machine code through use of the table, and executes, by native execution or emulation, only machine code instructions which correspond to source constructs that precede the breakpoint in the source code order. The method further enables a comparison of the results of two passes of emulation (in different orders) to detect a class of bugs that are particularly hard to find: bugs caused by optimizer errors and user bugs that manifest themselves only in the optimized executable.
-
Citations
18 Claims
-
1. A method for debugging a machine code of a program that has been subjected to an optimizing action, wherein the machine code may have been reordered, duplicated, eliminated or transformed so as not to correspond with the program'"'"'s source code order, said method comprising the steps of:
-
a) deriving a table which associates each machine code instruction with a source construct for which it was generated;
b) setting one or more breakpoints in said source code;
c) determining at least one corresponding location for a breakpoint in said machine code through use of said table;
d) executing, by emulation, only machine code instructions which correspond to source constructs that precede said breakpoint in said source code order to provide for a user, execution of a sequence of said machine code instructions in accordance with a sequence of corresponding source constructs;
e) emulating the machine code instructions in the order in which instructions appear in the machine code; and
f) comparing results of steps d) and e) and if a difference is detected in an effect produced by any emulated instruction, indicating a bug or an optimizer error. - View Dependent Claims (2, 3, 4, 5, 6, 7, 8, 9)
enabling recovery of variable state(s) after each instruction has been executed by said emulation.
-
-
4. The method as recited in claim 1, wherein step c) further comprises:
c1) establishing a high watermark (HW) at each first machine code instruction in said machine code that derives from a source construct occurring after said breakpoint and is a commitpoint, where a commitpoint is a first such machine code instruction on a path from a procedure entry to a point in said machine code where control flowing to that point is a confirmation that said breakpoint has been encountered.
-
5. The method as recited in claim 4, wherein step c) further comprises:
c2) establishing a low watermark (LW) at each last machine code instruction in said machine code that derives from a source construct occurring before said breakpoint and is a last such machine code instruction on a path from (i) a commitpoint in said machine code, to (ii) a procedure exit point.
-
6. The method as recited in claim 5, wherein step d) further comprises:
d1) selectively executing by emulation machine code instructions which lie between said HW and said LW.
-
7. The method as recited in claim 1, further comprising the step of:
upon encountering a loop or a function call, discontinuing said emulation of step d) and natively executing said loop or function call.
-
8. The method as recited in claim 1, wherein steps b), c) and d) are performed by a debugging procedure.
-
9. The method as recited in claim 1, wherein step d), upon encountering a pre-breakpoint machine code instruction after a post breakpoint conditional branch machine code instruction, either emulates said pre-breakpoint machine code instruction if a branch outcome can be determined via emulation, or selects a sequence of subsequent instructions for execution.
-
10. A memory media for controlling a computer to debug a machine code of a program that has been subjected to an optimizing action, wherein the machine code may have been reordered, duplicated, eliminated or transformed so as not to correspond with the program'"'"'s source code order, said memory media comprising:
-
a) means for controlling said computer to derive a table which associates each machine code instruction with a source construct for which it was generated;
b) means for controlling said computer to set one or more breakpoints in said source code;
c) means for controlling said computer to determine at least one corresponding location for a breakpoint in said machine code through use of said table;
d) means for controlling said computer to execute, by emulation, only machine code instructions which correspond to source constructs that precede said breakpoint in said source code order to provide for a user, execution of a sequence of said machine code instructions in accordance with a sequence of corresponding source constructs;
e) means for controlling said computer to emulate the machine code instructions in the order in which instructions appear in the machine code; and
f) means for controlling said computer to compare results determined by means d) and e) and if a difference is detected in an effect produced by any emulated instruction, to indicate a bug or an optimizer error. - View Dependent Claims (11, 12, 13, 14, 15, 16, 17, 18)
means for controlling said computer to enable recovery of variable state(s) after each instruction has been executed by said emulation.
-
-
13. The memory media as recited in claim 10, wherein means c) further comprises:
c1) means for controlling said computer to establish a high watermark (HW) at each first machine code instruction in said machine code that derives from a source construct occurring after said breakpoint and is a commitpoint, where a commitpoint is a first such machine code instruction on a path from a procedure entry to a point in said machine code where control flowing to that point is a confirmation that said breakpoint has been encountered.
-
14. The memory media as recited in claim 13, wherein means c) further comprises:
c2) means for controlling said computer to establish a low watermark (LW) at each last machine code instruction in said machine code that derives from a source construct occurring before said breakpoint and is a last such machine code instruction on a path from (i) a commitpoint in said machine code, to (ii) a procedure exit point.
-
15. The memory media as recited in claim 14, wherein means d) further comprises:
d1) means for controlling said computer to selectively execute, by emulation, machine code instructions which lie between said HW and said LW.
-
16. The memory media as recited in claim 10, further comprising:
means for controlling said computer, in response to encountering a loop or a function call, to discontinue said emulation by means d) and to natively execute said loop or function call.
-
17. The memory media as recited in claim 10, wherein means b), c) and d) are comprise portions of a debugging procedure.
-
18. The memory media as recited in claim 10, wherein means d), upon encountering a pre-breakpoint machine code instruction after a post breakpoint conditional branch machine code instruction, either emulates said pre-breakpoint machine code instruction if a branch outcome can be determined via emulation, or selects a sequence of subsequent instructions for execution.
Specification