/*
Copyright (C) 2006 - 2009 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 <QSharedPointer>
#include "Breakpoint.h"

class QString;
class QStringList;
class State;
class DebugEvent;

class DebuggerCoreInterface {
public:
	virtual ~DebuggerCoreInterface() {}
	
	enum EVENT_STATUS {
		DEBUG_CONTINUE,
		DEBUG_EXCEPTION_NOT_HANDLED
	};
	
public:
	// system information
	virtual edb::address_t pageSize() const = 0;
	
public:
	typedef QMap<edb::address_t, QSharedPointer<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 immediately.
	virtual bool writeBytes(edb::address_t address, const void *buf, std::size_t len) = 0;
	virtual bool readBytes(edb::address_t address, void *buf, std::size_t len) = 0;
	virtual bool readPages(edb::address_t address, void *buf, std::size_t count) = 0;
	
public:
	// thread support stuff (optional)
	virtual QList<edb::tid_t> threadIDs() const	{ return QList<edb::tid_t>(); }
	virtual edb::tid_t activeThread() const		{ return static_cast<edb::tid_t>(-1); }
	virtual void setActiveThread(edb::tid_t)	{}

public:
	virtual bool open(const QString &path, const QString &cwd, const QStringList &args, const QString &tty) = 0;
	virtual bool open(const QString &path, const QString &cwd, const QStringList &args) = 0;
	virtual bool attach(edb::pid_t pid) = 0;
	virtual void detach() = 0;
	virtual void kill() = 0;
	virtual void pause() = 0;
	virtual void resume(EVENT_STATUS status) = 0;
	virtual void step(EVENT_STATUS status) = 0;
	virtual void getState(State &state) = 0;
	virtual void setState(const State &state) = 0;
	virtual bool waitForDebugEvent(DebugEvent &event, int msecs) = 0;
	
public:
	// basic breakpoint managment
	virtual int breakpointSize() const = 0;
	virtual void setBreakpointCondition(edb::address_t address, const QString &condition) = 0;
	virtual QString getBreakpointCondition(edb::address_t address) = 0;
	virtual void addBreakpoint(edb::address_t address, bool oneTime = false) = 0;
	virtual void removeBreakpoint(edb::address_t address) = 0;
	virtual edb::address_t disableBreakpoint(edb::address_t address) = 0;
	virtual edb::address_t enableBreakpoint(edb::address_t address) = 0;
	virtual BreakpointState backupBreakpoints() const = 0;
	virtual QSharedPointer<Breakpoint> findBreakpoint(edb::address_t address) = 0;
	virtual void clearBreakpoints() = 0;
public:
	// what is the PID of the process we are currently debugging
	virtual edb::pid_t pid() const = 0;
};

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


#endif
