OffsetSet instrSuccOffsets(Op* opc, const Unit* unit) { OffsetSet succBcOffs; Op* bcStart = (Op*)(unit->entry()); if (!instrIsControlFlow(*opc)) { Offset succOff = opc + instrLen(opc) - bcStart; succBcOffs.insert(succOff); return succBcOffs; } if (instrAllowsFallThru(*opc)) { Offset succOff = opc + instrLen(opc) - bcStart; succBcOffs.insert(succOff); } if (isSwitch(*opc)) { foreachSwitchTarget(opc, [&](Offset& offset) { succBcOffs.insert(offset + opc - bcStart); }); } else { Offset target = instrJumpTarget(bcStart, opc - bcStart); if (target != InvalidAbsoluteOffset) { succBcOffs.insert(target); } } return succBcOffs; }
OffsetSet instrSuccOffsets(PC opc, const Unit* unit) { OffsetSet succBcOffs; auto const bcStart = unit->entry(); auto const op = peek_op(opc); if (!instrIsControlFlow(op)) { Offset succOff = opc + instrLen(opc) - bcStart; succBcOffs.insert(succOff); return succBcOffs; } if (instrAllowsFallThru(op)) { Offset succOff = opc + instrLen(opc) - bcStart; succBcOffs.insert(succOff); } if (isSwitch(op)) { foreachSwitchTarget(opc, [&](Offset offset) { succBcOffs.insert(offset + opc - bcStart); }); } else { Offset target = instrJumpTarget(bcStart, opc - bcStart); if (target != InvalidAbsoluteOffset) { succBcOffs.insert(target); } } return succBcOffs; }
/** * Return the number of successor-edges including fall-through paths but not * implicit exception paths. */ int numSuccs(const Opcode* instr) { if (!instrIsControlFlow(*instr)) return 1; if ((instrFlags(*instr) & TF) != 0) { if (Op(*instr) == OpSwitch) return *(int*)(instr + 1); if (Op(*instr) == OpJmp) return 1; return 0; } if (instrJumpOffset(const_cast<Opcode*>(instr))) return 2; return 1; }
// Place internal breakpoints to get out of the current function. This may place // multiple internal breakpoints, and it may place them more than one frame up. // Some instructions can cause PHP to be invoked without an explicit call. A set // which causes a destructor to run, a iteration init which causes an object's // next() method to run, a RetC which causes destructors to run, etc. This // recgonizes such cases and ensures we have internal breakpoints to cover the // destination(s) of such instructions. void CmdFlowControl::setupStepOuts() { // Existing step outs should be cleaned up before making new ones. assert(!hasStepOuts()); auto fp = g_context->getFP(); if (!fp) return; // No place to step out to! Offset returnOffset; bool fromVMEntry; while (!hasStepOuts()) { fp = g_context->getPrevVMState(fp, &returnOffset, nullptr, &fromVMEntry); // If we've run off the top of the stack, just return having setup no // step outs. This will cause cmds like Next and Out to just let the program // run, which is appropriate. if (!fp) break; Unit* returnUnit = fp->m_func->unit(); PC returnPC = returnUnit->at(returnOffset); TRACE(2, "CmdFlowControl::setupStepOuts: at '%s' offset %d opcode %s\n", fp->m_func->fullName()->data(), returnOffset, opcodeToName(*reinterpret_cast<const Op*>(returnPC))); // Don't step out to generated functions, keep looking. if (fp->m_func->line1() == 0) continue; if (fromVMEntry) { TRACE(2, "CmdFlowControl::setupStepOuts: VM entry\n"); // We only execute this for opcodes which invoke more PHP, and that does // not include switches. Thus, we'll have at most two destinations. assert(!isSwitch(*reinterpret_cast<const Op*>(returnPC)) && (numSuccs(reinterpret_cast<const Op*>(returnPC)) <= 2)); // Set an internal breakpoint after the instruction if it can fall thru. if (instrAllowsFallThru(*reinterpret_cast<const Op*>(returnPC))) { Offset nextOffset = returnOffset + instrLen((Op*)returnPC); TRACE(2, "CmdFlowControl: step out to '%s' offset %d (fall-thru)\n", fp->m_func->fullName()->data(), nextOffset); m_stepOut1 = StepDestination(returnUnit, nextOffset); } // Set an internal breakpoint at the target of a control flow instruction. // A good example of a control flow op that invokes PHP is IterNext. if (instrIsControlFlow(*reinterpret_cast<const Op*>(returnPC))) { Offset target = instrJumpTarget(reinterpret_cast<const Op*>(returnPC), 0); if (target != InvalidAbsoluteOffset) { Offset targetOffset = returnOffset + target; TRACE(2, "CmdFlowControl: step out to '%s' offset %d (jump target)\n", fp->m_func->fullName()->data(), targetOffset); m_stepOut2 = StepDestination(returnUnit, targetOffset); } } // If we have no place to step out to, then unwind another frame and try // again. The most common case that leads here is Ret*, which does not // fall-thru and has no encoded target. } else { TRACE(2, "CmdFlowControl: step out to '%s' offset %d\n", fp->m_func->fullName()->data(), returnOffset); m_stepOut1 = StepDestination(returnUnit, returnOffset); } } }
/** * Return the number of successor-edges including fall-through paths but not * implicit exception paths. */ int numSuccs(const Op* instr) { if ((instrFlags(*instr) & TF) != 0) { if (isSwitch(*instr)) { return *(int*)(instr + 1); } if (isUnconditionalJmp(*instr) || *instr == OpIterBreak) return 1; return 0; } if (!instrIsControlFlow(*instr)) return 1; if (instrJumpOffset(const_cast<Op*>(instr))) return 2; return 1; }
/** * Return the number of successor-edges including fall-through paths but not * implicit exception paths. */ int numSuccs(PC const origPC) { auto pc = origPC; auto const op = decode_op(pc); if ((instrFlags(op) & TF) != 0) { if (isSwitch(op)) { return decode_raw<int32_t>(pc); } if (isUnconditionalJmp(op) || op == OpIterBreak) return 1; return 0; } if (!instrIsControlFlow(op)) return 1; if (instrJumpOffset(origPC)) return 2; return 1; }
bool instrIsNonCallControlFlow(Op opcode) { if (!instrIsControlFlow(opcode) || isFCallStar(opcode)) return false; switch (opcode) { case OpContEnter: case OpFCallBuiltin: case OpIncl: case OpInclOnce: case OpReq: case OpReqOnce: case OpReqDoc: return false; default: return true; } }
/** * Return the number of successor-edges including fall-through paths but not * implicit exception paths. */ int numSuccs(PC const origPC) { auto pc = origPC; auto const op = decode_op(pc); if ((instrFlags(op) & TF) != 0) { if (isSwitch(op)) { if (op == Op::Switch) { decode_raw<SwitchKind>(pc); // skip bounded flag decode_raw<int64_t>(pc); // skip base } return decode_raw<int32_t>(pc); // vector length } if (isUnconditionalJmp(op) || op == OpIterBreak) return 1; return 0; } if (!instrIsControlFlow(op)) return 1; if (instrJumpOffset(origPC)) return 2; return 1; }
bool instrIsNonCallControlFlow(Op opcode) { if (!instrIsControlFlow(opcode) || isFCallStar(opcode)) return false; switch (opcode) { case OpAwait: case OpYield: case OpYieldK: case OpContEnter: case OpContRaise: case OpContEnterDelegate: case OpYieldFromDelegate: case OpFCallBuiltin: case OpIncl: case OpInclOnce: case OpReq: case OpReqOnce: case OpReqDoc: return false; default: return true; } }