source: trunk/src/scripttools/debugging/qscriptdebuggercommand.cpp@ 342

Last change on this file since 342 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 18.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtSCriptTools module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qscriptdebuggercommand_p.h"
43#include "qscriptbreakpointdata_p.h"
44#include "qscriptdebuggervalue_p.h"
45
46#include <QtCore/qhash.h>
47#include <QtCore/qdatastream.h>
48
49Q_DECLARE_METATYPE(QScriptBreakpointData)
50Q_DECLARE_METATYPE(QScriptDebuggerValue)
51
52QT_BEGIN_NAMESPACE
53
54/*!
55 \since 4.5
56 \class QScriptDebuggerCommand
57 \internal
58
59 \brief The QScriptDebuggerCommand class represents a command issued to a QScriptDebuggerFrontend.
60
61 A debugger command is described by a command type and zero or more
62 attributes. Such commands are generated internally by the
63 QScriptDebuggerFrontend class (through the scheduleXXX commands). A
64 command is typically passed on to a QScriptDebuggerCommandExecutor
65 that applies the command to a QScriptDebuggerBackend.
66*/
67
68class QScriptDebuggerCommandPrivate
69{
70public:
71 QScriptDebuggerCommandPrivate();
72 ~QScriptDebuggerCommandPrivate();
73
74 QScriptDebuggerCommand::Type type;
75 QHash<QScriptDebuggerCommand::Attribute, QVariant> attributes;
76};
77
78QScriptDebuggerCommandPrivate::QScriptDebuggerCommandPrivate()
79 : type(QScriptDebuggerCommand::None)
80{
81}
82
83QScriptDebuggerCommandPrivate::~QScriptDebuggerCommandPrivate()
84{
85}
86
87/*!
88 Constructs a QScriptDebuggerCommand of type None.
89*/
90QScriptDebuggerCommand::QScriptDebuggerCommand()
91 : d_ptr(new QScriptDebuggerCommandPrivate)
92{
93 d_ptr->type = None;
94}
95
96/*!
97 Constructs a QScriptDebuggerCommand of the given \a type, with no
98 attributes defined.
99*/
100QScriptDebuggerCommand::QScriptDebuggerCommand(Type type)
101 : d_ptr(new QScriptDebuggerCommandPrivate)
102{
103 d_ptr->type = type;
104}
105
106/*!
107 Constructs a QScriptDebuggerCommand that is a copy of the \a other
108 command.
109*/
110QScriptDebuggerCommand::QScriptDebuggerCommand(const QScriptDebuggerCommand &other)
111 : d_ptr(new QScriptDebuggerCommandPrivate)
112{
113 *d_ptr = *other.d_ptr;
114}
115
116/*!
117 Destroys this QScriptDebuggerCommand.
118*/
119QScriptDebuggerCommand::~QScriptDebuggerCommand()
120{
121 delete d_ptr;
122}
123
124/*!
125 Assigns the \a other value to this QScriptDebuggerCommand.
126*/
127QScriptDebuggerCommand &QScriptDebuggerCommand::operator=(const QScriptDebuggerCommand &other)
128{
129 *d_ptr = *other.d_ptr;
130 return *this;
131}
132
133/*!
134 Returns the type of this command.
135*/
136QScriptDebuggerCommand::Type QScriptDebuggerCommand::type() const
137{
138 Q_D(const QScriptDebuggerCommand);
139 return d->type;
140}
141
142/*!
143 Returns the value of the given \a attribute, or \a defaultValue
144 if the attribute is not defined.
145*/
146QVariant QScriptDebuggerCommand::attribute(Attribute attribute,
147 const QVariant &defaultValue) const
148{
149 Q_D(const QScriptDebuggerCommand);
150 return d->attributes.value(attribute, defaultValue);
151}
152
153/*!
154 Sets the \a value of the given \a attribute.
155*/
156void QScriptDebuggerCommand::setAttribute(Attribute attribute,
157 const QVariant &value)
158{
159 Q_D(QScriptDebuggerCommand);
160 if (!value.isValid())
161 d->attributes.remove(attribute);
162 else
163 d->attributes[attribute] = value;
164}
165
166QHash<QScriptDebuggerCommand::Attribute, QVariant> QScriptDebuggerCommand::attributes() const
167{
168 Q_D(const QScriptDebuggerCommand);
169 return d->attributes;
170}
171
172/*!
173 Returns the FileName attribute of this command converted to a string.
174 This function is provided for convenience.
175
176 \sa attribute()
177*/
178QString QScriptDebuggerCommand::fileName() const
179{
180 Q_D(const QScriptDebuggerCommand);
181 return d->attributes.value(FileName).toString();
182}
183
184void QScriptDebuggerCommand::setFileName(const QString &fileName)
185{
186 Q_D(QScriptDebuggerCommand);
187 d->attributes[FileName] = fileName;
188}
189
190/*!
191 Returns the LineNumber attribute of this command converted to an int.
192 This function is provided for convenience.
193
194 \sa attribute()
195*/
196int QScriptDebuggerCommand::lineNumber() const
197{
198 Q_D(const QScriptDebuggerCommand);
199 return d->attributes.value(LineNumber, -1).toInt();
200}
201
202void QScriptDebuggerCommand::setLineNumber(int lineNumber)
203{
204 Q_D(QScriptDebuggerCommand);
205 d->attributes[LineNumber] = lineNumber;
206}
207
208/*!
209 Returns the ScriptID attribute of this command converted to a qint64.
210 This function is provided for convenience.
211
212 \sa attribute()
213*/
214qint64 QScriptDebuggerCommand::scriptId() const
215{
216 Q_D(const QScriptDebuggerCommand);
217 return d->attributes.value(ScriptID, -1).toLongLong();
218}
219
220void QScriptDebuggerCommand::setScriptId(qint64 id)
221{
222 Q_D(QScriptDebuggerCommand);
223 d->attributes[ScriptID] = id;
224}
225
226QString QScriptDebuggerCommand::program() const
227{
228 Q_D(const QScriptDebuggerCommand);
229 return d->attributes.value(Program).toString();
230}
231
232void QScriptDebuggerCommand::setProgram(const QString &program)
233{
234 Q_D(QScriptDebuggerCommand);
235 d->attributes[Program] = program;
236}
237
238int QScriptDebuggerCommand::breakpointId() const
239{
240 Q_D(const QScriptDebuggerCommand);
241 return d->attributes.value(BreakpointID, -1).toInt();
242}
243
244void QScriptDebuggerCommand::setBreakpointId(int id)
245{
246 Q_D(QScriptDebuggerCommand);
247 d->attributes[BreakpointID] = id;
248}
249
250QScriptBreakpointData QScriptDebuggerCommand::breakpointData() const
251{
252 Q_D(const QScriptDebuggerCommand);
253 return qvariant_cast<QScriptBreakpointData>(d->attributes.value(BreakpointData));
254}
255
256void QScriptDebuggerCommand::setBreakpointData(const QScriptBreakpointData &data)
257{
258 Q_D(QScriptDebuggerCommand);
259 d->attributes[BreakpointData] = qVariantFromValue(data);
260}
261
262QScriptDebuggerValue QScriptDebuggerCommand::scriptValue() const
263{
264 Q_D(const QScriptDebuggerCommand);
265 return qvariant_cast<QScriptDebuggerValue>(d->attributes.value(ScriptValue));
266}
267
268void QScriptDebuggerCommand::setScriptValue(const QScriptDebuggerValue &value)
269{
270 Q_D(QScriptDebuggerCommand);
271 d->attributes[ScriptValue] = qVariantFromValue(value);
272}
273
274int QScriptDebuggerCommand::contextIndex() const
275{
276 Q_D(const QScriptDebuggerCommand);
277 return d->attributes.value(ContextIndex, -1).toInt();
278}
279
280void QScriptDebuggerCommand::setContextIndex(int index)
281{
282 Q_D(QScriptDebuggerCommand);
283 d->attributes[ContextIndex] = index;
284}
285
286int QScriptDebuggerCommand::iteratorId() const
287{
288 Q_D(const QScriptDebuggerCommand);
289 return d->attributes.value(IteratorID, -1).toInt();
290}
291
292void QScriptDebuggerCommand::setIteratorId(int id)
293{
294 Q_D(QScriptDebuggerCommand);
295 d->attributes[IteratorID] = id;
296}
297
298QString QScriptDebuggerCommand::name() const
299{
300 Q_D(const QScriptDebuggerCommand);
301 return d->attributes.value(Name).toString();
302}
303
304void QScriptDebuggerCommand::setName(const QString &name)
305{
306 Q_D(QScriptDebuggerCommand);
307 d->attributes[Name] = name;
308}
309
310QScriptDebuggerValue QScriptDebuggerCommand::subordinateScriptValue() const
311{
312 Q_D(const QScriptDebuggerCommand);
313 return qvariant_cast<QScriptDebuggerValue>(d->attributes.value(SubordinateScriptValue));
314}
315
316void QScriptDebuggerCommand::setSubordinateScriptValue(const QScriptDebuggerValue &value)
317{
318 Q_D(QScriptDebuggerCommand);
319 d->attributes[SubordinateScriptValue] = qVariantFromValue(value);
320}
321
322int QScriptDebuggerCommand::snapshotId() const
323{
324 Q_D(const QScriptDebuggerCommand);
325 return d->attributes.value(SnapshotID, -1).toInt();
326}
327
328void QScriptDebuggerCommand::setSnapshotId(int id)
329{
330 Q_D(QScriptDebuggerCommand);
331 d->attributes[SnapshotID] = id;
332}
333
334/*!
335 Returns true if this QScriptDebuggerCommand is equal to the \a other
336 command, otherwise returns false.
337*/
338bool QScriptDebuggerCommand::operator==(const QScriptDebuggerCommand &other) const
339{
340 Q_D(const QScriptDebuggerCommand);
341 const QScriptDebuggerCommandPrivate *od = other.d_func();
342 if (d == od)
343 return true;
344 if (!d || !od)
345 return false;
346 return ((d->type == od->type)
347 && (d->attributes == od->attributes));
348}
349
350/*!
351 Returns true if this QScriptDebuggerCommand is not equal to the \a
352 other command, otherwise returns false.
353*/
354bool QScriptDebuggerCommand::operator!=(const QScriptDebuggerCommand &other) const
355{
356 return !(*this == other);
357}
358
359QScriptDebuggerCommand QScriptDebuggerCommand::interruptCommand()
360{
361 QScriptDebuggerCommand cmd(Interrupt);
362 return cmd;
363}
364
365QScriptDebuggerCommand QScriptDebuggerCommand::continueCommand()
366{
367 QScriptDebuggerCommand cmd(Continue);
368 return cmd;
369}
370
371QScriptDebuggerCommand QScriptDebuggerCommand::stepIntoCommand(int count)
372{
373 QScriptDebuggerCommand cmd(StepInto);
374 cmd.setAttribute(StepCount, count);
375 return cmd;
376}
377
378QScriptDebuggerCommand QScriptDebuggerCommand::stepOverCommand(int count)
379{
380 QScriptDebuggerCommand cmd(StepOver);
381 cmd.setAttribute(StepCount, count);
382 return cmd;
383}
384
385QScriptDebuggerCommand QScriptDebuggerCommand::stepOutCommand()
386{
387 QScriptDebuggerCommand cmd(StepOut);
388 return cmd;
389}
390
391QScriptDebuggerCommand QScriptDebuggerCommand::runToLocationCommand(const QString &fileName, int lineNumber)
392{
393 QScriptDebuggerCommand cmd(RunToLocation);
394 cmd.setFileName(fileName);
395 cmd.setLineNumber(lineNumber);
396 return cmd;
397}
398
399QScriptDebuggerCommand QScriptDebuggerCommand::runToLocationCommand(qint64 scriptId, int lineNumber)
400{
401 QScriptDebuggerCommand cmd(RunToLocationByID);
402 cmd.setScriptId(scriptId);
403 cmd.setLineNumber(lineNumber);
404 return cmd;
405}
406
407QScriptDebuggerCommand QScriptDebuggerCommand::forceReturnCommand(int contextIndex, const QScriptDebuggerValue &value)
408{
409 QScriptDebuggerCommand cmd(ForceReturn);
410 cmd.setContextIndex(contextIndex);
411 cmd.setScriptValue(value);
412 return cmd;
413}
414
415QScriptDebuggerCommand QScriptDebuggerCommand::resumeCommand()
416{
417 QScriptDebuggerCommand cmd(Resume);
418 return cmd;
419}
420
421QScriptDebuggerCommand QScriptDebuggerCommand::setBreakpointCommand(const QString &fileName, int lineNumber)
422{
423 QScriptDebuggerCommand cmd(SetBreakpoint);
424 cmd.setBreakpointData(QScriptBreakpointData(fileName, lineNumber));
425 return cmd;
426}
427
428QScriptDebuggerCommand QScriptDebuggerCommand::setBreakpointCommand(const QScriptBreakpointData &data)
429{
430 QScriptDebuggerCommand cmd(SetBreakpoint);
431 cmd.setBreakpointData(data);
432 return cmd;
433}
434
435QScriptDebuggerCommand QScriptDebuggerCommand::deleteBreakpointCommand(int id)
436{
437 QScriptDebuggerCommand cmd(DeleteBreakpoint);
438 cmd.setBreakpointId(id);
439 return cmd;
440}
441
442QScriptDebuggerCommand QScriptDebuggerCommand::deleteAllBreakpointsCommand()
443{
444 QScriptDebuggerCommand cmd(DeleteAllBreakpoints);
445 return cmd;
446}
447
448QScriptDebuggerCommand QScriptDebuggerCommand::getBreakpointsCommand()
449{
450 QScriptDebuggerCommand cmd(GetBreakpoints);
451 return cmd;
452}
453
454QScriptDebuggerCommand QScriptDebuggerCommand::getBreakpointDataCommand(int id)
455{
456 QScriptDebuggerCommand cmd(GetBreakpointData);
457 cmd.setBreakpointId(id);
458 return cmd;
459}
460
461QScriptDebuggerCommand QScriptDebuggerCommand::setBreakpointDataCommand(int id, const QScriptBreakpointData &data)
462{
463 QScriptDebuggerCommand cmd(SetBreakpointData);
464 cmd.setBreakpointId(id);
465 cmd.setBreakpointData(data);
466 return cmd;
467}
468
469QScriptDebuggerCommand QScriptDebuggerCommand::getScriptsCommand()
470{
471 QScriptDebuggerCommand cmd(GetScripts);
472 return cmd;
473}
474
475QScriptDebuggerCommand QScriptDebuggerCommand::getScriptDataCommand(qint64 id)
476{
477 QScriptDebuggerCommand cmd(GetScriptData);
478 cmd.setScriptId(id);
479 return cmd;
480}
481
482QScriptDebuggerCommand QScriptDebuggerCommand::scriptsCheckpointCommand()
483{
484 QScriptDebuggerCommand cmd(ScriptsCheckpoint);
485 return cmd;
486}
487
488QScriptDebuggerCommand QScriptDebuggerCommand::getScriptsDeltaCommand()
489{
490 QScriptDebuggerCommand cmd(GetScriptsDelta);
491 return cmd;
492}
493
494QScriptDebuggerCommand QScriptDebuggerCommand::resolveScriptCommand(const QString &fileName)
495{
496 QScriptDebuggerCommand cmd(ResolveScript);
497 cmd.setFileName(fileName);
498 return cmd;
499}
500
501QScriptDebuggerCommand QScriptDebuggerCommand::getBacktraceCommand()
502{
503 QScriptDebuggerCommand cmd(GetBacktrace);
504 return cmd;
505}
506
507QScriptDebuggerCommand QScriptDebuggerCommand::getContextCountCommand()
508{
509 QScriptDebuggerCommand cmd(GetContextCount);
510 return cmd;
511}
512
513QScriptDebuggerCommand QScriptDebuggerCommand::getContextStateCommand(int contextIndex)
514{
515 QScriptDebuggerCommand cmd(GetContextState);
516 cmd.setContextIndex(contextIndex);
517 return cmd;
518}
519
520QScriptDebuggerCommand QScriptDebuggerCommand::getContextInfoCommand(int contextIndex)
521{
522 QScriptDebuggerCommand cmd(GetContextInfo);
523 cmd.setContextIndex(contextIndex);
524 return cmd;
525}
526
527QScriptDebuggerCommand QScriptDebuggerCommand::getContextIdCommand(int contextIndex)
528{
529 QScriptDebuggerCommand cmd(GetContextID);
530 cmd.setContextIndex(contextIndex);
531 return cmd;
532}
533
534QScriptDebuggerCommand QScriptDebuggerCommand::getThisObjectCommand(int contextIndex)
535{
536 QScriptDebuggerCommand cmd(GetThisObject);
537 cmd.setContextIndex(contextIndex);
538 return cmd;
539}
540
541QScriptDebuggerCommand QScriptDebuggerCommand::getActivationObjectCommand(int contextIndex)
542{
543 QScriptDebuggerCommand cmd(GetActivationObject);
544 cmd.setContextIndex(contextIndex);
545 return cmd;
546}
547
548QScriptDebuggerCommand QScriptDebuggerCommand::getScopeChainCommand(int contextIndex)
549{
550 QScriptDebuggerCommand cmd(GetScopeChain);
551 cmd.setContextIndex(contextIndex);
552 return cmd;
553}
554
555QScriptDebuggerCommand QScriptDebuggerCommand::contextsCheckpoint()
556{
557 QScriptDebuggerCommand cmd(ContextsCheckpoint);
558 return cmd;
559}
560
561QScriptDebuggerCommand QScriptDebuggerCommand::newScriptObjectSnapshotCommand()
562{
563 QScriptDebuggerCommand cmd(NewScriptObjectSnapshot);
564 return cmd;
565}
566
567QScriptDebuggerCommand QScriptDebuggerCommand::scriptObjectSnapshotCaptureCommand(int id, const QScriptDebuggerValue &object)
568{
569 Q_ASSERT(object.type() == QScriptDebuggerValue::ObjectValue);
570 QScriptDebuggerCommand cmd(ScriptObjectSnapshotCapture);
571 cmd.setSnapshotId(id);
572 cmd.setScriptValue(object);
573 return cmd;
574}
575
576QScriptDebuggerCommand QScriptDebuggerCommand::deleteScriptObjectSnapshotCommand(int id)
577{
578 QScriptDebuggerCommand cmd(DeleteScriptObjectSnapshot);
579 cmd.setSnapshotId(id);
580 return cmd;
581}
582
583QScriptDebuggerCommand QScriptDebuggerCommand::newScriptValueIteratorCommand(const QScriptDebuggerValue &object)
584{
585 QScriptDebuggerCommand cmd(NewScriptValueIterator);
586 Q_ASSERT(object.type() == QScriptDebuggerValue::ObjectValue);
587 cmd.setScriptValue(object);
588 return cmd;
589}
590
591QScriptDebuggerCommand QScriptDebuggerCommand::getPropertiesByIteratorCommand(int id, int count)
592{
593 Q_UNUSED(count);
594 QScriptDebuggerCommand cmd(GetPropertiesByIterator);
595 cmd.setIteratorId(id);
596 return cmd;
597}
598
599QScriptDebuggerCommand QScriptDebuggerCommand::deleteScriptValueIteratorCommand(int id)
600{
601 QScriptDebuggerCommand cmd(DeleteScriptValueIterator);
602 cmd.setIteratorId(id);
603 return cmd;
604}
605
606QScriptDebuggerCommand QScriptDebuggerCommand::evaluateCommand(
607 int contextIndex, const QString &program, const QString &fileName, int lineNumber)
608{
609 QScriptDebuggerCommand cmd(Evaluate);
610 cmd.setContextIndex(contextIndex);
611 cmd.setProgram(program);
612 cmd.setFileName(fileName);
613 cmd.setLineNumber(lineNumber);
614 return cmd;
615}
616
617QScriptDebuggerCommand QScriptDebuggerCommand::scriptValueToStringCommand(const QScriptDebuggerValue &value)
618{
619 QScriptDebuggerCommand cmd(ScriptValueToString);
620 cmd.setScriptValue(value);
621 return cmd;
622}
623
624QScriptDebuggerCommand QScriptDebuggerCommand::setScriptValuePropertyCommand(
625 const QScriptDebuggerValue &object, const QString &name,
626 const QScriptDebuggerValue &value)
627{
628 QScriptDebuggerCommand cmd(SetScriptValueProperty);
629 cmd.setScriptValue(object);
630 cmd.setName(name);
631 cmd.setSubordinateScriptValue(value);
632 return cmd;
633}
634
635QScriptDebuggerCommand QScriptDebuggerCommand::clearExceptionsCommand()
636{
637 QScriptDebuggerCommand cmd(ClearExceptions);
638 return cmd;
639}
640
641/*!
642 \fn QDataStream &operator<<(QDataStream &stream, const QScriptDebuggerCommand &command)
643 \relates QScriptDebuggerCommand
644
645 Writes the given \a command to the specified \a stream.
646*/
647QDataStream &operator<<(QDataStream &out, const QScriptDebuggerCommand &command)
648{
649 const QScriptDebuggerCommandPrivate *d = command.d_ptr;
650 out << (quint32)d->type;
651 out << (qint32)d->attributes.size();
652 QHash<QScriptDebuggerCommand::Attribute, QVariant>::const_iterator it;
653 for (it = d->attributes.constBegin(); it != d->attributes.constEnd(); ++it) {
654 out << (quint32)it.key();
655 out << it.value();
656 }
657 return out;
658}
659
660/*!
661 \fn QDataStream &operator>>(QDataStream &stream, QScriptDebuggerCommand &command)
662 \relates QScriptDebuggerCommand
663
664 Reads a QScriptDebuggerCommand from the specified \a stream into the
665 given \a command.
666*/
667QDataStream &operator>>(QDataStream &in, QScriptDebuggerCommand &command)
668{
669 QScriptDebuggerCommandPrivate *d = command.d_ptr;
670
671 quint32 type;
672 in >> type;
673 d->type = QScriptDebuggerCommand::Type(type);
674
675 qint32 attribCount;
676 in >> attribCount;
677 QHash<QScriptDebuggerCommand::Attribute, QVariant> attribs;
678 for (qint32 i = 0; i < attribCount; ++i) {
679 quint32 key;
680 in >> key;
681 QVariant value;
682 in >> value;
683 attribs[QScriptDebuggerCommand::Attribute(key)] = value;
684 }
685 d->attributes = attribs;
686
687 return in;
688}
689
690QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.