fixed bugs with switch bytecodes in Dalvik.

ignore exceptions in callgraph construction when they are ignored in
bytecode from Dalvik.
This commit is contained in:
Julian Dolby 2015-11-13 19:25:23 -05:00
parent d010e36923
commit 2b2543cfbb
4 changed files with 16 additions and 13 deletions

View File

@ -426,11 +426,11 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
protected static boolean hasUniqueCatchBlock(SSAAbstractInvokeInstruction call, IR ir) {
ISSABasicBlock[] bb = ir.getBasicBlocksForCall(call.getCallSite());
if (bb.length == 1) {
Iterator it = ir.getControlFlowGraph().getExceptionalSuccessors(bb[0]).iterator();
Iterator<ISSABasicBlock> it = ir.getControlFlowGraph().getExceptionalSuccessors(bb[0]).iterator();
// check that there's exactly one element in the iterator
if (it.hasNext()) {
it.next();
return (!it.hasNext());
if (it.hasNext()) {
ISSABasicBlock sb = it.next();
return (!it.hasNext() && (sb.isExitBlock() || ((sb instanceof ExceptionHandlerBasicBlock) && ((ExceptionHandlerBasicBlock)sb).getCatchInstruction() != null)));
}
}
return false;

View File

@ -705,7 +705,7 @@ public class DexIMethod implements IBytecodeMethod {
protected void parseBytecode() {
org.jf.dexlib.Code.Instruction[] instrucs = eMethod.codeItem.getInstructions();
// for (org.jf.dexlib.Code.Instruction inst: instrucs)
// for (org.jfmethod.getInstructionIndex(.dexlib.Code.Instruction inst: instrucs)
// {
// switch (inst.getFormat())
// {
@ -2264,8 +2264,6 @@ public class DexIMethod implements IBytecodeMethod {
currentCodeAddress += inst.getSize(currentCodeAddress);
}
//// comment out start
//// Instruction[] iinstructions = new Instruction[instrucs.length];
// instructions = new InsructionArray();

View File

@ -156,6 +156,9 @@ public class InstructionArray implements Collection<Instruction> {
* @return The index of the instruction of given byte code index
*/
public int getIndexFromPc(int pc) {
if (!pc2index.containsKey(pc) && pc2index.containsKey(pc+1)) {
pc++;
}
return pc2index.get(pc);
}
@ -185,5 +188,4 @@ public class InstructionArray implements Collection<Instruction> {
return instructions.get(pc2index.get(pc));
}
}

View File

@ -75,10 +75,13 @@ public class Switch extends Instruction {
private void computeCasesAndLabels() {
casesAndLabels = pad.getLabelsAndOffsets();
for (int i = 1; i < casesAndLabels.length; i+=2)
casesAndLabels[i] = method.getInstructionIndex(pc+casesAndLabels[i]);
defaultLabel = method.getInstructionIndex(pc + pad.getDefaultOffset());
// casesAndLabels[i] = method.getInstructionIndex(pc+casesAndLabels[i]);
casesAndLabels[i] = pc+casesAndLabels[i];
// defaultLabel = method.getInstructionIndex(pc + pad.getDefaultOffset());
defaultLabel = pc + pad.getDefaultOffset();
}
public int[] getOffsets()
@ -98,9 +101,9 @@ public class Switch extends Instruction {
@Override
public int[] getBranchTargets() {
int[] r = new int[casesAndLabels.length / 2 + 1];
r[0] = defaultLabel;
r[0] = method.getInstructionIndex(defaultLabel);
for (int i = 1; i < r.length; i++) {
r[i] = casesAndLabels[(i - 1) * 2 + 1];
r[i] = method.getInstructionIndex(casesAndLabels[(i - 1) * 2 + 1]);
}
return r;
}