debugger.cpp

00001 // -*- c-basic-offset: 2 -*-
00002 /*
00003  *  This file is part of the KDE libraries
00004  *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
00005  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
00006  *
00007  *  This library is free software; you can redistribute it and/or
00008  *  modify it under the terms of the GNU Lesser General Public
00009  *  License as published by the Free Software Foundation; either
00010  *  version 2 of the License, or (at your option) any later version.
00011  *
00012  *  This library is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  *  Lesser General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU Lesser General Public
00018  *  License along with this library; if not, write to the Free Software
00019  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020  *
00021  */
00022 
00023 #include "debugger.h"
00024 #include "value.h"
00025 #include "object.h"
00026 #include "types.h"
00027 #include "interpreter.h"
00028 #include "internal.h"
00029 #include "ustring.h"
00030 
00031 using namespace KJS;
00032 
00033 // ------------------------------ Debugger -------------------------------------
00034 
00035 namespace KJS {
00036   struct AttachedInterpreter
00037   {
00038   public:
00039     AttachedInterpreter(Interpreter *i) : interp(i), next(0L) {}
00040     Interpreter *interp;
00041     AttachedInterpreter *next;
00042   };
00043 
00044 }
00045 
00046 Debugger::Debugger()
00047 {
00048   rep = new DebuggerImp();
00049 }
00050 
00051 Debugger::~Debugger()
00052 {
00053   // detach from all interpreters
00054   while (rep->interps)
00055     detach(rep->interps->interp);
00056 
00057   delete rep;
00058 }
00059 
00060 void Debugger::attach(Interpreter *interp)
00061 {
00062   if (interp->imp()->debugger() != this)
00063     interp->imp()->setDebugger(this);
00064 
00065   // add to the list of attached interpreters
00066   if (!rep->interps)
00067     rep->interps = new AttachedInterpreter(interp);
00068   else {
00069     AttachedInterpreter *ai = rep->interps;
00070     while (ai->next) {
00071       if (ai->interp == interp)
00072           return; // already in list
00073       ai = ai->next;
00074     }
00075     ai->next = new AttachedInterpreter(interp);
00076   }
00077 }
00078 
00079 void Debugger::detach(Interpreter *interp)
00080 {
00081   if (interp->imp()->debugger() == this)
00082     interp->imp()->setDebugger(0L);
00083 
00084   if (!rep->interps)
00085     return;
00086   // remove from the list of attached interpreters
00087   if (rep->interps->interp == interp) {
00088     AttachedInterpreter *old = rep->interps;
00089     rep->interps = rep->interps->next;
00090     delete old;
00091   }
00092 
00093   AttachedInterpreter *ai = rep->interps;
00094   if (!ai)
00095     return;
00096   while (ai->next && ai->next->interp != interp)
00097     ai = ai->next;
00098   if (ai->next) {
00099     AttachedInterpreter *old = ai->next;
00100     ai->next = ai->next->next;
00101     delete old;
00102   }
00103 }
00104 
00105 bool Debugger::sourceParsed(ExecState * /*exec*/, int /*sourceId*/,
00106                             const UString &/*source*/, int /*errorLine*/)
00107 {
00108   return true;
00109 }
00110 
00111 bool Debugger::sourceUnused(ExecState * /*exec*/, int /*sourceId*/)
00112 {
00113   return true;
00114 }
00115 
00116 bool Debugger::exception(ExecState * /*exec*/, const Value &/*value*/,
00117              bool /*inTryCatch*/)
00118 {
00119   return true;
00120 }
00121 
00122 bool Debugger::atStatement(ExecState * /*exec*/)
00123 {
00124   return true;
00125 }
00126 
00127 bool Debugger::enterContext(ExecState * /*exec*/)
00128 {
00129   return true;
00130 }
00131 
00132 bool Debugger::exitContext(ExecState * /*exec*/, const Completion &/*completion*/)
00133 {
00134   return true;
00135 }
KDE Home | KDE Accessibility Home | Description of Access Keys