Search in sources :

Example 1 with LineNumberInfo

use of org.ballerinalang.util.codegen.LineNumberInfo in project ballerina by ballerina-lang.

the class CPU method debug.

/**
 * Method to calculate and detect debug points when the instruction point is given.
 */
private static boolean debug(WorkerExecutionContext ctx) {
    Debugger debugger = ctx.programFile.getDebugger();
    if (!debugger.isClientSessionActive()) {
        return false;
    }
    DebugContext debugContext = ctx.getDebugContext();
    if (debugContext.isWorkerPaused()) {
        debugContext.setWorkerPaused(false);
        return false;
    }
    LineNumberInfo currentExecLine = debugger.getLineNumber(ctx.callableUnitInfo.getPackageInfo().getPkgPath(), ctx.ip);
    /*
         Below if check stops hitting the same debug line again and again in case that single line has
         multctx.iple instructions.
         */
    if (currentExecLine.equals(debugContext.getLastLine())) {
        return false;
    }
    if (debugPointCheck(ctx, currentExecLine, debugger)) {
        return true;
    }
    switch(debugContext.getCurrentCommand()) {
        case RESUME:
            /*
                 In case of a for loop, need to clear the last hit line, so that, same line can get hit again.
                 */
            debugContext.clearLastDebugLine();
            break;
        case STEP_IN:
        case STEP_OVER:
            debugHit(ctx, currentExecLine, debugger);
            return true;
        case STEP_OUT:
            break;
        default:
            debugger.notifyExit();
            debugger.stopDebugging();
    }
    return false;
}
Also used : Debugger(org.ballerinalang.util.debugger.Debugger) LineNumberInfo(org.ballerinalang.util.codegen.LineNumberInfo) DebugContext(org.ballerinalang.util.debugger.DebugContext)

Example 2 with LineNumberInfo

use of org.ballerinalang.util.codegen.LineNumberInfo in project ballerina by ballerina-lang.

the class BLangVMErrors method getStackFrame.

public static BStruct getStackFrame(CallableUnitInfo callableUnitInfo, int ip) {
    if (callableUnitInfo == null) {
        return null;
    }
    ProgramFile progFile = callableUnitInfo.getPackageInfo().getProgramFile();
    PackageInfo runtimePackage = progFile.getPackageInfo(PACKAGE_RUNTIME);
    StructInfo callStackElement = runtimePackage.getStructInfo(STRUCT_CALL_STACK_ELEMENT);
    int currentIP = ip - 1;
    Object[] values;
    values = new Object[4];
    String parentScope = "";
    if (callableUnitInfo instanceof ResourceInfo) {
        parentScope = ((ResourceInfo) callableUnitInfo).getServiceInfo().getName() + ".";
    } else if (callableUnitInfo instanceof ActionInfo) {
        parentScope = ((ActionInfo) callableUnitInfo).getConnectorInfo().getName() + ".";
    }
    values[0] = parentScope + callableUnitInfo.getName();
    values[1] = callableUnitInfo.getPkgPath();
    if (callableUnitInfo.isNative()) {
        values[2] = "<native>";
        values[3] = 0;
    } else {
        LineNumberInfo lineNumberInfo = callableUnitInfo.getPackageInfo().getLineNumberInfo(currentIP);
        if (lineNumberInfo != null) {
            values[2] = lineNumberInfo.getFileName();
            values[3] = lineNumberInfo.getLineNumber();
        }
    }
    return BLangVMStructs.createBStruct(callStackElement, values);
}
Also used : ResourceInfo(org.ballerinalang.util.codegen.ResourceInfo) StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) ActionInfo(org.ballerinalang.util.codegen.ActionInfo) LineNumberInfo(org.ballerinalang.util.codegen.LineNumberInfo) ProgramFile(org.ballerinalang.util.codegen.ProgramFile)

Example 3 with LineNumberInfo

use of org.ballerinalang.util.codegen.LineNumberInfo in project ballerina by ballerina-lang.

the class DebugInfoHolder method processPkgInfo.

/**
 * Process and build information required for debugging the package.
 *
 * @param packageInfo   To extract relevant information.
 */
private void processPkgInfo(PackageInfo packageInfo) {
    DebuggerPkgInfo debuggerPkgInfo = new DebuggerPkgInfo(packageInfo.getInstructionCount());
    LineNumberTableAttributeInfo lineNumberTableAttributeInfo = (LineNumberTableAttributeInfo) packageInfo.getAttributeInfo(AttributeInfo.Kind.LINE_NUMBER_TABLE_ATTRIBUTE);
    List<LineNumberInfo> lineNumberInfos = lineNumberTableAttributeInfo.getLineNumberInfoList().stream().sorted(Comparator.comparing(LineNumberInfo::getIp)).collect(Collectors.toList());
    LineNumberInfo currentLineNoInfo = null;
    for (LineNumberInfo lineNoInfo : lineNumberInfos) {
        if (currentLineNoInfo == null) {
            currentLineNoInfo = lineNoInfo;
            continue;
        }
        debuggerPkgInfo.addLineNumberInfo(currentLineNoInfo.getIp(), lineNoInfo.getIp(), currentLineNoInfo);
        currentLineNoInfo = lineNoInfo;
    }
    if (currentLineNoInfo != null) {
        debuggerPkgInfo.addLineNumberInfo(currentLineNoInfo.getIp(), packageInfo.getInstructionCount(), currentLineNoInfo);
    }
    packageInfoMap.put(packageInfo.getPkgPath(), debuggerPkgInfo);
}
Also used : LineNumberTableAttributeInfo(org.ballerinalang.util.codegen.attributes.LineNumberTableAttributeInfo) LineNumberInfo(org.ballerinalang.util.codegen.LineNumberInfo)

Example 4 with LineNumberInfo

use of org.ballerinalang.util.codegen.LineNumberInfo 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)

Aggregations

LineNumberInfo (org.ballerinalang.util.codegen.LineNumberInfo)4 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 ActionInfo (org.ballerinalang.util.codegen.ActionInfo)1 PackageInfo (org.ballerinalang.util.codegen.PackageInfo)1 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)1 ResourceInfo (org.ballerinalang.util.codegen.ResourceInfo)1 StructInfo (org.ballerinalang.util.codegen.StructInfo)1 LineNumberTableAttributeInfo (org.ballerinalang.util.codegen.attributes.LineNumberTableAttributeInfo)1 LocalVariableAttributeInfo (org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo)1 DebugContext (org.ballerinalang.util.debugger.DebugContext)1 Debugger (org.ballerinalang.util.debugger.Debugger)1 BreakPointDTO (org.ballerinalang.util.debugger.dto.BreakPointDTO)1 FrameDTO (org.ballerinalang.util.debugger.dto.FrameDTO)1 MessageDTO (org.ballerinalang.util.debugger.dto.MessageDTO)1 VariableDTO (org.ballerinalang.util.debugger.dto.VariableDTO)1