Search in sources :

Example 1 with MessageDTO

use of org.ballerinalang.util.debugger.dto.MessageDTO in project ballerina by ballerina-lang.

the class VMDebuggerUtil method startDebug.

public static void startDebug(String srcPath, BreakPointDTO[] bPoints, ExpectedResults expRes) {
    TestDebugger debugger = setupProgram(srcPath, bPoints);
    if (!debugger.tryAcquireLock(1000)) {
        Assert.fail("VM doesn't start within 1000ms");
    }
    debugger.startDebug();
    int hitCount = 0;
    while (true) {
        debugger.getClientHandler().aquireSem();
        if (debugger.getClientHandler().isExit()) {
            break;
        }
        MessageDTO debugHit = debugger.getClientHandler().getDebugHit();
        DebugPoint debugPoint = expRes.getDebugHit(debugHit.getLocation());
        Assert.assertNotNull(debugPoint, "Invalid debug point hit - " + debugHit.getLocation());
        int hits = debugPoint.decrementAndGetHits();
        Assert.assertTrue(hits >= 0, "Invalid number of hits for same point - " + debugPoint.getExpBreakPoint() + " remaining hit count - " + hits);
        hitCount++;
        executeDebuggerCmd(debugger, debugHit.getThreadId(), debugPoint.getNextStep());
    }
    Assert.assertEquals(hitCount, expRes.getDebugCount(), "Missing debug point hits - " + expRes);
}
Also used : MessageDTO(org.ballerinalang.util.debugger.dto.MessageDTO)

Example 2 with MessageDTO

use of org.ballerinalang.util.debugger.dto.MessageDTO in project ballerina by ballerina-lang.

the class Debugger method notifyDebugHit.

/**
 * Send a message to the debug client when a breakpoint is hit.
 *
 * @param ctx               Current context.
 * @param currentExecLine   Current execution line.
 * @param workerId          Current thread id.
 */
public void notifyDebugHit(WorkerExecutionContext ctx, LineNumberInfo currentExecLine, String workerId) {
    MessageDTO message = generateDebugHitMessage(ctx, currentExecLine, workerId);
    clientHandler.notifyHalt(message);
}
Also used : MessageDTO(org.ballerinalang.util.debugger.dto.MessageDTO)

Example 3 with MessageDTO

use of org.ballerinalang.util.debugger.dto.MessageDTO in project ballerina by ballerina-lang.

the class Debugger method sendAcknowledge.

/**
 * Send a generic acknowledge message to the client.
 *
 * @param messageText message to send to the client
 */
private void sendAcknowledge(String messageText) {
    MessageDTO message = new MessageDTO(DebugConstants.CODE_ACK, messageText);
    clientHandler.sendCustomMsg(message);
}
Also used : MessageDTO(org.ballerinalang.util.debugger.dto.MessageDTO)

Example 4 with MessageDTO

use of org.ballerinalang.util.debugger.dto.MessageDTO in project ballerina by ballerina-lang.

the class Debugger method generateDebugHitMessage.

/**
 * Generate debug hit message.
 *
 * @param ctx               Current context.
 * @param currentExecLine   Current execution line.
 * @param workerId          Current thread id.
 * @return  message         To be sent.
 */
private MessageDTO generateDebugHitMessage(WorkerExecutionContext ctx, LineNumberInfo currentExecLine, String workerId) {
    MessageDTO message = new MessageDTO(DebugConstants.CODE_HIT, DebugConstants.MSG_HIT);
    message.setThreadId(workerId);
    BreakPointDTO breakPointDTO = new BreakPointDTO(currentExecLine.getPackageInfo().getPkgPath(), currentExecLine.getFileName(), currentExecLine.getLineNumber());
    message.setLocation(breakPointDTO);
    int callingIp = currentExecLine.getIp();
    String pck = ctx.callableUnitInfo.getPackageInfo().getPkgPath();
    String functionName = ctx.callableUnitInfo.getName();
    LineNumberInfo callingLine = getLineNumber(ctx.callableUnitInfo.getPackageInfo().getPkgPath(), callingIp);
    FrameDTO frameDTO = new FrameDTO(pck, functionName, callingLine.getFileName(), callingLine.getLineNumber());
    message.addFrame(frameDTO);
    LocalVariableAttributeInfo localVarAttrInfo = (LocalVariableAttributeInfo) ctx.workerInfo.getAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE);
    localVarAttrInfo.getLocalVariables().forEach(l -> {
        VariableDTO variableDTO = new VariableDTO(l.getVariableName(), "Local");
        switch(l.getVariableType().getTag()) {
            case TypeTags.INT_TAG:
                variableDTO.setBValue(new BInteger(ctx.workerLocal.longRegs[l.getVariableIndex()]));
                break;
            case TypeTags.FLOAT_TAG:
                variableDTO.setBValue(new BFloat(ctx.workerLocal.doubleRegs[l.getVariableIndex()]));
                break;
            case TypeTags.STRING_TAG:
                variableDTO.setBValue(new BString(ctx.workerLocal.stringRegs[l.getVariableIndex()]));
                break;
            case TypeTags.BOOLEAN_TAG:
                variableDTO.setBValue(new BBoolean(ctx.workerLocal.intRegs[l.getVariableIndex()] == 1));
                break;
            case TypeTags.BLOB_TAG:
                variableDTO.setBValue(new BBlob(ctx.workerLocal.byteRegs[l.getVariableIndex()]));
                break;
            default:
                variableDTO.setBValue(ctx.workerLocal.refRegs[l.getVariableIndex()]);
                break;
        }
        frameDTO.addVariable(variableDTO);
    });
    return message;
}
Also used : BreakPointDTO(org.ballerinalang.util.debugger.dto.BreakPointDTO) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BBoolean(org.ballerinalang.model.values.BBoolean) BString(org.ballerinalang.model.values.BString) MessageDTO(org.ballerinalang.util.debugger.dto.MessageDTO) LocalVariableAttributeInfo(org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo) VariableDTO(org.ballerinalang.util.debugger.dto.VariableDTO) BFloat(org.ballerinalang.model.values.BFloat) LineNumberInfo(org.ballerinalang.util.codegen.LineNumberInfo) BBlob(org.ballerinalang.model.values.BBlob) FrameDTO(org.ballerinalang.util.debugger.dto.FrameDTO)

Example 5 with MessageDTO

use of org.ballerinalang.util.debugger.dto.MessageDTO in project ballerina by ballerina-lang.

the class VMDebugClientHandler method notifyExit.

@Override
public void notifyExit() {
    MessageDTO message = new MessageDTO(DebugConstants.CODE_EXIT, DebugConstants.MSG_EXIT);
    pushMessageToClient(message);
}
Also used : MessageDTO(org.ballerinalang.util.debugger.dto.MessageDTO)

Aggregations

MessageDTO (org.ballerinalang.util.debugger.dto.MessageDTO)5 BBlob (org.ballerinalang.model.values.BBlob)1 BBoolean (org.ballerinalang.model.values.BBoolean)1 BFloat (org.ballerinalang.model.values.BFloat)1 BInteger (org.ballerinalang.model.values.BInteger)1 BString (org.ballerinalang.model.values.BString)1 LineNumberInfo (org.ballerinalang.util.codegen.LineNumberInfo)1 LocalVariableAttributeInfo (org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo)1 BreakPointDTO (org.ballerinalang.util.debugger.dto.BreakPointDTO)1 FrameDTO (org.ballerinalang.util.debugger.dto.FrameDTO)1 VariableDTO (org.ballerinalang.util.debugger.dto.VariableDTO)1