Title: Debugging Optimized Code
1Debugging Optimized Code
2Debugging 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
- Data value problems
3Talk Overview
- Understanding the problems
- Introducing Source-Level Debugging of Scalar
Optimized Code - Classifying data-value problems
- Identifying data-value problems
- Whats next?
4The Code Location Problem
Source S1 y0 S2 abc S3 x2 S4 yz3 Optimized Assembly I1 ld r1, b ltS2gt I2 ld r2, c ltS2gt I3 ld r5, z ltS4gt I4 mul r6, r5, 3 ltS4gt I5 mov r4, 2 ltS3gt I6 add r3, r1, r2 ltS2gt
We want a breakpoint at S2
5The Data-Value Problem
Source S1 y0 S2 abc S3 x2 S4 yz3 Optimized Assembly I1 ld r1, b ltS2gt I2 ld r2, c ltS2gt I3 ld r5, z ltS4gt I4 mul r6, r5, 3 ltS4gt I5 mov r4, 2 ltS3gt I6 add r3, r1, r2 ltS2gt
What is the value of y at S2?
6Source-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
7Some 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
- Suspect Actual may be expected
8Code Hoisting
E0 xu-v
E1 xyz
Bkpt1
Bkpt2 E2 xyz Bkpt3
9Code Hoisting
E0 xu-v
E1 xyz
E3 xyz Bkpt1
Bkpt2 E2 xyz Bkpt3
E2RedCopy(E3)
10Hoist Reaches
E0 xu-v
E1 xyz
E3 xyz Bkpt1
Bkpt2 E2 xyz Bkpt3
E2RedCopy(E3)
11Dead Code Elimination
E0 xyz Bkpt1
Bkpt3 E1 x Bkpt4
Bkpt2
Bkpt5 E2 xu-v Bkpt6
12Dead Code Elimination
E0 xyz Bkpt1
Bkpt3 E3 xyz E1 x Bkpt4
Bkpt2
Bkpt5 E2 xu-v Bkpt6
13Dead Reaching
E0 xyz Bkpt1
Bkpt3 E3 xyz E1 x Bkpt4
Bkpt2
Bkpt5 E2 xu-v Bkpt6
14Whats Next?
- Good paper, but it only warns programmer
- Suggestions about how to get the expected value
- Alok Ladsariyas talk