#include "config.h"
#include "debugger.h"
#include "ustring.h"
#include "internal.h"
using namespace KJS;
namespace KJS {
struct AttachedInterpreter
{
public:
AttachedInterpreter(Interpreter *i, AttachedInterpreter *ai) : interp(i), next(ai) { ++Debugger::debuggersPresent; }
~AttachedInterpreter() { --Debugger::debuggersPresent; }
Interpreter *interp;
AttachedInterpreter *next;
};
}
int Debugger::debuggersPresent = 0;
Debugger::Debugger()
{
rep = new DebuggerImp();
}
Debugger::~Debugger()
{
detach(0);
delete rep;
}
void Debugger::attach(Interpreter* interp)
{
Debugger *other = interp->debugger();
if (other == this)
return;
if (other)
other->detach(interp);
interp->setDebugger(this);
rep->interps = new AttachedInterpreter(interp, rep->interps);
}
void Debugger::detach(Interpreter* interp)
{
AttachedInterpreter **p = &rep->interps;
AttachedInterpreter *q;
while ((q = *p)) {
if (!interp || q->interp == interp) {
*p = q->next;
q->interp->setDebugger(0);
delete q;
} else
p = &q->next;
}
if (interp)
latestExceptions.remove(interp);
else
latestExceptions.clear();
}
bool Debugger::hasHandledException(ExecState *exec, JSValue *exception)
{
if (latestExceptions.get(exec->dynamicInterpreter()).get() == exception)
return true;
latestExceptions.set(exec->dynamicInterpreter(), exception);
return false;
}
bool Debugger::sourceParsed(ExecState*, int , const UString &,
const UString &, int , int , const UString & )
{
return true;
}
bool Debugger::sourceUnused(ExecState*, int )
{
return true;
}
bool Debugger::exception(ExecState*, int , int ,
JSValue* )
{
return true;
}
bool Debugger::atStatement(ExecState*, int , int ,
int )
{
return true;
}
bool Debugger::callEvent(ExecState*, int , int ,
JSObject* , const List &)
{
return true;
}
bool Debugger::returnEvent(ExecState*, int , int ,
JSObject* )
{
return true;
}