Qt 4.8
Public Functions | Static Public Functions | Public Variables | Protected Functions | Private Slots | Private Functions | Properties | List of all members
QJSDebugService Class Reference

#include <qjsdebugservice_p.h>

Inheritance diagram for QJSDebugService:
QDeclarativeDebugService QObject

Public Functions

void addEngine (QDeclarativeEngine *)
 
void processMessage (const JSAgentCoverageData &message)
 
 QJSDebugService (QObject *parent=0)
 
void removeEngine (QDeclarativeEngine *)
 
 ~QJSDebugService ()
 
- Public Functions inherited from QDeclarativeDebugService
QString name () const
 
 QDeclarativeDebugService (const QString &, QObject *parent=0)
 
void sendMessage (const QByteArray &)
 
Status status () const
 
bool waitForMessage ()
 
 ~QDeclarativeDebugService ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Static Public Functions

static QJSDebugServiceinstance ()
 
- Static Public Functions inherited from QDeclarativeDebugService
static bool hasDebuggingClient ()
 
static int idForObject (QObject *)
 Returns a unique id for object. More...
 
static bool isDebuggingEnabled ()
 
static QObjectobjectForId (int)
 Returns the object for unique id. More...
 
static QString objectToString (QObject *obj)
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 

Public Variables

QElapsedTimer m_timer
 

Protected Functions

void messageReceived (const QByteArray &)
 
void statusChanged (Status status)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Slots

void executionStopped (bool becauseOfException, const QString &exception)
 

Private Functions

void sendMessages ()
 

Properties

QPointer< QJSDebuggerAgentm_agent
 
QList< JSAgentCoverageDatam_data
 
bool m_deferredSend
 
QList< QDeclarativeEngine * > m_engines
 

Additional Inherited Members

- Public Types inherited from QDeclarativeDebugService
enum  Status { NotConnected, Unavailable, Enabled }
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 87 of file qjsdebugservice_p.h.

Constructors and Destructors

◆ QJSDebugService()

QJSDebugService::QJSDebugService ( QObject parent = 0)

Definition at line 63 of file qjsdebugservice.cpp.

64  : QDeclarativeDebugService(QLatin1String("JSDebugger"), parent)
65  , m_agent(0), m_deferredSend(true)
66 {
67  m_timer.start();
68 }
QPointer< QJSDebuggerAgent > m_agent
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QElapsedTimer m_timer
QDeclarativeDebugService(const QString &, QObject *parent=0)
void start()
Starts this timer.

◆ ~QJSDebugService()

QJSDebugService::~QJSDebugService ( )

Definition at line 70 of file qjsdebugservice.cpp.

71 {
72  delete m_agent;
73 }
QPointer< QJSDebuggerAgent > m_agent

Functions

◆ addEngine()

void QJSDebugService::addEngine ( QDeclarativeEngine engine)

Definition at line 80 of file qjsdebugservice.cpp.

Referenced by QDeclarativeEnginePrivate::init().

81 {
82  Q_ASSERT(engine);
83  Q_ASSERT(!m_engines.contains(engine));
84 
85  m_engines.append(engine);
86 
87  if (status() == Enabled && !m_engines.isEmpty() && !m_agent) {
88  m_agent = new QJSDebuggerAgent(engine, engine);
89  connect(m_agent, SIGNAL(stopped(bool,QString)),
90  this, SLOT(executionStopped(bool,QString)));
91 
92  while (!m_agent->isInitialized()) {
94  }
95  }
96 }
QList< QDeclarativeEngine * > m_engines
#define SLOT(a)
Definition: qobjectdefs.h:226
QPointer< QJSDebuggerAgent > m_agent
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
void executionStopped(bool becauseOfException, const QString &exception)
bool isInitialized() const
Indicates whether the agent got the list of breakpoints.

◆ executionStopped

void QJSDebugService::executionStopped ( bool  becauseOfException,
const QString exception 
)
privateslot

Definition at line 215 of file qjsdebugservice.cpp.

Referenced by addEngine(), and statusChanged().

