@ -11,7 +11,7 @@
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with cpp - ethereum . If not , see < http : //www.gnu.org/licenses/>.
along with cpp - ethereum . If not , see < http : //www.gnu.org/licenses/>.
*/
*/
/** @file AssemblyDebuggerCtrl.cpp
/** @file AssemblyDebuggerCon tro l.cpp
* @ author Yann yann @ ethdev . com
* @ author Yann yann @ ethdev . com
* @ date 2014
* @ date 2014
* display opcode debugging .
* display opcode debugging .
@ -25,7 +25,7 @@
# include <libdevcore/CommonJS.h>
# include <libdevcore/CommonJS.h>
# include <libethereum/Transaction.h>
# include <libethereum/Transaction.h>
# include "AssemblyDebuggerModel.h"
# include "AssemblyDebuggerModel.h"
# include "AssemblyDebuggerCtrl.h"
# include "AssemblyDebuggerCon tro l.h"
# include "KeyEventManager.h"
# include "KeyEventManager.h"
# include "AppContext.h"
# include "AppContext.h"
# include "DebuggingStateWrapper.h"
# include "DebuggingStateWrapper.h"
@ -36,11 +36,12 @@
using namespace dev : : eth ;
using namespace dev : : eth ;
using namespace dev : : mix ;
using namespace dev : : mix ;
AssemblyDebuggerCtrl : : AssemblyDebuggerCtrl ( QTextDocument * _doc ) : Extension ( ExtensionDisplayBehavior : : ModalDialog )
AssemblyDebuggerCon tro l : : AssemblyDebuggerCon tro l ( QTextDocument * _doc ) : Extension ( ExtensionDisplayBehavior : : ModalDialog )
{
{
qRegisterMetaType < QVariableDefinition * > ( " QVariableDefinition* " ) ;
qRegisterMetaType < QVariableDefinition * > ( " QVariableDefinition* " ) ;
qRegisterMetaType < QVariableDefinitionList * > ( " QVariableDefinitionList* " ) ;
qRegisterMetaType < QVariableDefinitionList * > ( " QVariableDefinitionList* " ) ;
qRegisterMetaType < QList < QVariableDefinition * > > ( " QList<QVariableDefinition*> " ) ;
qRegisterMetaType < QList < QVariableDefinition * > > ( " QList<QVariableDefinition*> " ) ;
qRegisterMetaType < QList < QVariableDeclaration * > > ( " QList<QVariableDeclaration*> " ) ;
qRegisterMetaType < QVariableDeclaration * > ( " QVariableDeclaration* " ) ;
qRegisterMetaType < QVariableDeclaration * > ( " QVariableDeclaration* " ) ;
qRegisterMetaType < AssemblyDebuggerData > ( " AssemblyDebuggerData " ) ;
qRegisterMetaType < AssemblyDebuggerData > ( " AssemblyDebuggerData " ) ;
qRegisterMetaType < DebuggingStatusResult > ( " DebuggingStatusResult " ) ;
qRegisterMetaType < DebuggingStatusResult > ( " DebuggingStatusResult " ) ;
@ -53,23 +54,23 @@ AssemblyDebuggerCtrl::AssemblyDebuggerCtrl(QTextDocument* _doc): Extension(Exten
m_doc = _doc ;
m_doc = _doc ;
}
}
QString AssemblyDebuggerCtrl : : contentUrl ( ) const
QString AssemblyDebuggerCon tro l : : contentUrl ( ) const
{
{
return QStringLiteral ( " qrc:/qml/Debugger.qml " ) ;
return QStringLiteral ( " qrc:/qml/Debugger.qml " ) ;
}
}
QString AssemblyDebuggerCtrl : : title ( ) const
QString AssemblyDebuggerCon tro l : : title ( ) const
{
{
return QApplication : : tr ( " debugger " ) ;
return QApplication : : tr ( " debugger " ) ;
}
}
void AssemblyDebuggerCtrl : : start ( ) const
void AssemblyDebuggerCon tro l : : start ( ) const
{
{
//start to listen on F5
//start to listen on F5
m_ctx - > getKeyEventManager ( ) - > registerEvent ( this , SLOT ( keyPressed ( int ) ) ) ;
m_ctx - > getKeyEventManager ( ) - > registerEvent ( this , SLOT ( keyPressed ( int ) ) ) ;
}
}
void AssemblyDebuggerCtrl : : keyPressed ( int _key )
void AssemblyDebuggerCon tro l : : keyPressed ( int _key )
{
{
if ( _key = = Qt : : Key_F5 )
if ( _key = = Qt : : Key_F5 )
{
{
@ -85,14 +86,13 @@ void AssemblyDebuggerCtrl::keyPressed(int _key)
}
}
}
}
void AssemblyDebuggerCtrl : : callContract ( TransactionSettings _tr , Address _contract )
void AssemblyDebuggerCon tro l : : callContract ( TransactionSettings _tr , Address _contract )
{
{
CompilerResult compilerRes = m_compilation - > compile ( m_doc - > toPlainText ( ) ) ;
CompilerResult compilerRes = m_compilation - > compile ( m_doc - > toPlainText ( ) ) ;
if ( ! compilerRes . success )
if ( ! compilerRes . success )
{
AppContext : : getInstance ( ) - > displayMessageDialog ( " debugger " , " compilation failed " ) ;
AppContext : : getInstance ( ) - > displayMessageDialog ( " debugger " , " compilation failed " ) ;
return ;
else
}
{
ContractCallDataEncoder c ;
ContractCallDataEncoder c ;
std : : shared_ptr < QContractDefinition > contractDef = QContractDefinition : : Contract ( m_doc - > toPlainText ( ) ) ;
std : : shared_ptr < QContractDefinition > contractDef = QContractDefinition : : Contract ( m_doc - > toPlainText ( ) ) ;
QFunctionDefinition * f = nullptr ;
QFunctionDefinition * f = nullptr ;
@ -101,13 +101,13 @@ void AssemblyDebuggerCtrl::callContract(TransactionSettings _tr, Address _contra
if ( contractDef - > functions ( ) . at ( k ) - > name ( ) = = _tr . functionId )
if ( contractDef - > functions ( ) . at ( k ) - > name ( ) = = _tr . functionId )
{
{
f = ( QFunctionDefinition * ) contractDef - > functions ( ) . at ( k ) ;
f = ( QFunctionDefinition * ) contractDef - > functions ( ) . at ( k ) ;
break ;
}
}
}
}
if ( ! f )
if ( ! f )
{
AppContext : : getInstance ( ) - > displayMessageDialog ( QApplication : : tr ( " debugger " ) , QApplication : : tr ( " function not found. Please redeploy this contract. " ) ) ;
AppContext : : getInstance ( ) - > displayMessageDialog ( QApplication : : tr ( " debugger " ) , QApplication : : tr ( " function not found. Please redeploy this contract. " ) ) ;
return ;
else
}
{
c . encode ( f - > index ( ) ) ;
c . encode ( f - > index ( ) ) ;
for ( int k = 0 ; k < f - > parameters ( ) . size ( ) ; k + + )
for ( int k = 0 ; k < f - > parameters ( ) . size ( ) ; k + + )
{
{
@ -117,21 +117,23 @@ void AssemblyDebuggerCtrl::callContract(TransactionSettings _tr, Address _contra
DebuggingContent debuggingContent = m_modelDebugger - > callContract ( _contract , c . encodedData ( ) , _tr ) ;
DebuggingContent debuggingContent = m_modelDebugger - > callContract ( _contract , c . encodedData ( ) , _tr ) ;
debuggingContent . returnParameters = c . decode ( f - > returnParameters ( ) , debuggingContent . returnValue ) ;
debuggingContent . returnParameters = c . decode ( f - > returnParameters ( ) , debuggingContent . returnValue ) ;
finalizeExecution ( debuggingContent ) ;
finalizeExecution ( debuggingContent ) ;
}
}
}
}
void AssemblyDebuggerCtrl : : deployContract ( QString _source )
void AssemblyDebuggerCon tro l : : deployContract ( QString _source )
{
{
CompilerResult compilerRes = m_compilation - > compile ( _source ) ;
CompilerResult compilerRes = m_compilation - > compile ( _source ) ;
if ( ! compilerRes . success )
if ( ! compilerRes . success )
{
emit dataAvailable ( false , DebuggingStatusResult : : Compilationfailed ) ;
emit dataAvailable ( false , DebuggingStatusResult : : Compilationfailed ) ;
return ;
else
}
{
m_previousDebugResult = m_modelDebugger - > deployContract ( compilerRes . bytes ) ;
m_previousDebugResult = m_modelDebugger - > deployContract ( compilerRes . bytes ) ;
finalizeExecution ( m_previousDebugResult ) ;
finalizeExecution ( m_previousDebugResult ) ;
}
}
}
void AssemblyDebuggerCtrl : : finalizeExecution ( DebuggingContent _debuggingContent )
void AssemblyDebuggerCon tro l : : finalizeExecution ( DebuggingContent _debuggingContent )
{
{
//we need to wrap states in a QObject before sending to QML.
//we need to wrap states in a QObject before sending to QML.
QList < QObject * > wStates ;
QList < QObject * > wStates ;
@ -145,7 +147,7 @@ void AssemblyDebuggerCtrl::finalizeExecution(DebuggingContent _debuggingContent)
emit dataAvailable ( true , DebuggingStatusResult : : Ok , _debuggingContent . returnParameters , wStates , code ) ;
emit dataAvailable ( true , DebuggingStatusResult : : Ok , _debuggingContent . returnParameters , wStates , code ) ;
}
}
void AssemblyDebuggerCtrl : : updateGUI ( bool _success , DebuggingStatusResult const & _reason , QList < QVariableDefinition * > const & _returnParam , QList < QObject * > const & _wStates , AssemblyDebuggerData const & _code )
void AssemblyDebuggerCon tro l : : updateGUI ( bool _success , DebuggingStatusResult const & _reason , QList < QVariableDefinition * > const & _returnParam , QList < QObject * > const & _wStates , AssemblyDebuggerData const & _code )
{
{
Q_UNUSED ( _reason ) ;
Q_UNUSED ( _reason ) ;
if ( _success )
if ( _success )
@ -160,7 +162,7 @@ void AssemblyDebuggerCtrl::updateGUI(bool _success, DebuggingStatusResult const&
m_ctx - > displayMessageDialog ( QApplication : : tr ( " debugger " ) , QApplication : : tr ( " compilation failed " ) ) ;
m_ctx - > displayMessageDialog ( QApplication : : tr ( " debugger " ) , QApplication : : tr ( " compilation failed " ) ) ;
}
}
void AssemblyDebuggerCtrl : : runTransaction ( TransactionSettings const & _tr )
void AssemblyDebuggerCon tro l : : runTransaction ( TransactionSettings const & _tr )
{
{
QtConcurrent : : run ( [ this , _tr ] ( )
QtConcurrent : : run ( [ this , _tr ] ( )
{
{