Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Fix bad debug info due to 64-bit registers alignment
Browse files Browse the repository at this point in the history
- Registers of LocalStart and LocalSnapshot must also be shift when it is required.

Bug: 16344305

(cherry picked from commit 32631e6)

Change-Id: Ic437ed4102ad0fbeccc069df0f44cb2d774ff27d
  • Loading branch information
mikaelpeltier authored and Sebastien Hertz committed Jul 21, 2014
1 parent cd2b099 commit 34ac540
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
13 changes: 13 additions & 0 deletions dx/src/com/android/dx/dex/code/DalvInsn.java
Expand Up @@ -19,9 +19,11 @@
import com.android.dx.rop.code.RegisterSpec;
import com.android.dx.rop.code.RegisterSpecList;
import com.android.dx.rop.code.SourcePosition;
import com.android.dx.ssa.RegisterMapper;
import com.android.dx.util.AnnotatedOutput;
import com.android.dx.util.Hex;
import com.android.dx.util.TwoColumnOutput;

import java.util.BitSet;

/**
Expand Down Expand Up @@ -380,6 +382,17 @@ public final int getNextAddress() {
return getAddress() + codeSize();
}

/**
* Returns an instance that is just like this one, except that the
* register list is mapped by using {@code mapper}.
*
* @param mapper {@code non-null;} used to map registers
* @return {@code non-null;} an appropriately-constructed instance
*/
public DalvInsn withMapper(RegisterMapper mapper) {
return withRegisters(mapper.map(getRegisters()));
}

/**
* Gets the size of this instruction, in 16-bit code units.
*
Expand Down
7 changes: 7 additions & 0 deletions dx/src/com/android/dx/dex/code/LocalSnapshot.java
Expand Up @@ -20,6 +20,7 @@
import com.android.dx.rop.code.RegisterSpecList;
import com.android.dx.rop.code.RegisterSpecSet;
import com.android.dx.rop.code.SourcePosition;
import com.android.dx.ssa.RegisterMapper;

/**
* Pseudo-instruction which is used to hold a snapshot of the
Expand Down Expand Up @@ -93,4 +94,10 @@ protected String listingString0(boolean noteIndices) {

return sb.toString();
}

/** {@inheritDoc} */
@Override
public DalvInsn withMapper(RegisterMapper mapper) {
return new LocalSnapshot(getPosition(), mapper.map(locals));
}
}
7 changes: 7 additions & 0 deletions dx/src/com/android/dx/dex/code/LocalStart.java
Expand Up @@ -19,6 +19,7 @@
import com.android.dx.rop.code.RegisterSpec;
import com.android.dx.rop.code.RegisterSpecList;
import com.android.dx.rop.code.SourcePosition;
import com.android.dx.ssa.RegisterMapper;

/**
* Pseudo-instruction which is used to introduce a new local variable. That
Expand Down Expand Up @@ -95,4 +96,10 @@ protected String argString() {
protected String listingString0(boolean noteIndices) {
return "local-start " + localString(local);
}

/** {@inheritDoc} */
@Override
public DalvInsn withMapper(RegisterMapper mapper) {
return new LocalStart(getPosition(), mapper.map(local));
}
}
6 changes: 5 additions & 1 deletion dx/src/com/android/dx/dex/code/OutputFinisher.java
Expand Up @@ -870,6 +870,8 @@ private void shiftAllRegisters(int delta) {

for (int i = 0; i < insnSize; i++) {
DalvInsn insn = insns.get(i);
// Since there is no need to replace CodeAddress since it does not use registers, skips it to
// avoid to update all TargetInsn that contain a reference to CodeAddress
if (!(insn instanceof CodeAddress)) {
insns.set(i, insn.withRegisterOffset(delta));
}
Expand All @@ -892,8 +894,10 @@ private void shiftParameters(int delta) {

for (int i = 0; i < insnSize; i++) {
DalvInsn insn = insns.get(i);
// Since there is no need to replace CodeAddress since it does not use registers, skips it to
// avoid to update all TargetInsn that contain a reference to CodeAddress
if (!(insn instanceof CodeAddress)) {
insns.set(i, insn.withRegisters(mapper.map(insn.getRegisters())));
insns.set(i, insn.withMapper(mapper));
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions dx/src/com/android/dx/ssa/RegisterMapper.java
Expand Up @@ -18,6 +18,7 @@

import com.android.dx.rop.code.RegisterSpec;
import com.android.dx.rop.code.RegisterSpecList;
import com.android.dx.rop.code.RegisterSpecSet;

/**
* Represents a mapping between two register numbering schemes.
Expand Down Expand Up @@ -57,4 +58,26 @@ public final RegisterSpecList map(RegisterSpecList sources) {
// Return the old sources if nothing has changed.
return newSources.equals(sources) ? sources : newSources;
}

/**
*
* @param sources old register set
* @return new mapped register set, or old if nothing has changed.
*/
public final RegisterSpecSet map(RegisterSpecSet sources) {
int sz = sources.getMaxSize();
RegisterSpecSet newSources = new RegisterSpecSet(getNewRegisterCount());

for (int i = 0; i < sz; i++) {
RegisterSpec registerSpec = sources.get(i);
if (registerSpec != null) {
newSources.put(map(registerSpec));
}
}

newSources.setImmutable();

// Return the old sources if nothing has changed.
return newSources.equals(sources) ? sources : newSources;
}
}

0 comments on commit 34ac540

Please sign in to comment.