groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Milles (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (GROOVY-7647) Incorrect line information for debug
Date Mon, 05 Nov 2018 17:15:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-7647?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16675422#comment-16675422
] 

Eric Milles edited comment on GROOVY-7647 at 11/5/18 5:14 PM:
--------------------------------------------------------------

It seems the only critical bit is to add a {{visitLineNumber}} for the path that skips over
the else block.  -Only trick is to determine the last line number of the enclosing block.
 Does anyone know how to do that from within {{StatementWriter}}?-

{code:java}
    public void writeIfElse(IfStatement ifElse) {
        controller.getAcg().onLineNumber(ifElse,"visitIfElse");
        writeStatementLabel(ifElse);

        MethodVisitor mv = controller.getMethodVisitor();

        ifElse.getBooleanExpression().visit(controller.getAcg());
        Label l0 = controller.getOperandStack().jump(IFEQ);

        // if-else is here handled as a special version
        // of a boolean expression
        controller.getCompileStack().pushBooleanExpression();
        ifElse.getIfBlock().visit(controller.getAcg());
        controller.getCompileStack().pop();

        if (ifElse.getElseBlock()==EmptyStatement.INSTANCE) {
            mv.visitLabel(l0);
        } else {
            Label l1 = new Label();
            mv.visitJumpInsn(GOTO, l1);
            mv.visitLabel(l0);
            // GRECLIPSE add
            if (ifElse.getElseBlock().getLineNumber() < 1) {
                MethodNode mn = controller.getConstructorNode();
                if (mn == null) mn = controller.getMethodNode();
                mv.visitLineNumber(mn.getLastLineNumber(), l0);
            }
            // GRECLIPSE end

            controller.getCompileStack().pushBooleanExpression();
            ifElse.getElseBlock().visit(controller.getAcg());
            controller.getCompileStack().pop();

            mv.visitLabel(l1);
        }
    }
{code}


was (Author: emilles):
It seems the only critical bit is to add a {{visitLineNumber}} for the path that skips over
the else block.  -Only trick is to determine the last line number of the enclosing block.
 Does anyone know how to do that from within {{StatementWriter}}?-

{code:java}
    public void writeIfElse(IfStatement ifElse) {
        controller.getAcg().onLineNumber(ifElse,"visitIfElse");
        writeStatementLabel(ifElse);

        MethodVisitor mv = controller.getMethodVisitor();

        ifElse.getBooleanExpression().visit(controller.getAcg());
        Label l0 = controller.getOperandStack().jump(IFEQ);

        // if-else is here handled as a special version
        // of a boolean expression
        controller.getCompileStack().pushBooleanExpression();
        ifElse.getIfBlock().visit(controller.getAcg());
        controller.getCompileStack().pop();

        if (ifElse.getElseBlock()==EmptyStatement.INSTANCE) {
            mv.visitLabel(l0);
        } else {
            Label l1 = new Label();
            mv.visitJumpInsn(GOTO, l1);
            mv.visitLabel(l0);
            // GRECLIPSE add
            if (ifElse.getElseBlock().getLineNumber() < 1) {
                if (controller.getMethodNode() != null) {
                    mv.visitLineNumber(controller.getMethodNode().getLastLineNumber(), l0);
                } else if (controller.getConstructorNode() != null) {
                    mv.visitLineNumber(controller.getConstructorNode().getLastLineNumber(),
l0);
                }
            }
            // GRECLIPSE end

            controller.getCompileStack().pushBooleanExpression();
            ifElse.getElseBlock().visit(controller.getAcg());
            controller.getCompileStack().pop();

            mv.visitLabel(l1);
        }
    }
{code}

> Incorrect line information for debug
> ------------------------------------
>
>                 Key: GROOVY-7647
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7647
>             Project: Groovy
>          Issue Type: Bug
>          Components: class generator, Compiler
>    Affects Versions: 2.4.5
>            Reporter: Egor Ushakov
>            Priority: Major
>
> Try to debug the code:
> {code}
> boolean boolVar = false; //line 15
> if (boolVar) { // set breakpoint here and step over //line 16
>     print "ok"; //line 17
> } // end of file //line 18
> {code}
> It steps over to the line with print even though it is not executed.
> Seems that compiler does not generate line info for the last block (line 18):
> {code}
>  public java.lang.Object run();
>     descriptor: ()Ljava/lang/Object;
>     flags: ACC_PUBLIC
>     Code:
>       stack=3, locals=3, args_size=1
>          0: invokestatic  #18                 // Method $getCallSiteArray:()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
>          3: astore_1
>          4: iconst_0
>          5: istore_2
>          6: iload_2
>          7: pop
>          8: iload_2
>          9: ifeq          28
>         12: aload_1
>         13: ldc           #41                 // int 1
>         15: aaload
>         16: aload_0
>         17: ldc           #43                 // String ok
>         19: invokeinterface #47,  3           // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.callCurrent:(Lgroovy/lang/GroovyObject;Ljava/lang/Object;)Ljava/lang/Object;
>         24: areturn
>         25: goto          30
>         28: aconst_null
>         29: areturn
>         30: aconst_null
>         31: areturn
>       LocalVariableTable:
>         Start  Length  Slot  Name   Signature
>             0      30     0  this   Lsdfklajsdlkjas/test;
>             6      24     2 boolVar   Z
>       LineNumberTable:
>         line 15: 4
>         line 16: 8
>         line 17: 12
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message