Skip to content

Commit

Permalink
Merge pull request tklab-tud#166 from tklab-tud/sradomski
Browse files Browse the repository at this point in the history
Debugger bugfixes and improvements
  • Loading branch information
sradomski authored Aug 9, 2017
2 parents 97e72c5 + 008cca1 commit ee0a17c
Show file tree
Hide file tree
Showing 7 changed files with 6,066 additions and 177 deletions.
100 changes: 68 additions & 32 deletions src/uscxml/debug/DebugSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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);
Expand All @@ -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());
Expand All @@ -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);

Expand All @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

}
2 changes: 1 addition & 1 deletion src/uscxml/debug/DebugSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/uscxml/debug/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/uscxml/debug/DebuggerServlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down Expand Up @@ -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")) {
Expand Down
15 changes: 0 additions & 15 deletions src/uscxml/debug/DebuggerServlet.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,6 @@ class USCXML_API DebuggerServlet : public Debugger, public HTTPServlet {

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>);
Expand Down
Loading

0 comments on commit ee0a17c

Please sign in to comment.