2011-02-18 10:36:52 +01:00
/**************************************************************************
* *
* * This file is part of Qt Creator
* *
* * Copyright ( c ) 2011 Nokia Corporation and / or its subsidiary ( - ies ) .
* *
2011-04-13 08:42:33 +02:00
* * Contact : Nokia Corporation ( info @ qt . nokia . com )
2011-02-18 10:36:52 +01:00
* *
* *
* * GNU Lesser General Public License Usage
* *
2011-04-13 08:42:33 +02:00
* * This file may be used under the terms of the GNU Lesser General Public
* * License version 2.1 as published by the Free Software Foundation and
* * appearing in the file LICENSE . LGPL included in the packaging of this file .
* * Please review the following information to ensure the GNU Lesser General
* * Public License version 2.1 requirements will be met :
* * http : //www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
2011-02-18 10:36:52 +01:00
* *
* * In addition , as a special exception , Nokia gives you certain additional
2011-04-13 08:42:33 +02:00
* * rights . These rights are described in the Nokia Qt LGPL Exception
2011-02-18 10:36:52 +01:00
* * version 1.1 , included in the file LGPL_EXCEPTION . txt in this package .
* *
2011-04-13 08:42:33 +02:00
* * Other Usage
* *
* * Alternatively , this file may be used in accordance with the terms and
* * conditions contained in a signed written agreement between you and Nokia .
* *
2011-02-18 10:36:52 +01:00
* * If you have questions regarding the use of this file , please contact
2011-05-06 15:05:37 +02:00
* * Nokia at info @ qt . nokia . com .
2011-02-18 10:36:52 +01:00
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-08-18 13:54:12 +02:00
2011-01-14 17:08:59 +01:00
# include "qmlcppengine.h"
2011-02-24 16:50:15 +01:00
# include "debuggerruncontrolfactory.h"
2011-01-14 17:08:59 +01:00
# include "debuggercore.h"
# include "debuggerstartparameters.h"
2011-01-19 17:34:28 +01:00
# include "stackhandler.h"
2011-02-21 17:01:40 +01:00
# include "qmlengine.h"
2010-08-18 13:54:12 +02:00
2011-01-14 14:25:02 +01:00
# include <utils/qtcassert.h>
2011-07-12 14:18:48 +02:00
# include <coreplugin/icore.h>
# include <QtGui/QMainWindow>
# include <QtGui/QMessageBox>
# include <QtCore/QTimer>
2010-08-18 13:54:12 +02:00
namespace Debugger {
2011-01-11 11:06:15 +01:00
namespace Internal {
2010-08-18 13:54:12 +02:00
2011-01-19 10:48:39 +01:00
enum { debug = 0 } ;
# define EDEBUG(s) do { if (debug) qDebug() << s; } while (0)
2010-08-18 13:54:12 +02:00
const int ConnectionWaitTimeMs = 5000 ;
2011-02-21 17:01:40 +01:00
QmlEngine * createQmlEngine ( const DebuggerStartParameters & ,
2011-01-12 12:10:12 +01:00
DebuggerEngine * masterEngine ) ;
2010-08-18 13:54:12 +02:00
2011-02-24 16:50:15 +01:00
DebuggerEngine * createQmlCppEngine ( const DebuggerStartParameters & sp ,
DebuggerEngineType slaveEngineType ,
QString * errorMessage )
2010-08-18 13:54:12 +02:00
{
2011-02-24 16:50:15 +01:00
QmlCppEngine * newEngine = new QmlCppEngine ( sp , slaveEngineType , errorMessage ) ;
2010-10-27 15:23:30 +02:00
if ( newEngine - > cppEngine ( ) )
2010-10-06 17:18:31 +02:00
return newEngine ;
2010-10-27 15:23:30 +02:00
delete newEngine ;
return 0 ;
2010-08-18 13:54:12 +02:00
}
2010-10-27 15:23:30 +02:00
2011-01-19 17:34:28 +01:00
////////////////////////////////////////////////////////////////////////
//
// QmlCppEnginePrivate
//
////////////////////////////////////////////////////////////////////////
class QmlCppEnginePrivate : public QObject
2010-11-22 10:20:31 +01:00
{
2011-01-19 17:34:28 +01:00
Q_OBJECT
2010-11-15 17:09:28 +01:00
public :
2011-01-19 17:34:28 +01:00
QmlCppEnginePrivate ( QmlCppEngine * parent ,
const DebuggerStartParameters & sp ) ;
2010-11-15 17:09:28 +01:00
~ QmlCppEnginePrivate ( ) { }
2010-09-13 13:30:35 +02:00
2011-01-19 17:34:28 +01:00
private slots :
void cppStackChanged ( ) ;
void qmlStackChanged ( ) ;
2010-11-15 17:09:28 +01:00
private :
2011-01-19 17:34:28 +01:00
friend class QmlCppEngine ;
QmlCppEngine * q ;
2011-02-21 17:01:40 +01:00
QmlEngine * m_qmlEngine ;
2010-09-13 13:30:35 +02:00
DebuggerEngine * m_cppEngine ;
DebuggerEngine * m_activeEngine ;
2011-01-19 18:59:53 +01:00
int m_stackBoundary ;
2011-07-12 14:18:48 +02:00
QMessageBox * m_msg ;
2010-09-13 13:30:35 +02:00
} ;
2011-01-19 17:34:28 +01:00
QmlCppEnginePrivate : : QmlCppEnginePrivate ( QmlCppEngine * parent ,
const DebuggerStartParameters & sp )
2011-02-24 16:50:15 +01:00
: q ( parent ) , m_qmlEngine ( createQmlEngine ( sp , q ) ) ,
2011-07-12 14:18:48 +02:00
m_cppEngine ( 0 ) , m_activeEngine ( 0 ) , m_msg ( 0 )
2010-09-13 13:30:35 +02:00
{
2011-02-24 16:50:15 +01:00
setObjectName ( QLatin1String ( " QmlCppEnginePrivate " ) ) ;
2011-01-19 17:34:28 +01:00
}
2011-01-14 14:25:02 +01:00
2011-01-19 17:34:28 +01:00
void QmlCppEnginePrivate : : cppStackChanged ( )
{
const QLatin1String firstFunction ( " QScript::FunctionWrapper::proxyCall " ) ;
StackFrames frames ;
foreach ( const StackFrame & frame , m_cppEngine - > stackHandler ( ) - > frames ( ) ) {
if ( frame . function . endsWith ( firstFunction ) )
break ;
frames . append ( frame ) ;
}
int level = frames . size ( ) ;
2011-01-19 18:59:53 +01:00
m_stackBoundary = level ;
2011-01-19 17:34:28 +01:00
foreach ( StackFrame frame , m_qmlEngine - > stackHandler ( ) - > frames ( ) ) {
frame . level = level + + ;
frames . append ( frame ) ;
2011-01-14 14:25:02 +01:00
}
2011-01-19 17:34:28 +01:00
q - > stackHandler ( ) - > setFrames ( frames ) ;
}
void QmlCppEnginePrivate : : qmlStackChanged ( )
{
2011-01-19 18:59:53 +01:00
StackFrames frames = m_qmlEngine - > stackHandler ( ) - > frames ( ) ;
q - > stackHandler ( ) - > setFrames ( frames ) ;
m_stackBoundary = frames . size ( ) ;
2011-01-19 17:34:28 +01:00
}
////////////////////////////////////////////////////////////////////////
//
// QmlCppEngine
//
////////////////////////////////////////////////////////////////////////
2011-02-24 16:50:15 +01:00
QmlCppEngine : : QmlCppEngine ( const DebuggerStartParameters & sp ,
DebuggerEngineType slaveEngineType ,
QString * errorMessage )
2011-01-19 17:34:28 +01:00
: DebuggerEngine ( sp ) , d ( new QmlCppEnginePrivate ( this , sp ) )
{
2011-02-24 16:50:15 +01:00
setObjectName ( QLatin1String ( " QmlCppEngine " ) ) ;
d - > m_cppEngine = DebuggerRunControlFactory : : createEngine ( slaveEngineType , sp , this , errorMessage ) ;
if ( ! d - > m_cppEngine ) {
2011-03-01 17:07:15 +01:00
* errorMessage = tr ( " The slave debugging engine required for combined QML/C++-Debugging could not be created: %1 " ) . arg ( * errorMessage ) ;
2011-02-24 16:50:15 +01:00
return ;
}
d - > m_activeEngine = d - > m_cppEngine ;
connect ( d - > m_cppEngine - > stackHandler ( ) - > model ( ) , SIGNAL ( modelReset ( ) ) ,
d . data ( ) , SLOT ( cppStackChanged ( ) ) , Qt : : QueuedConnection ) ;
connect ( d - > m_qmlEngine - > stackHandler ( ) - > model ( ) , SIGNAL ( modelReset ( ) ) ,
d . data ( ) , SLOT ( qmlStackChanged ( ) ) , Qt : : QueuedConnection ) ;
connect ( d - > m_cppEngine , SIGNAL ( stackFrameCompleted ( ) ) , this , SIGNAL ( stackFrameCompleted ( ) ) ) ;
2011-07-08 10:09:02 +02:00
connect ( d - > m_cppEngine , SIGNAL ( requestRemoteSetup ( ) ) , this , SIGNAL ( requestRemoteSetup ( ) ) ) ;
2011-02-24 16:50:15 +01:00
connect ( d - > m_qmlEngine , SIGNAL ( stackFrameCompleted ( ) ) , this , SIGNAL ( stackFrameCompleted ( ) ) ) ;
2010-08-18 13:54:12 +02:00
}
QmlCppEngine : : ~ QmlCppEngine ( )
{
2010-11-16 16:17:16 +01:00
delete d - > m_qmlEngine ;
delete d - > m_cppEngine ;
2010-08-18 13:54:12 +02:00
}
2011-02-17 10:08:57 +01:00
bool QmlCppEngine : : setToolTipExpression ( const QPoint & mousePos ,
2011-02-11 15:00:13 +01:00
TextEditor : : ITextEditor * editor , const DebuggerToolTipContext & ctx )
2010-08-18 13:54:12 +02:00
{
2011-02-17 10:08:57 +01:00
return d - > m_activeEngine - > setToolTipExpression ( mousePos , editor , ctx ) ;
2010-08-18 13:54:12 +02:00
}
2010-11-26 10:10:00 +01:00
void QmlCppEngine : : updateWatchData ( const WatchData & data ,
const WatchUpdateFlags & flags )
2010-08-18 13:54:12 +02:00
{
2010-09-13 13:30:35 +02:00
d - > m_activeEngine - > updateWatchData ( data , flags ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : watchPoint ( const QPoint & point )
{
2010-09-13 13:30:35 +02:00
d - > m_cppEngine - > watchPoint ( point ) ;
2010-08-18 13:54:12 +02:00
}
2010-12-14 12:29:32 +01:00
void QmlCppEngine : : fetchMemory ( MemoryAgent * ma , QObject * obj ,
2010-08-18 13:54:12 +02:00
quint64 addr , quint64 length )
{
2010-12-14 12:29:32 +01:00
d - > m_cppEngine - > fetchMemory ( ma , obj , addr , length ) ;
2010-08-18 13:54:12 +02:00
}
2010-12-14 12:29:32 +01:00
void QmlCppEngine : : fetchDisassembler ( DisassemblerAgent * da )
2010-08-18 13:54:12 +02:00
{
2010-12-14 12:29:32 +01:00
d - > m_cppEngine - > fetchDisassembler ( da ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : activateFrame ( int index )
{
2011-01-19 18:59:53 +01:00
if ( index > = d - > m_stackBoundary )
d - > m_qmlEngine - > activateFrame ( index - d - > m_stackBoundary ) ;
else
d - > m_cppEngine - > activateFrame ( index ) ;
2011-02-02 13:35:42 +01:00
stackHandler ( ) - > setCurrentIndex ( index ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : reloadModules ( )
{
2010-09-13 13:30:35 +02:00
d - > m_cppEngine - > reloadModules ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : examineModules ( )
{
2010-09-13 13:30:35 +02:00
d - > m_cppEngine - > examineModules ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : loadSymbols ( const QString & moduleName )
{
2010-09-13 13:30:35 +02:00
d - > m_cppEngine - > loadSymbols ( moduleName ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : loadAllSymbols ( )
{
2010-09-13 13:30:35 +02:00
d - > m_cppEngine - > loadAllSymbols ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : requestModuleSymbols ( const QString & moduleName )
{
2010-09-13 13:30:35 +02:00
d - > m_cppEngine - > requestModuleSymbols ( moduleName ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : reloadRegisters ( )
{
2010-09-13 13:30:35 +02:00
d - > m_cppEngine - > reloadRegisters ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : reloadSourceFiles ( )
{
2010-09-13 13:30:35 +02:00
d - > m_cppEngine - > reloadSourceFiles ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : reloadFullStack ( )
{
2010-09-13 13:30:35 +02:00
d - > m_cppEngine - > reloadFullStack ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : setRegisterValue ( int regnr , const QString & value )
{
2010-09-13 13:30:35 +02:00
d - > m_cppEngine - > setRegisterValue ( regnr , value ) ;
2010-08-18 13:54:12 +02:00
}
unsigned QmlCppEngine : : debuggerCapabilities ( ) const
{
// ### this could also be an OR of both engines' capabilities
2010-09-13 13:30:35 +02:00
return d - > m_cppEngine - > debuggerCapabilities ( ) ;
2010-08-18 13:54:12 +02:00
}
2011-02-28 10:58:21 +01:00
bool QmlCppEngine : : canWatchWidgets ( ) const
{
return d - > m_activeEngine - > canWatchWidgets ( ) ;
}
bool QmlCppEngine : : acceptsWatchesWhileRunning ( ) const
{
return d - > m_activeEngine - > acceptsWatchesWhileRunning ( ) ;
}
2010-08-30 07:52:41 +02:00
bool QmlCppEngine : : isSynchronous ( ) const
2010-08-18 13:54:12 +02:00
{
2010-09-13 13:30:35 +02:00
return d - > m_activeEngine - > isSynchronous ( ) ;
2010-08-18 13:54:12 +02:00
}
2010-09-01 17:36:09 +02:00
QByteArray QmlCppEngine : : qtNamespace ( ) const
2010-08-18 13:54:12 +02:00
{
2010-09-13 13:30:35 +02:00
return d - > m_cppEngine - > qtNamespace ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : createSnapshot ( )
{
2010-09-13 13:30:35 +02:00
d - > m_cppEngine - > createSnapshot ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : updateAll ( )
{
2010-09-13 13:30:35 +02:00
d - > m_activeEngine - > updateAll ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : attemptBreakpointSynchronization ( )
{
2010-09-13 13:30:35 +02:00
d - > m_cppEngine - > attemptBreakpointSynchronization ( ) ;
2010-12-03 12:07:32 +01:00
d - > m_qmlEngine - > attemptBreakpointSynchronization ( ) ;
2010-08-18 13:54:12 +02:00
}
2011-06-24 16:25:30 +02:00
bool QmlCppEngine : : acceptsBreakpoint ( BreakpointModelId id ) const
2010-10-05 11:01:14 +02:00
{
2010-11-10 16:33:11 +01:00
return d - > m_cppEngine - > acceptsBreakpoint ( id )
| | d - > m_qmlEngine - > acceptsBreakpoint ( id ) ;
2010-10-05 11:01:14 +02:00
}
2010-08-18 13:54:12 +02:00
void QmlCppEngine : : selectThread ( int index )
{
2010-09-13 13:30:35 +02:00
d - > m_cppEngine - > selectThread ( index ) ;
2010-08-18 13:54:12 +02:00
}
2010-11-26 10:10:00 +01:00
void QmlCppEngine : : assignValueInDebugger ( const WatchData * data ,
const QString & expr , const QVariant & value )
2010-08-18 13:54:12 +02:00
{
2010-11-26 10:10:00 +01:00
d - > m_activeEngine - > assignValueInDebugger ( data , expr , value ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : detachDebugger ( )
{
2010-09-13 13:30:35 +02:00
d - > m_qmlEngine - > detachDebugger ( ) ;
d - > m_cppEngine - > detachDebugger ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : executeStep ( )
2011-01-14 17:08:59 +01:00
{
if ( d - > m_activeEngine = = d - > m_qmlEngine ) {
QTC_ASSERT ( d - > m_cppEngine - > state ( ) = = InferiorRunOk , /**/ ) ;
2011-01-19 14:34:25 +01:00
if ( d - > m_cppEngine - > setupQmlStep ( true ) )
return ; // Wait for callback to readyToExecuteQmlStep()
2011-01-25 10:46:57 +01:00
} else {
notifyInferiorRunRequested ( ) ;
d - > m_cppEngine - > executeStep ( ) ;
2011-01-14 17:08:59 +01:00
}
}
2011-01-19 14:34:25 +01:00
void QmlCppEngine : : readyToExecuteQmlStep ( )
2010-08-18 13:54:12 +02:00
{
2011-01-14 14:25:02 +01:00
notifyInferiorRunRequested ( ) ;
2011-01-19 14:34:25 +01:00
d - > m_qmlEngine - > executeStep ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : executeStepOut ( )
{
2011-01-14 14:25:02 +01:00
notifyInferiorRunRequested ( ) ;
2010-09-13 13:30:35 +02:00
d - > m_activeEngine - > executeStepOut ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : executeNext ( )
{
2011-01-14 14:25:02 +01:00
notifyInferiorRunRequested ( ) ;
2010-09-13 13:30:35 +02:00
d - > m_activeEngine - > executeNext ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : executeStepI ( )
{
2011-01-14 14:25:02 +01:00
notifyInferiorRunRequested ( ) ;
2011-01-12 12:10:12 +01:00
d - > m_activeEngine - > executeStepI ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : executeNextI ( )
{
2011-01-14 14:25:02 +01:00
notifyInferiorRunRequested ( ) ;
2010-09-13 13:30:35 +02:00
d - > m_activeEngine - > executeNextI ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : executeReturn ( )
{
2011-01-14 14:25:02 +01:00
notifyInferiorRunRequested ( ) ;
2010-09-13 13:30:35 +02:00
d - > m_activeEngine - > executeReturn ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : continueInferior ( )
{
2011-01-19 10:48:39 +01:00
EDEBUG ( " \n MASTER CONTINUE INFERIOR "
< < d - > m_cppEngine - > state ( ) < < d - > m_qmlEngine - > state ( ) ) ;
2011-01-14 14:25:02 +01:00
notifyInferiorRunRequested ( ) ;
if ( d - > m_cppEngine - > state ( ) = = InferiorStopOk ) {
d - > m_cppEngine - > continueInferior ( ) ;
} else if ( d - > m_qmlEngine - > state ( ) = = InferiorStopOk ) {
d - > m_qmlEngine - > continueInferior ( ) ;
2010-11-15 17:09:28 +01:00
} else {
2011-01-14 14:25:02 +01:00
QTC_ASSERT ( false , qDebug ( ) < < " MASTER CANNOT CONTINUE INFERIOR "
< < d - > m_cppEngine - > state ( ) < < d - > m_qmlEngine - > state ( ) ) ;
notifyEngineIll ( ) ;
2010-11-15 17:09:28 +01:00
}
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : interruptInferior ( )
{
2011-01-19 10:48:39 +01:00
EDEBUG ( " \n MASTER INTERRUPT INFERIOR " ) ;
2011-04-18 16:49:41 +02:00
d - > m_cppEngine - > requestInterruptInferior ( ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : requestInterruptInferior ( )
{
2011-02-25 15:27:13 +01:00
EDEBUG ( " \n MASTER REQUEST INTERRUPT INFERIOR " ) ;
2010-11-15 17:09:28 +01:00
DebuggerEngine : : requestInterruptInferior ( ) ;
2010-08-18 13:54:12 +02:00
}
2011-02-23 10:16:11 +01:00
void QmlCppEngine : : executeRunToLine ( const ContextData & data )
2010-08-18 13:54:12 +02:00
{
2011-02-23 10:16:11 +01:00
d - > m_activeEngine - > executeRunToLine ( data ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : executeRunToFunction ( const QString & functionName )
{
2010-09-13 13:30:35 +02:00
d - > m_activeEngine - > executeRunToFunction ( functionName ) ;
2010-08-18 13:54:12 +02:00
}
2011-02-23 10:16:11 +01:00
void QmlCppEngine : : executeJumpToLine ( const ContextData & data )
2010-08-18 13:54:12 +02:00
{
2011-02-23 10:16:11 +01:00
d - > m_activeEngine - > executeJumpToLine ( data ) ;
2010-08-18 13:54:12 +02:00
}
void QmlCppEngine : : executeDebuggerCommand ( const QString & command )
{
2011-01-19 10:48:39 +01:00
d - > m_cppEngine - > executeDebuggerCommand ( command ) ;
2010-08-18 13:54:12 +02:00
}
2010-11-15 17:09:28 +01:00
/////////////////////////////////////////////////////////
2011-01-14 14:25:02 +01:00
void QmlCppEngine : : setupEngine ( )
2010-11-15 17:09:28 +01:00
{
2011-01-19 10:48:39 +01:00
EDEBUG ( " \n MASTER SETUP ENGINE " ) ;
2011-02-08 16:17:13 +01:00
d - > m_activeEngine = d - > m_cppEngine ;
d - > m_stackBoundary = 0 ;
2011-01-14 18:16:40 +01:00
d - > m_qmlEngine - > setupSlaveEngine ( ) ;
d - > m_cppEngine - > setupSlaveEngine ( ) ;
2011-01-14 14:25:02 +01:00
}
2010-11-15 17:09:28 +01:00
2011-01-14 14:25:02 +01:00
void QmlCppEngine : : notifyEngineRunAndInferiorRunOk ( )
{
2011-01-19 10:48:39 +01:00
EDEBUG ( " \n MASTER NOTIFY ENGINE RUN AND INFERIOR RUN OK " ) ;
2011-01-14 14:25:02 +01:00
DebuggerEngine : : notifyEngineRunAndInferiorRunOk ( ) ;
2010-11-15 17:09:28 +01:00
}
2010-08-18 13:54:12 +02:00
void QmlCppEngine : : notifyInferiorRunOk ( )
{
2011-01-19 10:48:39 +01:00
EDEBUG ( " \n MASTER NOTIFY INFERIOR RUN OK " ) ;
2010-08-18 13:54:12 +02:00
DebuggerEngine : : notifyInferiorRunOk ( ) ;
}
2011-01-14 14:25:02 +01:00
void QmlCppEngine : : notifyInferiorSpontaneousStop ( )
2010-08-18 13:54:12 +02:00
{
2011-01-19 10:48:39 +01:00
EDEBUG ( " \n MASTER SPONTANEOUS STOP OK " ) ;
2011-01-14 14:25:02 +01:00
DebuggerEngine : : notifyInferiorSpontaneousStop ( ) ;
2010-08-18 13:54:12 +02:00
}
2011-01-14 14:25:02 +01:00
void QmlCppEngine : : notifyInferiorShutdownOk ( )
2010-08-18 13:54:12 +02:00
{
2011-01-19 10:48:39 +01:00
EDEBUG ( " \n MASTER INFERIOR SHUTDOWN OK " ) ;
2011-01-14 14:25:02 +01:00
DebuggerEngine : : notifyInferiorShutdownOk ( ) ;
2010-08-18 13:54:12 +02:00
}
2011-01-14 14:25:02 +01:00
void QmlCppEngine : : setupInferior ( )
2010-08-18 13:54:12 +02:00
{
2011-01-19 10:48:39 +01:00
EDEBUG ( " \n MASTER SETUP INFERIOR " ) ;
2011-01-14 18:16:40 +01:00
d - > m_qmlEngine - > setupSlaveInferior ( ) ;
d - > m_cppEngine - > setupSlaveInferior ( ) ;
2010-08-18 13:54:12 +02:00
}
2011-01-14 14:25:02 +01:00
void QmlCppEngine : : runEngine ( )
2010-08-18 13:54:12 +02:00
{
2011-01-19 10:48:39 +01:00
EDEBUG ( " \n MASTER RUN ENGINE " ) ;
2011-01-14 18:16:40 +01:00
d - > m_qmlEngine - > runSlaveEngine ( ) ;
d - > m_cppEngine - > runSlaveEngine ( ) ;
2010-08-18 13:54:12 +02:00
}
2011-01-14 14:25:02 +01:00
void QmlCppEngine : : shutdownInferior ( )
2010-08-18 13:54:12 +02:00
{
2011-01-19 10:48:39 +01:00
EDEBUG ( " \n MASTER SHUTDOWN INFERIOR " ) ;
2011-01-14 14:25:02 +01:00
d - > m_qmlEngine - > quitDebugger ( ) ;
2010-08-18 13:54:12 +02:00
}
2010-11-15 17:09:28 +01:00
void QmlCppEngine : : shutdownEngine ( )
2010-08-18 13:54:12 +02:00
{
2011-01-19 10:48:39 +01:00
EDEBUG ( " \n MASTER SHUTDOWN ENGINE " ) ;
2011-01-14 18:16:40 +01:00
d - > m_qmlEngine - > shutdownSlaveEngine ( ) ;
d - > m_cppEngine - > shutdownSlaveEngine ( ) ;
2010-08-18 13:54:12 +02:00
}
2011-01-14 14:25:02 +01:00
void QmlCppEngine : : setState ( DebuggerState newState , bool forced )
2010-08-18 13:54:12 +02:00
{
2011-01-19 10:48:39 +01:00
EDEBUG ( " SET MASTER STATE: " < < newState ) ;
EDEBUG ( " CPP STATE: " < < d - > m_cppEngine - > state ( ) ) ;
EDEBUG ( " QML STATE: " < < d - > m_qmlEngine - > state ( ) ) ;
2011-01-14 14:25:02 +01:00
DebuggerEngine : : setState ( newState , forced ) ;
2010-08-18 13:54:12 +02:00
}
2011-01-14 14:25:02 +01:00
void QmlCppEngine : : slaveEngineStateChanged
( DebuggerEngine * slaveEngine , const DebuggerState newState )
2010-11-15 17:09:28 +01:00
{
2011-01-14 19:32:47 +01:00
DebuggerEngine * otherEngine = slaveEngine = = d - > m_cppEngine
? d - > m_qmlEngine : d - > m_cppEngine ;
2011-01-14 14:25:02 +01:00
2011-01-19 10:48:39 +01:00
EDEBUG ( " GOT SLAVE STATE: " < < slaveEngine < < newState ) ;
EDEBUG ( " OTHER ENGINE: " < < otherEngine < < otherEngine - > state ( ) ) ;
EDEBUG ( " COMBINED ENGINE: " < < this < < state ( ) < < isDying ( ) ) ;
2010-08-18 13:54:12 +02:00
2010-11-15 17:09:28 +01:00
switch ( newState ) {
2011-01-14 14:25:02 +01:00
case DebuggerNotReady :
case InferiorUnrunnable :
break ;
case EngineSetupRequested :
break ;
case EngineSetupFailed :
notifyEngineSetupFailed ( ) ;
break ;
case EngineSetupOk :
if ( otherEngine - > state ( ) = = EngineSetupOk )
2010-11-15 17:09:28 +01:00
notifyEngineSetupOk ( ) ;
2011-01-14 14:25:02 +01:00
else
2011-01-19 10:48:39 +01:00
EDEBUG ( " ... WAITING FOR OTHER ENGINE SETUP... " ) ;
2011-01-14 14:25:02 +01:00
break ;
case InferiorSetupRequested :
break ;
case InferiorSetupFailed :
2011-02-02 10:42:32 +01:00
if ( otherEngine - > state ( ) = = InferiorRunOk )
otherEngine - > quitDebugger ( ) ;
else
notifyInferiorSetupFailed ( ) ;
2011-01-14 14:25:02 +01:00
break ;
case InferiorSetupOk :
if ( otherEngine - > state ( ) = = InferiorSetupOk )
notifyInferiorSetupOk ( ) ;
else
2011-01-19 10:48:39 +01:00
EDEBUG ( " ... WAITING FOR OTHER INFERIOR SETUP... " ) ;
2011-01-14 14:25:02 +01:00
break ;
case EngineRunRequested :
break ;
case EngineRunFailed :
2011-02-02 10:42:32 +01:00
if ( otherEngine - > state ( ) = = InferiorRunOk )
otherEngine - > quitDebugger ( ) ;
else
notifyEngineRunFailed ( ) ;
2011-01-14 14:25:02 +01:00
break ;
2010-11-15 17:09:28 +01:00
case InferiorRunRequested :
2011-01-14 14:25:02 +01:00
break ;
case InferiorRunFailed :
notifyInferiorRunFailed ( ) ;
break ;
case InferiorRunOk :
2011-01-14 18:47:44 +01:00
if ( state ( ) = = EngineRunRequested ) {
2011-02-02 15:07:29 +01:00
if ( otherEngine - > state ( ) = = InferiorRunOk )
2011-01-14 18:47:44 +01:00
notifyEngineRunAndInferiorRunOk ( ) ;
2011-02-02 15:07:29 +01:00
else if ( otherEngine - > state ( ) = = InferiorStopOk )
2011-01-14 18:47:44 +01:00
notifyEngineRunAndInferiorStopOk ( ) ;
else
2011-01-19 10:48:39 +01:00
EDEBUG ( " ... WAITING FOR OTHER INFERIOR RUN " ) ;
2011-01-14 18:47:44 +01:00
} else {
if ( otherEngine - > state ( ) = = InferiorRunOk ) {
2011-01-19 10:48:39 +01:00
EDEBUG ( " PLANNED INFERIOR RUN " ) ;
2011-01-14 18:47:44 +01:00
notifyInferiorRunOk ( ) ;
2011-01-19 19:28:16 +01:00
} else if ( otherEngine - > state ( ) = = InferiorStopOk ) {
EDEBUG ( " PLANNED SINGLE INFERIOR RUN " ) ;
2011-01-14 18:47:44 +01:00
} else {
2011-01-19 10:48:39 +01:00
EDEBUG ( " **** INFERIOR RUN NOT OK **** " ) ;
2011-01-14 18:47:44 +01:00
}
}
2011-01-14 14:25:02 +01:00
break ;
2010-08-18 13:54:12 +02:00
case InferiorStopRequested :
2011-01-14 14:25:02 +01:00
break ;
case InferiorStopFailed :
notifyInferiorStopFailed ( ) ;
2010-08-18 13:54:12 +02:00
break ;
case InferiorStopOk :
2011-01-14 14:25:02 +01:00
if ( isDying ( ) ) {
2011-01-19 10:48:39 +01:00
EDEBUG ( " ... AN INFERIOR STOPPED DURING SHUTDOWN " ) ;
2011-04-18 16:49:41 +02:00
if ( state ( ) = = InferiorStopRequested ) {
notifyInferiorStopOk ( ) ;
}
2011-01-14 14:25:02 +01:00
} else {
2011-01-14 19:04:16 +01:00
if ( slaveEngine ! = d - > m_activeEngine ) {
QString engineName = slaveEngine = = d - > m_cppEngine
? QLatin1String ( " C++ " ) : QLatin1String ( " QML " ) ;
showStatusMessage ( tr ( " %1 debugger activated " ) . arg ( engineName ) ) ;
d - > m_activeEngine = slaveEngine ;
}
2011-01-19 19:28:16 +01:00
if ( otherEngine - > state ( ) = = InferiorStopOk ) {
EDEBUG ( " ... BOTH STOPPED " ) ;
} else if ( otherEngine - > state ( ) = = InferiorShutdownOk ) {
2011-01-19 10:48:39 +01:00
EDEBUG ( " ... STOPP " ) ;
2011-01-14 14:25:02 +01:00
} else if ( state ( ) = = InferiorStopRequested ) {
2011-01-19 10:48:39 +01:00
EDEBUG ( " ... AN INFERIOR STOPPED EXPECTEDLY " ) ;
2011-01-14 14:25:02 +01:00
notifyInferiorStopOk ( ) ;
2011-07-12 14:18:48 +02:00
} else if ( otherEngine - > state ( ) = = EngineRunRequested & & otherEngine = = d - > m_qmlEngine ) {
EDEBUG ( " ... BREAKPOINT HIT IN C++ BEFORE QML STARTUP " ) ;
QTimer : : singleShot ( 0 , this , SLOT ( skipCppBreakpoint ( ) ) ) ;
2011-02-02 10:42:32 +01:00
} else if ( state ( ) = = EngineRunRequested ) {
EDEBUG ( " ... AN INFERIOR FAILED STARTUP, OTHER STOPPED EXPECTEDLY " ) ;
2011-04-28 16:14:38 +02:00
// wait for failure notification from other engine
2011-01-14 14:25:02 +01:00
} else {
2011-01-19 19:28:16 +01:00
EDEBUG ( " ... AN INFERIOR STOPPED SPONTANEOUSLY " ) ;
2011-01-14 14:25:02 +01:00
notifyInferiorSpontaneousStop ( ) ;
2010-08-18 13:54:12 +02:00
}
}
break ;
2011-01-14 14:25:02 +01:00
case InferiorExitOk :
2010-08-18 13:54:12 +02:00
break ;
2010-11-15 17:09:28 +01:00
case InferiorShutdownRequested :
2010-08-18 13:54:12 +02:00
break ;
2011-01-14 14:25:02 +01:00
case InferiorShutdownFailed :
notifyInferiorShutdownFailed ( ) ;
break ;
case InferiorShutdownOk :
2011-01-14 19:32:47 +01:00
if ( otherEngine - > state ( ) = = InferiorShutdownOk ) {
if ( state ( ) = = InferiorRunOk )
notifyInferiorExited ( ) ;
else
notifyInferiorShutdownOk ( ) ;
} else if ( otherEngine - > state ( ) = = InferiorRunOk ) {
2011-01-14 14:25:02 +01:00
otherEngine - > quitDebugger ( ) ;
2011-01-14 19:32:47 +01:00
} else if ( otherEngine - > state ( ) = = InferiorStopOk ) {
2011-01-14 14:25:02 +01:00
otherEngine - > quitDebugger ( ) ;
2011-02-02 10:42:32 +01:00
} else if ( otherEngine - > state ( ) = = EngineRunFailed ) {
EDEBUG ( " ... INFERIOR STOPPED, OTHER ENGINE FAILED " ) ;
notifyEngineRunFailed ( ) ;
} else if ( otherEngine - > state ( ) = = InferiorSetupFailed ) {
EDEBUG ( " ... INFERIOR STOPPED, OTHER INFERIOR FAILED " ) ;
notifyInferiorSetupFailed ( ) ;
2011-01-14 19:32:47 +01:00
}
2011-01-14 14:25:02 +01:00
break ;
2010-11-16 16:17:16 +01:00
case EngineShutdownRequested :
break ;
2011-01-14 14:25:02 +01:00
case EngineShutdownFailed :
notifyEngineShutdownFailed ( ) ;
2010-08-18 13:54:12 +02:00
break ;
2011-01-14 14:25:02 +01:00
case EngineShutdownOk :
if ( otherEngine - > state ( ) = = EngineShutdownOk )
2011-01-14 17:34:42 +01:00
; // Wait for DebuggerFinished.
2011-01-14 14:25:02 +01:00
else
2011-01-19 10:48:39 +01:00
EDEBUG ( " ... WAITING FOR OTHER ENGINE SHUTDOWN... " ) ;
2010-08-18 13:54:12 +02:00
break ;
2011-01-14 14:25:02 +01:00
case DebuggerFinished :
2011-01-14 17:34:42 +01:00
if ( otherEngine - > state ( ) = = DebuggerFinished )
notifyEngineShutdownOk ( ) ;
else
2011-01-19 10:48:39 +01:00
EDEBUG ( " ... WAITING FOR OTHER DEBUGGER TO FINISH... " ) ;
2011-01-14 17:34:42 +01:00
break ;
2010-08-18 13:54:12 +02:00
}
}
2010-12-10 12:41:44 +01:00
void QmlCppEngine : : handleRemoteSetupDone ( int gdbServerPort , int qmlPort )
{
2011-01-19 10:48:39 +01:00
EDEBUG ( " MASTER REMOTE SETUP DONE " ) ;
2010-12-10 12:41:44 +01:00
d - > m_qmlEngine - > handleRemoteSetupDone ( gdbServerPort , qmlPort ) ;
d - > m_cppEngine - > handleRemoteSetupDone ( gdbServerPort , qmlPort ) ;
}
void QmlCppEngine : : handleRemoteSetupFailed ( const QString & message )
{
2011-01-19 10:48:39 +01:00
EDEBUG ( " MASTER REMOTE SETUP FAILED " ) ;
2010-12-10 12:41:44 +01:00
d - > m_qmlEngine - > handleRemoteSetupFailed ( message ) ;
d - > m_cppEngine - > handleRemoteSetupFailed ( message ) ;
}
2011-02-21 17:01:40 +01:00
void QmlCppEngine : : showMessage ( const QString & msg , int channel , int timeout ) const
{
2011-04-20 15:52:44 +02:00
if ( channel = = AppOutput | | channel = = AppError | | channel = = AppStuff ) {
2011-02-21 17:01:40 +01:00
// message is from CppEngine, allow qml engine to process
d - > m_qmlEngine - > filterApplicationMessage ( msg , channel ) ;
}
DebuggerEngine : : showMessage ( msg , channel , timeout ) ;
}
2011-07-12 14:18:48 +02:00
void QmlCppEngine : : skipCppBreakpoint ( )
{
// only used to skip breakpoint in CPP when QML not ready yet
QTC_ASSERT ( d - > m_cppEngine - > state ( ) = = InferiorStopOk , return ) ;
QTC_ASSERT ( d - > m_qmlEngine - > state ( ) = = EngineRunRequested , return ) ;
if ( ! d - > m_msg ) {
Core : : ICore * const core = Core : : ICore : : instance ( ) ;
d - > m_msg = new QMessageBox ( core - > mainWindow ( ) ) ;
}
if ( d - > m_msg - > isHidden ( ) ) {
d - > m_msg - > setIcon ( QMessageBox : : Warning ) ;
d - > m_msg - > setWindowTitle ( tr ( " QML/C++ Debugging " ) ) ;
d - > m_msg - > setText ( tr ( " Cannot stop execution before QML engine is started. Skipping breakpoint. \n Suggestions: Move the breakpoint after QmlViewer initialization or switch to C++ only debugging " ) ) ;
d - > m_msg - > setStandardButtons ( QMessageBox : : Ok ) ;
d - > m_msg - > setDefaultButton ( QMessageBox : : Ok ) ;
d - > m_msg - > setModal ( false ) ;
d - > m_msg - > show ( ) ;
}
d - > m_cppEngine - > continueInferior ( ) ;
resetLocation ( ) ;
}
2010-09-13 13:30:35 +02:00
DebuggerEngine * QmlCppEngine : : cppEngine ( ) const
{
return d - > m_cppEngine ;
}
2010-12-03 12:07:32 +01:00
} // namespace Internal
2010-08-18 13:54:12 +02:00
} // namespace Debugger
2011-01-19 17:34:28 +01:00
# include "qmlcppengine.moc"