1 // -*- c-basic-offset: 2 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
5 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32 // ------------------------------ Debugger -------------------------------------
35 struct AttachedInterpreter
37 AttachedInterpreter(Interpreter
*i
, AttachedInterpreter
*ai
) : interp(i
), next(ai
) { ++Debugger::debuggersPresent
; }
38 ~AttachedInterpreter() { --Debugger::debuggersPresent
; }
40 AttachedInterpreter
*next
;
45 int Debugger::debuggersPresent
= 0;
50 rep
= new DebuggerImp();
59 void Debugger::attach(Interpreter
* interp
)
61 Debugger
*other
= interp
->debugger();
65 other
->detach(interp
);
66 interp
->setDebugger(this);
67 rep
->interps
= new AttachedInterpreter(interp
, rep
->interps
);
70 void Debugger::detach(Interpreter
* interp
)
72 // iterate the addresses where AttachedInterpreter pointers are stored
73 // so we can unlink items from the list
74 AttachedInterpreter
**p
= &rep
->interps
;
75 AttachedInterpreter
*q
;
77 if (!interp
|| q
->interp
== interp
) {
79 q
->interp
->setDebugger(0);
86 latestExceptions
.remove(interp
);
88 latestExceptions
.clear();
91 bool Debugger::hasHandledException(ExecState
*exec
, JSValue
*exception
)
93 if (latestExceptions
.get(exec
->dynamicInterpreter()).get() == exception
)
96 latestExceptions
.set(exec
->dynamicInterpreter(), exception
);
100 bool Debugger::sourceParsed(ExecState
* /*exec*/, int /*sourceId*/, const UString
&/*sourceURL*/,
101 const UString
&/*source*/, int /*startingLineNumber*/, int /*errorLine*/, const UString
& /*errorMsg*/)
106 bool Debugger::exception(ExecState
* /*exec*/, int /*sourceId*/, int /*lineno*/,
107 JSValue
* /*exception*/)
112 bool Debugger::atStatement(ExecState
* /*exec*/, int /*sourceId*/, int /*firstLine*/,
118 void Debugger::reportAtStatement(ExecState
*exec
, int sourceId
, int firstLine
, int lastLine
)
120 lastLineRan
= firstLine
;
121 atStatement(exec
, sourceId
, firstLine
, lastLine
);
124 void Debugger::reportException(ExecState
*exec
, JSValue
*exceptionVal
)
126 if (!hasHandledException(exec
, exceptionVal
))
127 exception(exec
, exec
->currentBody()->sourceId(), lastLineRan
, exceptionVal
);
130 bool Debugger::enterContext(ExecState
* /*exec*/, int /*sourceId*/, int /*lineno*/,
131 JSObject
* /*function*/, const List
& /*args*/)
136 bool Debugger::exitContext(ExecState
* /*exec*/, int /*sourceId*/, int /*lineno*/,
137 JSObject
* /*function*/)
142 bool Debugger::shouldReindentSources() const
147 bool Debugger::shouldReportCaught() const
152 void Debugger::reportSourceParsed(ExecState
*exec
, FunctionBodyNode
*body
, const UString
&source
,
153 int startingLineNumber
, int errorLine
, const UString
&errorMsg
)
155 UString code
= source
;
156 if (shouldReindentSources())
157 code
= body
->reindent(startingLineNumber
);
158 sourceParsed(exec
, body
->sourceId(), body
->sourceURL(), code
, startingLineNumber
, errorLine
, errorMsg
);