
#ifndef DEBUGGEROPS_20090424_H_
#define DEBUGGEROPS_20090424_H_

#include "State.h"
#include "Debugger.h"
#include "Instruction.h"
#include "DebuggerCoreInterface.h"

template<class F1, class F2>
void stepOver(F1 runFunc, F2 stepFunc) {
	const edb::address_t ip = edb::v1::currentState().instructionPointer();

	quint8 buffer[edb::Instruction::MAX_SIZE];
	int sz = sizeof(buffer);

	if(edb::v1::getInstructionBytes(ip, buffer, sz)) {
		edb::Instruction insn(buffer, sz, 0, std::nothrow);
		if(insn.valid()) {
			if(edb::v1::archProcessor().canStepOver(insn)) {
				// add a temporary breakpoint at the instruction just 
				// after the call
				edb::v1::debuggerBase->addBreakpoint(ip + insn.size(), true);

				runFunc();
				return;
			}
		}
	}

	// if all else fails, it's a step into
	stepFunc();
}

#endif
