Obtain script backtrace when a log event is generated in C++ code#1156
Obtain script backtrace when a log event is generated in C++ code#1156daleglass wants to merge 3 commits intovircadia:masterfrom
Conversation
|
Okay, less broken attempt. This shouldn't crash anymore. |
|
The following links are available:
build (macOS-latest, full) build (windows-latest, full) build (ubuntu-18.04, android) |
|
Suggestions:
|
| connect(scriptEngine.data(), &ScriptEngine::clearDebugWindow, scriptEngines, &ScriptEngines::onClearDebugWindow); | ||
|
|
||
|
|
||
| ScriptEngineLoggingAgent *scriptLogger = new ScriptEngineLoggingAgent(scriptEngine.data()); |
There was a problem hiding this comment.
| ScriptEngineLoggingAgent *scriptLogger = new ScriptEngineLoggingAgent(scriptEngine.data()); | |
| ScriptEngineLoggingAgent* scriptLogger = new ScriptEngineLoggingAgent(scriptEngine.data()); |
| // script-engine/src | ||
| // | ||
| // Created by Dale Glass on 04/04/2021. | ||
| // Copyright 2021 Vircadia Contributors |
There was a problem hiding this comment.
| // Copyright 2021 Vircadia Contributors | |
| // Copyright 2021 Vircadia contributors. |
| void ScriptEngineLoggingAgent::functionEntry(qint64 scriptId) { | ||
| if ( scriptId != -1) { |
There was a problem hiding this comment.
| void ScriptEngineLoggingAgent::functionEntry(qint64 scriptId) { | |
| if ( scriptId != -1) { | |
| void ScriptEngineLoggingAgent::functionEntry(qint64 scriptID) { | |
| if (scriptID != -1) { |
| void ScriptEngineLoggingAgent::functionExit(qint64 scriptId, const QScriptValue &returnValue) { | ||
| if ( scriptId != -1) { |
There was a problem hiding this comment.
| void ScriptEngineLoggingAgent::functionExit(qint64 scriptId, const QScriptValue &returnValue) { | |
| if ( scriptId != -1) { | |
| void ScriptEngineLoggingAgent::functionExit(qint64 scriptID, const QScriptValue& returnValue) { | |
| if (scriptID != -1) { |
| // script-engine/src | ||
| // | ||
| // Created by Dale Glass on 04/04/2021. | ||
| // Copyright 2021 Vircadia Contributors |
There was a problem hiding this comment.
| // Copyright 2021 Vircadia Contributors | |
| // Copyright 2021 Vircadia contributors. |
| QStringList ScriptContextHelper::get() { | ||
| QList<QStringList> data = _context.localData(); | ||
|
|
||
| if ( data.isEmpty() ) { |
There was a problem hiding this comment.
| if ( data.isEmpty() ) { | |
| if (data.isEmpty()) { |
|
|
||
| //return _context.localData(); |
There was a problem hiding this comment.
| //return _context.localData(); |
| // shared/src | ||
| // | ||
| // Created by Dale Glass on 04/04/2021. | ||
| // Copyright 2021 Vircadia Contributors |
There was a problem hiding this comment.
| // Copyright 2021 Vircadia Contributors | |
| // Copyright 2021 Vircadia contributors. |
|
|
||
| class ScriptContextHelper { | ||
| public: | ||
| static void push(QStringList context); |
There was a problem hiding this comment.
| static void push(QStringList context); | |
| static void push(const QStringList& context); |
|
|
||
| QThreadStorage<QList<QStringList>> ScriptContextHelper::_context; | ||
|
|
||
| void ScriptContextHelper::push(QStringList context) { |
There was a problem hiding this comment.
| void ScriptContextHelper::push(QStringList context) { | |
| void ScriptContextHelper::push(const QStringList& context) { |
|
|
||
|
|
||
| ScriptEngineLoggingAgent *scriptLogger = new ScriptEngineLoggingAgent(scriptEngine.data()); | ||
| scriptEngine->setAgent(scriptLogger); |
There was a problem hiding this comment.
I agree with david that it would be good to disable this by default so it doesn’t affect the performance of normal scripts. it seems like it adds overhead to every single function call.
I also wonder, is this agent automatically deleted when the script engine dies? what about the associated thread local storage?
There was a problem hiding this comment.
Good point, I'll look into it.
|
Okay, finally reviewed this after needing to to so for... a while. My thoughts...
|
|
I'm still having an eye towards this, especially after #1200 lands (which does use at least part of the technique described here). The only part of the patch I'm interested in here for surviving are the changes to libraries/shared/src/LogHandler.cpp, however I'm unsure how this would work as I'm trying to avoid adding dependencies from shared to script-engine |
|
Hello! Is this still an issue? |
This is a very, very early prototype and doesn't work. Here's the overall idea:
When a C++ function logs something, such as:
We want to figure out where that came from. Which script resulted in this function being called? And this works to some extent:
The problem is that a problem can be found at any arbitrary depth, not just in whatever QScriptEngine calls directly. So I figured out a way around that. Qt has the
QScriptEngineAgent, which allows us invoke code at interesting points, such as script function calls, including calls to native code.So the idea is:
Unfortunately it doesn't quite work. Problems:
So far this is extremely half-baked and guaranteed to run out of stack space right on start due to that last problem. Some help here would be extremely appreciated.