Debugging Optimized Code Steven Osman Debugging Optimized Code
Debugging Optimized Code Steven Osman
Debugging Optimized Code is Hard… Un-optimized code has a correlation between source and object code Optimizing compilers rearrange, add and remove code. This results in: Code location problems l Data value problems l
Talk Overview Understanding the problems Introducing Source-Level Debugging of Scalar Optimized Code Classifying data-value problems Identifying data-value problems What’s next?
The Code Location Problem Source S 1: S 2: S 3: S 4: y=0; a=b+c; x=2; y=z*3; We want a Optimized Assembly I 1: ld r 1, b <S 2> I 2: ld r 2, c <S 2> I 3: ld r 5, z <S 4> I 4: mul r 6, r 5, 3 <S 4> breakpoint at S 2 I 5: mov r 4, 2 <S 3> I 6: add r 3, r 1, r 2
The Data-Value Problem Source S 1: S 2: S 3: S 4: y=0; a=b+c; x=2; y=z*3; What is the value Optimized Assembly I 1: ld r 1, b <S 2> I 2: ld r 2, c <S 2> I 3: ld r 5, z <S 4> I 4: mul r 6, r 5, 3 of<S 4> y at S 2? I 5: mov r 4, 2 <S 3> I 6: add r 3, r 1, r 2
Source-Level Debugging of Scalar Optimized Code By Ali-Reza Adl-Tabatabai and Thomas Gross Identifies data-value problems No changes to the optimized code Uses knowledge of optimizations
Some Simple Terminology Expected value = value a variable should have Actual value = value stored in register Current = Actual value IS expected value (true for all in unoptimzed code) Endangered = Not current Noncurrent = Actual IS NOT expected l Suspect = Actual may be expected l
Code Hoisting E 0: x=u-v E 1: x=y+z Bkpt 1 Bkpt 2 E 2: x=y+z Bkpt 3
Code Hoisting E 0: x=u-v E 1: x=y+z E 3: x=y+z Bkpt 1 Bkpt 2 E 2: x=y+z Bkpt 3 E 2=Red. Copy(E 3)
Hoist Reaches E 0: x=u-v E 1: x=y+z E 3: x=y+z Bkpt 1 Bkpt 2 E 2: x=y+z Bkpt 3 E 2=Red. Copy(E 3)
Dead Code Elimination E 0: x=y+z Bkpt 1 Bkpt 3 E 1: …=x Bkpt 2 Bkpt 4 Bkpt 5 E 2: x=u-v Bkpt 6
Dead Code Elimination E 0: x=y+z Bkpt 1 Bkpt 3 E 3: x=y+z Bkpt 2 E 1: …=x Bkpt 4 Bkpt 5 E 2: x=u-v Bkpt 6
Dead Reaching E 0: x=y+z Bkpt 1 Bkpt 3 E 3: x=y+z Bkpt 2 E 1: …=x Bkpt 4 Bkpt 5 E 2: x=u-v Bkpt 6
What’s Next? Good paper, but it only warns programmer Suggestions about how to get the expected value Alok Ladsariya’s talk…
- Slides: 14