/*
Copyright (C) 2006 Evan Teran
                   eteran@alum.rit.edu

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef DEBUGGERCOREINTERFACE_20061101_H_
#define DEBUGGERCOREINTERFACE_20061101_H_

#include <QtPlugin>
#include <QByteArray>
#include <QMap>
#include "types.h"

class QString;

class DebuggerCoreInterface {
public:
	virtual ~DebuggerCoreInterface() {}
	
public:
	// BreakPoint meta-data
	
	// this represents how many bytes we should rewind EIP
	// after a breakpoint is hit
	virtual int executionBreakPointSize() const = 0;
	virtual QByteArray executionBreakPointData() const = 0;
	
public:
	typedef QMap<BaseTypes::address_t, BreakPoint> BreakPointState;
	
public:
	// returns true on success, false on failure, all bytes must be successfully 
	// read/written in order for a success. The debugged application should be stopped
	// or this will return false immidiately.
	virtual bool writeBytes(BaseTypes::address_t address, const void *buf, std::size_t len) = 0;
	virtual bool readBytes(BaseTypes::address_t address, void *buf, std::size_t len) = 0;
	
public:
	virtual bool open(const QString &path, const QString &args = "") = 0;
	virtual bool attach(BaseTypes::pid_t pid) = 0;
	virtual void detach() = 0;
	virtual void kill() = 0;
	virtual void pause() = 0;
	virtual void resume(int signum) = 0;
	virtual void step(int signum) = 0;
	virtual void getState(State &state) = 0;
	virtual void setState(const State &state) = 0;
	virtual void waitForDebugEvent(DebugEvent *event, bool &ok, int secs) = 0;
	
public:
	virtual BaseTypes::address_t getFaultAddress() = 0;
	
public:
	// basic breakpoint managment
	virtual void addBreakpoint(BaseTypes::address_t address, bool oneTime = false) = 0;
	virtual void removeBreakpoint(BaseTypes::address_t address) = 0;
	virtual void disableBreakpoint(BaseTypes::address_t address) = 0;
	virtual void enableBreakpoint(BaseTypes::address_t address) = 0;
	virtual void backupBreakPoints(BreakPointState &state) const = 0;
	virtual const BreakPoint *findBreakPoint(BaseTypes::address_t address) const = 0;

public:
	// what is the PID of the process we are currently debugging
	virtual BaseTypes::pid_t pid() const = 0;
};

Q_DECLARE_INTERFACE(DebuggerCoreInterface, "EDB.DebuggerCoreInterface/1.0")


#endif
