From ee43cfd89207a1b6e4e4a9bde05680a200bc25fa Mon Sep 17 00:00:00 2001 From: Heather Anderson Date: Sun, 30 Aug 2020 23:47:54 -0700 Subject: [PATCH 1/3] add more details to messages logged in entity scripts --- libraries/script-engine/src/ScriptEngine.cpp | 45 +++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 3b2a122e71..6a85a9d8ac 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -109,6 +109,7 @@ int functionSignatureMetaID = qRegisterMetaType(); static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine) { + // assemble the message by concatenating our arguments QString message = ""; for (int i = 0; i < context->argumentCount(); i++) { if (i > 0) { @@ -117,14 +118,48 @@ static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine) { message += context->argument(i).toString(); } - if (ScriptEngine *scriptEngine = qobject_cast(engine)) { - scriptEngine->print(message); - // prefix the script engine name to help disambiguate messages in the main debug log - qCDebug(scriptengine_script, "[%s] %s", qUtf8Printable(scriptEngine->getFilename()), qUtf8Printable(message)); - } else { + // was this generated by a script engine? If we don't recognize it then send the message and exit + ScriptEngine* scriptEngine = qobject_cast(engine); + if (scriptEngine == nullptr) { qCDebug(scriptengine_script, "%s", qUtf8Printable(message)); + return QScriptValue(); } + // This message was sent by one of our script engines, let's try to see if we can find the source. + // Note that the first entry in the backtrace should be "print" and is somewhat useless to us + QScriptContext* userContext = context; + while (userContext != nullptr && QScriptContextInfo(userContext).functionType() == QScriptContextInfo::NativeFunction) { + userContext = userContext->parentContext(); + } + QString location; + if (userContext != nullptr) { + QScriptContextInfo contextInfo(userContext); + QString fileName = contextInfo.fileName(); + int lineNumber = contextInfo.lineNumber(); + QString functionName = contextInfo.functionName(); + + location = functionName; + if (lineNumber != -1) { + location = QString("%1:%2").arg(location).arg(lineNumber); + } + if (!fileName.isEmpty()) { + if (location.isEmpty()) { + location = fileName; + } else { + location = QString("%1 at %2").arg(location).arg(fileName); + } + } + } + if (location.isEmpty()) { + location = scriptEngine->getFilename(); + } + + // give the script engine a chance to notify the system about this message + scriptEngine->print(message); + + // send the message to debug log + qCDebug(scriptengine_script, "[%s] %s", qUtf8Printable(location), qUtf8Printable(message)); + return QScriptValue(); } From 4096d75bb4133fb803405333ee50e48f77f52d19 Mon Sep 17 00:00:00 2001 From: Kalila L Date: Tue, 1 Sep 2020 16:46:22 -0400 Subject: [PATCH 2/3] Add checkbox for showing extra source logs. --- interface/src/ui/LogDialog.cpp | 22 ++++++- interface/src/ui/LogDialog.h | 2 + libraries/script-engine/src/ScriptEngine.cpp | 65 ++++++++++--------- .../src/shared/AbstractLoggerInterface.h | 3 + 4 files changed, 61 insertions(+), 31 deletions(-) diff --git a/interface/src/ui/LogDialog.cpp b/interface/src/ui/LogDialog.cpp index 1eaad05e33..645831621b 100644 --- a/interface/src/ui/LogDialog.cpp +++ b/interface/src/ui/LogDialog.cpp @@ -167,6 +167,13 @@ LogDialog::LogDialog(QWidget* parent, AbstractLoggerInterface* logger) : BaseLog } _extraDebuggingBox->show(); connect(_extraDebuggingBox, &QCheckBox::stateChanged, this, &LogDialog::handleExtraDebuggingCheckbox); + + _showSourceDebuggingBox = new QCheckBox("Show script sources", this); + if (_logger->showSourceDebugging()) { + _showSourceDebuggingBox->setCheckState(Qt::Checked); + } + _showSourceDebuggingBox->show(); + connect(_showSourceDebuggingBox, &QCheckBox::stateChanged, this, &LogDialog::handleShowSourceDebuggingCheckbox); _allLogsButton = new QPushButton("All Messages", this); // set object name for css styling @@ -196,8 +203,13 @@ void LogDialog::resizeEvent(QResizeEvent* event) { THIRD_ROW, COMBOBOX_WIDTH, ELEMENT_HEIGHT); - - _keepOnTopBox->setGeometry(width() - ELEMENT_MARGIN - COMBOBOX_WIDTH - ELEMENT_MARGIN - ALL_LOGS_BUTTON_WIDTH - ELEMENT_MARGIN - COMBOBOX_WIDTH - ELEMENT_MARGIN, + _keepOnTopBox->setGeometry(width() - ELEMENT_MARGIN - COMBOBOX_WIDTH - ELEMENT_MARGIN - ALL_LOGS_BUTTON_WIDTH - ELEMENT_MARGIN - COMBOBOX_WIDTH - ELEMENT_MARGIN, + THIRD_ROW, + COMBOBOX_WIDTH, + ELEMENT_HEIGHT); + _showSourceDebuggingBox->setGeometry(width() - ELEMENT_MARGIN - COMBOBOX_WIDTH - ELEMENT_MARGIN - ALL_LOGS_BUTTON_WIDTH + - ELEMENT_MARGIN - COMBOBOX_WIDTH - ELEMENT_MARGIN - ELEMENT_MARGIN + - COMBOBOX_WIDTH - ELEMENT_MARGIN, THIRD_ROW, COMBOBOX_WIDTH, ELEMENT_HEIGHT); @@ -217,6 +229,8 @@ void LogDialog::handleRevealButton() { } void LogDialog::handleAllLogsButton() { + _logger->setShowSourceDebugging(false); + _showSourceDebuggingBox->setCheckState(Qt::Unchecked); _logger->setExtraDebugging(false); _extraDebuggingBox->setCheckState(Qt::Unchecked); _logger->setDebugPrint(true); @@ -238,6 +252,10 @@ void LogDialog::handleAllLogsButton() { printLogFile(); } +void LogDialog::handleShowSourceDebuggingCheckbox(int state) { + _logger->setShowSourceDebugging(state != 0); +} + void LogDialog::handleExtraDebuggingCheckbox(int state) { _logger->setExtraDebugging(state != 0); } diff --git a/interface/src/ui/LogDialog.h b/interface/src/ui/LogDialog.h index d3ee81ca7e..0782ff7148 100644 --- a/interface/src/ui/LogDialog.h +++ b/interface/src/ui/LogDialog.h @@ -33,6 +33,7 @@ public slots: private slots: void handleRevealButton(); + void handleShowSourceDebuggingCheckbox(int); void handleExtraDebuggingCheckbox(int); void handleKeepWindowOnTop(int); void handleDebugPrintBox(int); @@ -55,6 +56,7 @@ protected: private: + QCheckBox* _showSourceDebuggingBox; QCheckBox* _extraDebuggingBox; QCheckBox* _keepOnTopBox; QPushButton* _revealLogButton; diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 6a85a9d8ac..04f1444daa 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -78,7 +79,6 @@ #include "StackTestScriptingInterface.h" #include "ModelScriptingInterface.h" - #include #include "../../midi/src/Midi.h" // FIXME why won't a simpler include work? @@ -127,38 +127,45 @@ static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine) { // This message was sent by one of our script engines, let's try to see if we can find the source. // Note that the first entry in the backtrace should be "print" and is somewhat useless to us - QScriptContext* userContext = context; - while (userContext != nullptr && QScriptContextInfo(userContext).functionType() == QScriptContextInfo::NativeFunction) { - userContext = userContext->parentContext(); - } - QString location; - if (userContext != nullptr) { - QScriptContextInfo contextInfo(userContext); - QString fileName = contextInfo.fileName(); - int lineNumber = contextInfo.lineNumber(); - QString functionName = contextInfo.functionName(); - - location = functionName; - if (lineNumber != -1) { - location = QString("%1:%2").arg(location).arg(lineNumber); + AbstractLoggerInterface* loggerInterface = AbstractLoggerInterface::get(); + if (loggerInterface->showSourceDebugging()) { + QScriptContext* userContext = context; + while (userContext != nullptr && QScriptContextInfo(userContext).functionType() == QScriptContextInfo::NativeFunction) { + userContext = userContext->parentContext(); } - if (!fileName.isEmpty()) { - if (location.isEmpty()) { - location = fileName; - } else { - location = QString("%1 at %2").arg(location).arg(fileName); + QString location; + if (userContext != nullptr) { + QScriptContextInfo contextInfo(userContext); + QString fileName = contextInfo.fileName(); + int lineNumber = contextInfo.lineNumber(); + QString functionName = contextInfo.functionName(); + + location = functionName; + if (lineNumber != -1) { + location = QString("%1:%2").arg(location).arg(lineNumber); + } + if (!fileName.isEmpty()) { + if (location.isEmpty()) { + location = fileName; + } else { + location = QString("%1 at %2").arg(location).arg(fileName); + } } } + if (location.isEmpty()) { + location = scriptEngine->getFilename(); + } + + // give the script engine a chance to notify the system about this message + scriptEngine->print(message); + + // send the message to debug log + qCDebug(scriptengine_script, "[%s] %s", qUtf8Printable(location), qUtf8Printable(message)); + } else { + scriptEngine->print(message); + // prefix the script engine name to help disambiguate messages in the main debug log + qCDebug(scriptengine_script, "[%s] %s", qUtf8Printable(scriptEngine->getFilename()), qUtf8Printable(message)); } - if (location.isEmpty()) { - location = scriptEngine->getFilename(); - } - - // give the script engine a chance to notify the system about this message - scriptEngine->print(message); - - // send the message to debug log - qCDebug(scriptengine_script, "[%s] %s", qUtf8Printable(location), qUtf8Printable(message)); return QScriptValue(); } diff --git a/libraries/shared/src/shared/AbstractLoggerInterface.h b/libraries/shared/src/shared/AbstractLoggerInterface.h index f48496324b..f222442df9 100644 --- a/libraries/shared/src/shared/AbstractLoggerInterface.h +++ b/libraries/shared/src/shared/AbstractLoggerInterface.h @@ -23,6 +23,7 @@ public: static AbstractLoggerInterface* get(); AbstractLoggerInterface(QObject* parent = NULL); ~AbstractLoggerInterface(); + inline bool showSourceDebugging() { return _showSourceDebugging; } inline bool extraDebugging() { return _extraDebugging; } inline bool debugPrint() { return _debugPrint; } inline bool infoPrint() { return _infoPrint; } @@ -31,6 +32,7 @@ public: inline bool suppressPrint() { return _suppressPrint; } inline bool fatalPrint() { return _fatalPrint; } inline bool unknownPrint() { return _unknownPrint; } + inline void setShowSourceDebugging(bool showSourceDebugging) { _showSourceDebugging = showSourceDebugging; } inline void setExtraDebugging(bool extraDebugging) { _extraDebugging = extraDebugging; } inline void setDebugPrint(bool debugPrint) { _debugPrint = debugPrint; } inline void setInfoPrint(bool infoPrint) { _infoPrint = infoPrint; } @@ -49,6 +51,7 @@ signals: void logReceived(QString message); private: + bool _showSourceDebugging{ false }; bool _extraDebugging{ false }; bool _debugPrint{ true }; bool _infoPrint{ true }; From ab46b1fc9e91938f0f04856b1371cc6e293e3880 Mon Sep 17 00:00:00 2001 From: Kalila L Date: Thu, 3 Sep 2020 01:41:31 -0400 Subject: [PATCH 3/3] Update ScriptEngine.cpp Just some revisions... --- libraries/script-engine/src/ScriptEngine.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 04f1444daa..5f46f03427 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -120,7 +120,7 @@ static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine) { // was this generated by a script engine? If we don't recognize it then send the message and exit ScriptEngine* scriptEngine = qobject_cast(engine); - if (scriptEngine == nullptr) { + if (!scriptEngine) { qCDebug(scriptengine_script, "%s", qUtf8Printable(message)); return QScriptValue(); } @@ -130,20 +130,17 @@ static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine) { AbstractLoggerInterface* loggerInterface = AbstractLoggerInterface::get(); if (loggerInterface->showSourceDebugging()) { QScriptContext* userContext = context; - while (userContext != nullptr && QScriptContextInfo(userContext).functionType() == QScriptContextInfo::NativeFunction) { + while (userContext && QScriptContextInfo(userContext).functionType() == QScriptContextInfo::NativeFunction) { userContext = userContext->parentContext(); } QString location; - if (userContext != nullptr) { + if (userContext) { QScriptContextInfo contextInfo(userContext); QString fileName = contextInfo.fileName(); int lineNumber = contextInfo.lineNumber(); QString functionName = contextInfo.functionName(); location = functionName; - if (lineNumber != -1) { - location = QString("%1:%2").arg(location).arg(lineNumber); - } if (!fileName.isEmpty()) { if (location.isEmpty()) { location = fileName; @@ -151,6 +148,9 @@ static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine) { location = QString("%1 at %2").arg(location).arg(fileName); } } + if (lineNumber != -1) { + location = QString("%1:%2").arg(location).arg(lineNumber); + } } if (location.isEmpty()) { location = scriptEngine->getFilename();