diff options
author | Stefan Radomski <github@mintwerk.de> | 2017-08-09 11:20:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-09 11:20:04 (GMT) |
commit | ee0a17cc63316edd83388a2f8f93b48cdcc6913c (patch) | |
tree | af912c58cc32e7b832f2eb40fa86588c11ffa526 /src | |
parent | 97e72c5cb5e70eca231f74f01097c9b2392b4c98 (diff) | |
parent | 008cca1a15ac9178c57de77d2f6699d9de3088cb (diff) | |
download | uscxml-ee0a17cc63316edd83388a2f8f93b48cdcc6913c.zip uscxml-ee0a17cc63316edd83388a2f8f93b48cdcc6913c.tar.gz uscxml-ee0a17cc63316edd83388a2f8f93b48cdcc6913c.tar.bz2 |
Merge pull request #166 from tklab-tud/sradomski
Debugger bugfixes and improvements
Diffstat (limited to 'src')
-rw-r--r-- | src/uscxml/debug/DebugSession.cpp | 100 | ||||
-rw-r--r-- | src/uscxml/debug/DebugSession.h | 2 | ||||
-rw-r--r-- | src/uscxml/debug/Debugger.cpp | 14 | ||||
-rw-r--r-- | src/uscxml/debug/DebuggerServlet.cpp | 2 | ||||
-rw-r--r-- | src/uscxml/debug/DebuggerServlet.h | 15 |
5 files changed, 77 insertions, 56 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); } } diff --git a/src/uscxml/debug/DebugSession.h b/src/uscxml/debug/DebugSession.h index ab4d79d..ec024f4 100644 --- a/src/uscxml/debug/DebugSession.h +++ b/src/uscxml/debug/DebugSession.h @@ -34,7 +34,7 @@ namespace uscxml { class Debugger; -class USCXML_API DebugSession : public LoggerImpl ,public std::enable_shared_from_this<DebugSession> { +class USCXML_API DebugSession : public LoggerImpl, public std::enable_shared_from_this<DebugSession> { public: DebugSession() { _isRunning = false; diff --git a/src/uscxml/debug/Debugger.cpp b/src/uscxml/debug/Debugger.cpp index cd7f0fe..fa173f0 100644 --- a/src/uscxml/debug/Debugger.cpp +++ b/src/uscxml/debug/Debugger.cpp @@ -145,7 +145,7 @@ void Debugger::handleExecutable(const std::string& sessionId, std::shared_ptr<DebugSession> session = getSession(sessionId); if (!session) return; - if (!session->_isRunning) + if (!session->_isRunning && !session->_isAttached) return; std::list<Breakpoint> breakpoints; @@ -165,7 +165,7 @@ void Debugger::handleEvent(const std::string& sessionId, const Event& event, Bre std::shared_ptr<DebugSession> session = getSession(sessionId); if (!session) return; - if (!session->_isRunning) + if (!session->_isRunning && !session->_isAttached) return; std::list<Breakpoint> breakpoints; @@ -184,7 +184,7 @@ void Debugger::handleStable(const std::string& sessionId, Breakpoint::When when) std::shared_ptr<DebugSession> session = getSession(sessionId); if (!session) return; - if (!session->_isRunning) + if (!session->_isRunning && !session->_isAttached) return; std::list<Breakpoint> breakpoints; @@ -201,7 +201,7 @@ void Debugger::handleMicrostep(const std::string& sessionId, Breakpoint::When wh std::shared_ptr<DebugSession> session = getSession(sessionId); if (!session) return; - if (!session->_isRunning) + if (!session->_isRunning && !session->_isAttached) return; std::list<Breakpoint> breakpoints; @@ -218,7 +218,7 @@ void Debugger::handleTransition(const std::string& sessionId, const XERCESC_NS:: std::shared_ptr<DebugSession> session = getSession(sessionId); if (!session) return; - if (!session->_isRunning) + if (!session->_isRunning && !session->_isAttached) return; Breakpoint breakpointTemplate; @@ -231,7 +231,7 @@ void Debugger::handleState(const std::string& sessionId, const XERCESC_NS::DOMEl std::shared_ptr<DebugSession> session = getSession(sessionId); if (!session) return; - if (!session->_isRunning) + if (!session->_isRunning && !session->_isAttached) return; Breakpoint breakpointTemplate; @@ -246,7 +246,7 @@ void Debugger::handleInvoke(const std::string& sessionId, const XERCESC_NS::DOME std::shared_ptr<DebugSession> session = getSession(sessionId); if (!session) return; - if (!session->_isRunning) + if (!session->_isRunning && !session->_isAttached) return; Breakpoint breakpointTemplate; diff --git a/src/uscxml/debug/DebuggerServlet.cpp b/src/uscxml/debug/DebuggerServlet.cpp index 8a7e087..7363d23 100644 --- a/src/uscxml/debug/DebuggerServlet.cpp +++ b/src/uscxml/debug/DebuggerServlet.cpp @@ -134,6 +134,7 @@ bool DebuggerServlet::requestFromHTTP(const HTTPServer::Request& request) { serverPushData(session); } else if (boost::starts_with(request.data.at("path").atom, "/debug/disconnect")) { + session->debugDetach(request.data["content"]); processDisconnect(request); } else if (boost::starts_with(request.data.at("path").atom, "/debug/issues")) { @@ -196,7 +197,6 @@ void DebuggerServlet::processConnect(const HTTPServer::Request& request) { void DebuggerServlet::processDisconnect(const HTTPServer::Request& request) { std::lock_guard<std::recursive_mutex> lock(_mutex); - Data replyData; if (!request.data.at("content").hasKey("session")) { diff --git a/src/uscxml/debug/DebuggerServlet.h b/src/uscxml/debug/DebuggerServlet.h index 674d842..2ba7eb9 100644 --- a/src/uscxml/debug/DebuggerServlet.h +++ b/src/uscxml/debug/DebuggerServlet.h @@ -52,21 +52,6 @@ public: void processIssues(const HTTPServer::Request& request); -// void processDebugPrepare(const HTTPServer::Request& request); -// void processDebugAttach(const HTTPServer::Request& request); -// void processDebugStart(const HTTPServer::Request& request); -// void processDebugStop(const HTTPServer::Request& request); - -// void processDebugEval(const HTTPServer::Request& request); -// void processDebugStart(const HTTPServer::Request& request); -// void processDebugStop(const HTTPServer::Request& request); -// void processDebugStep(const HTTPServer::Request& request); -// void processDebugResume(const HTTPServer::Request& request); -// void processDebugPause(const HTTPServer::Request& request); -// void processAddBreakPoint(const HTTPServer::Request& request); -// void processRemoveBreakPoint(const HTTPServer::Request& request); -// void processPoll(const HTTPServer::Request& request); - protected: void serverPushData(std::shared_ptr<DebugSession>); |