217 {
218  const QList<JSAgentStackData> backtrace = m_agent->backtrace();
219  const QList<JSAgentWatchData> watches = m_agent->watches();
220  const QList<JSAgentWatchData> locals = m_agent->locals();
221 
222  QByteArray reply;
223  QDataStream rs(&reply, QIODevice::WriteOnly);
224  rs << QByteArray("STOPPED") << backtrace << watches << locals
225  << becauseOfException << exception;
226  sendMessage(reply);
227 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QPointer< QJSDebuggerAgent > m_agent
QList< JSAgentWatchData > watches()
QList< JSAgentWatchData > locals()
QList< JSAgentStackData > backtrace()
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
void sendMessage(const QByteArray &)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ instance()

QJSDebugService * QJSDebugService::instance ( )
static

◆ messageReceived()

void QJSDebugService::messageReceived ( const QByteArray message)
protectedvirtual

Reimplemented from QDeclarativeDebugService.

Definition at line 122 of file qjsdebugservice.cpp.

123 {
124  if (!m_agent) {
125  qWarning() << "QJSDebugService::messageReceived: No QJSDebuggerAgent available";
126  return;
127  }
128 
129  QDataStream ds(message);
130  QByteArray command;
131  ds >> command;
132  if (command == "BREAKPOINTS") {
133  JSAgentBreakpoints breakpoints;
134  ds >> breakpoints;
135  m_agent->setBreakpoints(breakpoints);
136 
137  //qDebug() << "BREAKPOINTS";
138  //foreach (const JSAgentBreakpointData &bp, breakpoints)
139  // qDebug() << "BREAKPOINT: " << bp.fileUrl << bp.lineNumber;
140  } else if (command == "WATCH_EXPRESSIONS") {
141  QStringList watchExpressions;
142  ds >> watchExpressions;
143  m_agent->setWatchExpressions(watchExpressions);
144  } else if (command == "STEPOVER") {
145  m_agent->stepOver();
146  } else if (command == "STEPINTO" || command == "INTERRUPT") {
147  m_agent->stepInto();
148  } else if (command == "STEPOUT") {
149  m_agent->stepOut();
150  } else if (command == "CONTINUE") {
152  } else if (command == "EXEC") {
153  QByteArray id;
154  QString expr;
155  ds >> id >> expr;
156 
158 
159  QByteArray reply;
160  QDataStream rs(&reply, QIODevice::WriteOnly);
161  rs << QByteArray("RESULT") << id << data;
162  sendMessage(reply);
163  } else if (command == "EXPAND") {
164  QByteArray requestId;
165  quint64 objectId;
166  ds >> requestId >> objectId;
167 
169 
170  QByteArray reply;
171  QDataStream rs(&reply, QIODevice::WriteOnly);
172  rs << QByteArray("EXPANDED") << requestId << result;
173  sendMessage(reply);
174  } else if (command == "ACTIVATE_FRAME") {
175  int frameId;
176  ds >> frameId;
177 
178  QList<JSAgentWatchData> locals = m_agent->localsAtFrame(frameId);
179 
180  QByteArray reply;
181  QDataStream rs(&reply, QIODevice::WriteOnly);
182  rs << QByteArray("LOCALS") << frameId << locals;
183  sendMessage(reply);
184  } else if (command == "SET_PROPERTY") {
185  QByteArray id;
186  qint64 objectId;
188  QString value;
189  ds >> id >> objectId >> property >> value;
190 
191  m_agent->setProperty(objectId, property, value);
192 
193  //TODO: feedback
194  } else if (command == "PING") {
195  int ping;
196  ds >> ping;
197  QByteArray reply;
198  QDataStream rs(&reply, QIODevice::WriteOnly);
199  rs << QByteArray("PONG") << ping;
200  sendMessage(reply);
201  } else if (command == "COVERAGE") {
202  bool enabled;
203  ds >> enabled;
204  m_agent->setCoverageEnabled(enabled);
205  if (!enabled) {
206  sendMessages();
207  }
208  } else {
209  qDebug() << Q_FUNC_INFO << "Unknown command" << command;
210  }
211 
213 }
virtual void messageReceived(const QByteArray &)
JSAgentWatchData executeExpression(const QString &expr)
void setProperty(qint64 objectId, const QString &property, const QString &value)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QPointer< QJSDebuggerAgent > m_agent
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_CORE_EXPORT void qDebug(const char *,...)
unsigned __int64 quint64
Definition: qglobal.h:943
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
Q_CORE_EXPORT void qWarning(const char *,...)
QList< JSAgentWatchData > localsAtFrame(int frameId)
static const char * data(const QByteArray &arr)
void setBreakpoints(const JSAgentBreakpoints &)
void setCoverageEnabled(bool enabled)
__int64 qint64
Definition: qglobal.h:942
void setWatchExpressions(const QStringList &)
QList< JSAgentWatchData > expandObjectById(quint64 objectId)
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
#define enabled
void sendMessage(const QByteArray &)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ processMessage()

void QJSDebugService::processMessage ( const JSAgentCoverageData message)

Definition at line 233 of file qjsdebugservice.cpp.

Referenced by QJSDebuggerAgent::functionEntry(), QJSDebuggerAgent::functionExit(), QJSDebuggerAgent::positionChange(), and QJSDebuggerAgent::scriptLoad().

234 {
235  if (m_deferredSend)
236  m_data.append(message);
237  else
238  sendMessage(message.toByteArray());
239 }
QList< JSAgentCoverageData > m_data
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QByteArray toByteArray() const
void sendMessage(const QByteArray &)

◆ removeEngine()

void QJSDebugService::removeEngine ( QDeclarativeEngine engine)

Definition at line 98 of file qjsdebugservice.cpp.

Referenced by QDeclarativeEngine::~QDeclarativeEngine().

99 {
100  Q_ASSERT(engine);
101  Q_ASSERT(m_engines.contains(engine));
102 
103  m_engines.removeAll(engine);
104 }
QList< QDeclarativeEngine * > m_engines
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770

◆ sendMessages()

void QJSDebugService::sendMessages ( )
private

Definition at line 244 of file qjsdebugservice.cpp.

Referenced by messageReceived().

245 {
246  if (m_deferredSend) {
247  //### this is a suboptimal way to send batched messages
248  for (int i = 0; i < m_data.count(); ++i)
250  m_data.clear();
251 
252  //indicate completion
255  ds << QByteArray("COVERAGE") << (qint64)-1 << (int)CoverageComplete;
256  sendMessage(data);
257  }
258 }
QList< JSAgentCoverageData > m_data
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static const char * data(const QByteArray &arr)
void clear()
Removes all items from the list.
Definition: qlist.h:764
__int64 qint64
Definition: qglobal.h:942
QByteArray toByteArray() const
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
void sendMessage(const QByteArray &)

◆ statusChanged()

void QJSDebugService::statusChanged ( Status  status)
protectedvirtual

Reimplemented from QDeclarativeDebugService.

Definition at line 106 of file qjsdebugservice.cpp.

107 {
108  if (status == Enabled && !m_engines.isEmpty() && !m_agent) {
109  // Multiple engines are currently unsupported
110  QDeclarativeEngine *engine = m_engines.first();
111  m_agent = new QJSDebuggerAgent(engine, engine);
112 
113  connect(m_agent, SIGNAL(stopped(bool,QString)),
114  this, SLOT(executionStopped(bool,QString)));
115 
116  } else if (status != Enabled && m_agent) {
117  delete m_agent;
118  m_agent = 0;
119  }
120 }
QList< QDeclarativeEngine * > m_engines
#define SLOT(a)
Definition: qobjectdefs.h:226
QPointer< QJSDebuggerAgent > m_agent
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
The QDeclarativeEngine class provides an environment for instantiating QML components.
void executionStopped(bool becauseOfException, const QString &exception)

Properties

◆ m_agent

QPointer<QJSDebuggerAgent> QJSDebugService::m_agent
private

◆ m_data

QList<JSAgentCoverageData> QJSDebugService::m_data
private

Definition at line 116 of file qjsdebugservice_p.h.

Referenced by processMessage(), and sendMessages().

◆ m_deferredSend

bool QJSDebugService::m_deferredSend
private

Definition at line 115 of file qjsdebugservice_p.h.

Referenced by processMessage(), and sendMessages().

◆ m_engines

QList<QDeclarativeEngine *> QJSDebugService::m_engines
private

Definition at line 113 of file qjsdebugservice_p.h.

Referenced by addEngine(), removeEngine(), and statusChanged().

◆ m_timer

QElapsedTimer QJSDebugService::m_timer

The documentation for this class was generated from the following files: