Search in sources :

Example 1 with Debugger

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

the class TesterinaFunction method invoke.

/**
 * Invokes a ballerina test function, in blocking mode.
 *
 * @param args function arguments
 */
public BValue[] invoke(BValue[] args) {
    WorkerExecutionContext ctx = new WorkerExecutionContext(programFile);
    Debugger debugger = new Debugger(programFile);
    initDebugger(programFile, debugger);
    return BLangFunctions.invokeCallable(bFunction, ctx, args);
}
Also used : WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext) Debugger(org.ballerinalang.util.debugger.Debugger)

Example 2 with Debugger

use of org.ballerinalang.util.debugger.Debugger 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 3 with Debugger

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

the class BLangProgramRunner method runMain.

public static void runMain(ProgramFile programFile, String[] args) {
    if (!programFile.isMainEPAvailable()) {
        throw new BallerinaException("main function not found in  '" + programFile.getProgramFilePath() + "'");
    }
    PackageInfo mainPkgInfo = programFile.getEntryPackage();
    if (mainPkgInfo == null) {
        throw new BallerinaException("main function not found in  '" + programFile.getProgramFilePath() + "'");
    }
    Debugger debugger = new Debugger(programFile);
    initDebugger(programFile, debugger);
    boolean distributedTxEnabled = CompilerUtils.isDistributedTransactionsEnabled();
    programFile.setDistributedTransactionEnabled(distributedTxEnabled);
    FunctionInfo mainFuncInfo = getMainFunction(mainPkgInfo);
    try {
        BLangFunctions.invokeEntrypointCallable(programFile, mainPkgInfo, mainFuncInfo, extractMainArgs(args));
    } finally {
        if (debugger.isDebugEnabled()) {
            debugger.notifyExit();
        }
        BLangFunctions.invokeVMUtilFunction(mainPkgInfo.getStopFunctionInfo());
    }
}
Also used : Debugger(org.ballerinalang.util.debugger.Debugger) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) FunctionInfo(org.ballerinalang.util.codegen.FunctionInfo) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException)

Example 4 with Debugger

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

the class BLangProgramRunner method runService.

public static void runService(ProgramFile programFile) {
    if (!programFile.isServiceEPAvailable()) {
        throw new BallerinaException("no services found in '" + programFile.getProgramFilePath() + "'");
    }
    // Get the service package
    PackageInfo servicesPackage = programFile.getEntryPackage();
    if (servicesPackage == null) {
        throw new BallerinaException("no services found in '" + programFile.getProgramFilePath() + "'");
    }
    Debugger debugger = new Debugger(programFile);
    initDebugger(programFile, debugger);
    boolean distributedTxEnabled = CompilerUtils.isDistributedTransactionsEnabled();
    programFile.setDistributedTransactionEnabled(distributedTxEnabled);
    // Invoke package init function
    BLangFunctions.invokePackageInitFunction(servicesPackage.getInitFunctionInfo());
    BLangFunctions.invokeVMUtilFunction(servicesPackage.getStartFunctionInfo());
}
Also used : Debugger(org.ballerinalang.util.debugger.Debugger) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException)

Example 5 with Debugger

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

the class BRunUtil method invokePackageInit.

/**
 * Invoke package init function.
 *
 * @param compileResult CompileResult instance
 * @param packageName   Name of the package to invoke
 */
protected static void invokePackageInit(CompileResult compileResult, String packageName) {
    if (compileResult.getErrorCount() > 0) {
        throw new IllegalStateException(compileResult.toString());
    }
    ProgramFile programFile = compileResult.getProgFile();
    PackageInfo packageInfo = programFile.getPackageInfo(packageName);
    WorkerExecutionContext context = new WorkerExecutionContext(programFile);
    Debugger debugger = new Debugger(programFile);
    programFile.setDebugger(debugger);
    compileResult.setContext(context);
    BLangFunctions.invokePackageInitFunction(packageInfo.getInitFunctionInfo(), context);
}
Also used : WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext) Debugger(org.ballerinalang.util.debugger.Debugger) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) ProgramFile(org.ballerinalang.util.codegen.ProgramFile)

Aggregations

Debugger (org.ballerinalang.util.debugger.Debugger)12 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)7 PackageInfo (org.ballerinalang.util.codegen.PackageInfo)5 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)4 BValue (org.ballerinalang.model.values.BValue)3 WorkerExecutionContext (org.ballerinalang.bre.bvm.WorkerExecutionContext)2 FunctionInfo (org.ballerinalang.util.codegen.FunctionInfo)2 Diagnostic (org.ballerinalang.util.diagnostic.Diagnostic)2 CompilerPlugin (org.ballerinalang.compiler.plugins.CompilerPlugin)1 CompileResult (org.ballerinalang.launcher.util.CompileResult)1 BBoolean (org.ballerinalang.model.values.BBoolean)1 LineNumberInfo (org.ballerinalang.util.codegen.LineNumberInfo)1 DebugContext (org.ballerinalang.util.debugger.DebugContext)1