void printChoices() { int i = 0; SystemState ss = vm.getSystemState(); ChoiceGenerator<?>[] cgStack = ss.getChoiceGenerators(); nextChoice: for (ChoiceGenerator<?> cg : cgStack) { if (isRelevantCG(cg) && !cg.isDone()) { Object choice = cg.getNextChoice(); if (choice == null) { continue; } else { if (excludes != null) { for (String e : excludes) { if (choice.toString().startsWith(e)) { continue nextChoice; } } } } String line = null; switch (format) { case CHOICE: line = choice.toString(); if (line.startsWith("gov.nasa.jpf.jvm.")) { line = line.substring(17); } break; case CG: line = cg.toString(); if (line.startsWith("gov.nasa.jpf.jvm.choice.")) { line = line.substring(24); } break; } if (line != null) { pw.print(String.format("%4d: ", i++)); pw.print(line); if (showLocation) { String loc = cg.getSourceLocation(); if (loc != null) { pw.println(); pw.print(" \tat "); pw.print(loc); } } pw.println(); } } } }
@Override public Instruction execute(SystemState ss, KernelState ks, ThreadInfo ti) { StackFrame sf = ti.getTopFrame(); IntegerExpression sym_v1 = (IntegerExpression) sf.getOperandAttr(1); IntegerExpression sym_v2 = (IntegerExpression) sf.getOperandAttr(0); if ((sym_v1 == null) && (sym_v2 == null)) { // both conditions are concrete // System.out.println("Execute IF_ICMPEQ: The conditions are concrete"); return super.execute(ss, ks, ti); } else { // at least one condition is symbolic ChoiceGenerator<?> cg; if (!ti.isFirstStepInsn()) { // first time around cg = new PCChoiceGenerator(2); ss.setNextChoiceGenerator(cg); return this; } else { // this is what really returns results cg = ss.getChoiceGenerator(); assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg; conditionValue = (Integer) cg.getNextChoice() == 0 ? false : true; } int v2 = ti.pop(); int v1 = ti.pop(); // System.out.println("Execute IF_ICMPEQ: "+ conditionValue); PathCondition pc; // pc is updated with the pc stored in the choice generator above // get the path condition from the // previous choice generator of the same type ChoiceGenerator<?> prev_cg = cg.getPreviousChoiceGenerator(); while (!((prev_cg == null) || (prev_cg instanceof PCChoiceGenerator))) { prev_cg = prev_cg.getPreviousChoiceGenerator(); } if (prev_cg == null) pc = new PathCondition(); else pc = ((PCChoiceGenerator) prev_cg).getCurrentPC(); assert pc != null; if (conditionValue) { if (sym_v1 != null) { if (sym_v2 != null) { // both are symbolic values pc._addDet(Comparator.EQ, sym_v1, sym_v2); } else pc._addDet(Comparator.EQ, sym_v1, v2); } else pc._addDet(Comparator.EQ, v1, sym_v2); if (!pc.simplify()) { // not satisfiable ss.setIgnored(true); } else { // pc.solve(); ((PCChoiceGenerator) cg).setCurrentPC(pc); // System.out.println(((PCChoiceGenerator) cg).getCurrentPC()); } return getTarget(); } else { if (sym_v1 != null) { if (sym_v2 != null) { // both are symbolic values pc._addDet(Comparator.NE, sym_v1, sym_v2); } else pc._addDet(Comparator.NE, sym_v1, v2); } else pc._addDet(Comparator.NE, v1, sym_v2); if (!pc.simplify()) { // not satisfiable ss.setIgnored(true); } else { // pc.solve(); ((PCChoiceGenerator) cg).setCurrentPC(pc); // System.out.println(((PCChoiceGenerator) cg).getCurrentPC()); } return getNext(ti); } } }