/*
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 DEBUGGERCORE_20060430_H_
#define DEBUGGERCORE_20060430_H_

#include "DebuggerCoreInterface.h"

class DebuggerCore : public QObject, public DebuggerCoreInterface {
	Q_OBJECT
	Q_INTERFACES(DebuggerCoreInterface)
	
public:
	DebuggerCore();
	virtual ~DebuggerCore();
	
public:
	virtual int executionBreakPointSize() const;
	virtual QByteArray executionBreakPointData() const;
	
public:
	virtual bool writeBytes(BaseTypes::address_t address, const void *buf, std::size_t len);
	virtual bool readBytes(BaseTypes::address_t address, void *buf, std::size_t len);
	
public:
	virtual bool open(const QString &path, const QString &args = "");
	virtual bool attach(BaseTypes::pid_t pid);
	virtual void detach();
	virtual void kill();
	virtual void pause();
	virtual void resume(int signum);
	virtual void step(int signum);
	virtual void getState(State &state);
	virtual void setState(const State &state);
	virtual void waitForDebugEvent(DebugEvent *event, bool &ok, int secs);
	
public:
	virtual BaseTypes::address_t getFaultAddress();
	
public:
	virtual void addBreakpoint(BaseTypes::address_t address, bool oneTime = false);
	virtual void removeBreakpoint(BaseTypes::address_t address);
	virtual void disableBreakpoint(BaseTypes::address_t address);
	virtual void enableBreakpoint(BaseTypes::address_t address);
	virtual void backupBreakPoints(BreakPointState &state) const;
	virtual const BreakPoint *findBreakPoint(BaseTypes::address_t address) const;

public:
	virtual BaseTypes::pid_t pid() const;
	
private:
	void writeByte(BaseTypes::address_t address, uint8_t value, bool *ok = 0);
	void writeByteBase(BaseTypes::address_t address, uint8_t value, bool &ok);
	uint8_t readByte(BaseTypes::address_t address, bool *ok = 0);
	uint8_t readByteBase(BaseTypes::address_t address, bool &ok);

private:
	BaseTypes::pid_t	m_PID;
	BreakPointState		m_BreakPoints;
};

#endif
