Skip to content

Commit

Permalink
Calls coverage before terminating the interpreter
Browse files Browse the repository at this point in the history
Sorts a race condition where the interpreter would receive a stop
command and shut before the coverage was completely processed by the
debug plugin.

It could be squashed with 134c0be as it
is part of the fix.
  • Loading branch information
idhugoid committed Aug 18, 2020
1 parent 926d92c commit 926d272
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ public interface IVdmThread extends IThread /* , IFilteredStep */
void updateStackFrames();

IDbgpStatusInterpreterThreadState getInterpreterState();

Boolean handleCoverage();
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ public void setVdmThreadConfigurator(

void stepReturn() throws DebugException;

void handleCustomTerminationCommands();
Boolean handleCustomTerminationCommands();
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,21 @@ public void run()
if (target.getSessions().length > 0)
{
IDbgpSession session = target.getSessions()[0];

// Print coverage before send the quit command to the interpreter
if( line.equals("q") || line.equals("quit") ) {
target.handleCustomTerminationCommands(session);
}

final IDbgpProperty property = session.getExtendedCommands().execute(line);
if(property != null) {
final String result = property.getValue();
proxy.writeStdout(result);

// No need to print prompt
if( line.equals("q") || line.equals("quit") )
return;

proxy.printPrompt();
}else {
VdmDebugPlugin.logWarning("Interpreter response did not contain a value!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ public void printLog(LogItem item)
}
}

public void handleCustomTerminationCommands(IDbgpSession dbgpSession)
public Boolean handleCustomTerminationCommands(IDbgpSession dbgpSession)
{

try
Expand Down Expand Up @@ -873,7 +873,10 @@ public void handleCustomTerminationCommands(IDbgpSession dbgpSession)
{
e.printStackTrace();
}
return false;
}

return true;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ public void handleTermination(DbgpException e)
}
}

manager.handleCustomTerminationCommands();

session.requestTermination();
try
{
Expand Down Expand Up @@ -615,4 +613,11 @@ public void setErrorState()
errorState = true;

}

@Override
public Boolean handleCoverage() {

return manager.handleCustomTerminationCommands();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,6 @@ public void sendTerminationRequest() throws DebugException
if (threads.length > 0)
{
waitingForThreads = false;
handleCustomPreTerminationCommands();
}
for (int i = 0; i < threads.length; ++i)
{
Expand Down Expand Up @@ -637,28 +636,17 @@ public void configureThread(DbgpDebugger engine, VdmThread scriptThread)
}
}

public void handleCustomTerminationCommands()
public Boolean handleCustomTerminationCommands()
{
synchronized (threads)
{
if (threads.size() == 1)
{
target.handleCustomTerminationCommands(threads.get(0).getDbgpSession());
}
return target.handleCustomTerminationCommands(threads.get(0).getDbgpSession());
}else return false;
}

}

public void handleCustomPreTerminationCommands()
{
synchronized (threads)
{
if (!threads.isEmpty())
{
target.handleCustomTerminationCommands(threads.get(0).getDbgpSession());
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ public boolean canResume()

public void endResume(DbgpException e, IDbgpStatus status)
{
// Call coverage before setting the interpreter state to stopped
if (status.isStopped() && status.reasonOk()) {
final VdmThread t = (VdmThread) this.handler;
final Boolean success = t.handleCoverage();
if(success == false)
VdmDebugPlugin.logError("Coverage writing did not succeeed!");
}

handleStatus(e, status, DebugEvent.BREAKPOINT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,29 @@
*/
package org.overture.ide.debug.core.model.internal.operations;

import org.overture.ide.debug.core.VdmDebugPlugin;
import org.overture.ide.debug.core.dbgp.exceptions.DbgpException;
import org.overture.ide.debug.core.model.IVdmThread;
import org.overture.ide.debug.core.model.internal.VdmThread;

public class DbgpTerminateOperation extends DbgpOperation
{
private static final String JOB_NAME = "Terminate Operation";
private IVdmThread thread;

public DbgpTerminateOperation(IVdmThread thread, IResultHandler finish)
{
super(thread, JOB_NAME, finish);
this.thread = thread;
}

protected void process() throws DbgpException
{
// Call coverage before send the quit command to the interpreter
final Boolean success = thread.handleCoverage();
if(success == false)
VdmDebugPlugin.logError("Coverage writing did not succeeed!");

callFinish(getCore().stop());
}
}

0 comments on commit 926d272

Please sign in to comment.