diff options
author | Stefan Radomski <github@mintwerk.de> | 2017-08-04 12:41:26 (GMT) |
---|---|---|
committer | Stefan Radomski <github@mintwerk.de> | 2017-08-04 12:41:26 (GMT) |
commit | 008cca1a15ac9178c57de77d2f6699d9de3088cb (patch) | |
tree | af912c58cc32e7b832f2eb40fa86588c11ffa526 /src/uscxml/debug/DebugSession.cpp | |
parent | 045bde78c0587316e0373c7698413412d0f315f9 (diff) | |
download | uscxml-008cca1a15ac9178c57de77d2f6699d9de3088cb.zip uscxml-008cca1a15ac9178c57de77d2f6699d9de3088cb.tar.gz uscxml-008cca1a15ac9178c57de77d2f6699d9de3088cb.tar.bz2 |
Debugger bugfixes and improvements
Diffstat (limited to 'src/uscxml/debug/DebugSession.cpp')
-rw-r--r-- | src/uscxml/debug/DebugSession.cpp | 100 |
1 files changed, 68 insertions, 32 deletions
diff --git a/src/uscxml/debug/DebugSession.cpp b/src/uscxml/debug/DebugSession.cpp index b5c1605..69f9e6c 100644 --- a/src/uscxml/debug/DebugSession.cpp +++ b/src/uscxml/debug/DebugSession.cpp @@ -120,6 +120,9 @@ Data DebugSession::debugPrepare(const Data& data) { if (_interpreter) { // register ourself as a monitor _interpreter.addMonitor(_debugger); + ActionLanguage al; + al.logger = Logger(shared_from_this()); + _interpreter.setActionLanguage(al); _debugger->attachSession(_interpreter.getImpl()->getSessionId(), shared_from_this()); replyData.compound["status"] = Data("success", Data::VERBATIM); @@ -169,6 +172,12 @@ Data DebugSession::debugAttach(const Data& data) { Data DebugSession::debugDetach(const Data& data) { Data replyData; + if (!_isAttached) { + replyData.compound["status"] = Data("failure", Data::VERBATIM); + replyData.compound["reason"] = Data("Not attached to an interpreter", Data::VERBATIM); + return replyData; + } + _isAttached = false; _debugger->detachSession(_interpreter.getImpl()->getSessionId()); @@ -180,7 +189,7 @@ Data DebugSession::debugStart(const Data& data) { Data replyData; if (_isAttached) { - replyData.compound["reason"] = Data("Already started when attached", Data::VERBATIM); + replyData.compound["reason"] = Data("Interpreter always started when attached", Data::VERBATIM); replyData.compound["status"] = Data("failure", Data::VERBATIM); } else if (!_interpreter) { replyData.compound["reason"] = Data("No interpreter attached or loaded", Data::VERBATIM); @@ -194,34 +203,15 @@ Data DebugSession::debugStart(const Data& data) { return replyData; } -void DebugSession::run(void* instance) { - DebugSession* INSTANCE = (DebugSession*)instance; - -#ifdef APPLE - std::string threadName; - threadName += "uscxml::"; - threadName += (INSTANCE->_interpreter.getImpl()->_name.size() > 0 ? INSTANCE->_interpreter.getImpl()->_name : "anon"); - threadName += ".debug"; - - pthread_setname_np(threadName.c_str()); -#endif - - InterpreterState state = USCXML_UNDEF; - while(state != USCXML_FINISHED && INSTANCE->_isRunning) { - state = INSTANCE->_interpreter.step(); - - // if (!INSTANCE->_isStarted) { - // // we have been cancelled - // INSTANCE->_isActive = false; - // return; - // } - } - LOG(INSTANCE->_interpreter.getLogger(), USCXML_DEBUG) << "done" << std::endl; -} - Data DebugSession::debugStop(const Data& data) { Data replyData; + if (_isAttached) { + replyData.compound["reason"] = Data("Cannot stop an attached interpreter", Data::VERBATIM); + replyData.compound["status"] = Data("failure", Data::VERBATIM); + return replyData; + } + if (_interpreter) { // detach from old intepreter _debugger->detachSession(_interpreter.getImpl()->getSessionId()); @@ -246,6 +236,31 @@ Data DebugSession::debugStop(const Data& data) { return replyData; } +void DebugSession::run(void* instance) { + DebugSession* INSTANCE = (DebugSession*)instance; + +#ifdef APPLE + std::string threadName; + threadName += "uscxml::"; + threadName += (INSTANCE->_interpreter.getImpl()->_name.size() > 0 ? INSTANCE->_interpreter.getImpl()->_name : "anon"); + threadName += ".debug"; + + pthread_setname_np(threadName.c_str()); +#endif + + InterpreterState state = USCXML_UNDEF; + while(state != USCXML_FINISHED && INSTANCE->_isRunning) { + state = INSTANCE->_interpreter.step(); + + // if (!INSTANCE->_isStarted) { + // // we have been cancelled + // INSTANCE->_isActive = false; + // return; + // } + } + LOG(INSTANCE->_interpreter.getLogger(), USCXML_DEBUG) << "done" << std::endl; +} + Data DebugSession::debugStep(const Data& data) { std::lock_guard<std::recursive_mutex> lock(_mutex); @@ -270,10 +285,16 @@ Data DebugSession::debugStep(const Data& data) { Data DebugSession::debugResume(const Data& data) { std::lock_guard<std::recursive_mutex> lock(_mutex); + Data replyData; + + if (!_isStepping) { + replyData.compound["reason"] = Data("Interpreter not paused / stepping", Data::VERBATIM); + replyData.compound["status"] = Data("failure", Data::VERBATIM); + return replyData; + } stepping(false); - Data replyData; replyData.compound["status"] = Data("success", Data::VERBATIM); _resumeCond.notify_one(); @@ -283,11 +304,17 @@ Data DebugSession::debugResume(const Data& data) { Data DebugSession::debugPause(const Data& data) { std::lock_guard<std::recursive_mutex> lock(_mutex); + Data replyData; - _skipTo = Breakpoint(); + if (_isStepping) { + replyData.compound["reason"] = Data("Interpreter already paused / stepping", Data::VERBATIM); + replyData.compound["status"] = Data("failure", Data::VERBATIM); + return replyData; + } + + _skipTo = Breakpoint(); // a generic breakpoint that always matches stepping(true); - Data replyData; replyData.compound["status"] = Data("success", Data::VERBATIM); return replyData; @@ -537,15 +564,24 @@ void DebugSession::log(LogSeverity severity, const Event& event) { namelist.compound[name.first] = name.second; } - _debugger->pushData(shared_from_this(), d); + Data toPush; + toPush["log"] = d; + toPush["severity"] = Data(Logger::severityToString(severity)); + _debugger->pushData(shared_from_this(), toPush); } void DebugSession::log(LogSeverity severity, const Data& data) { - _debugger->pushData(shared_from_this(), data); + Data toPush; + toPush["log"] = data; + toPush["severity"] = Data(Logger::severityToString(severity)); + _debugger->pushData(shared_from_this(), toPush); } void DebugSession::log(LogSeverity severity, const std::string& message) { - _debugger->pushData(shared_from_this(), Data(message)); + Data toPush; + toPush["log"] = Data(message); + toPush["severity"] = Data(Logger::severityToString(severity)); + _debugger->pushData(shared_from_this(), toPush); } } |