Anamorphosee / stacktrace-decoroutinator

Small lib for recovering stack trace in exceptions thrown in Kotlin coroutines
Apache License 2.0
158 stars 4 forks source link

Jacoco interference #18

Closed p4654545 closed 1 year ago

p4654545 commented 1 year ago

When using Jacoco, methods are instrumented to call $jacocoInit first. As a consequence the first instructions of suspend methods are not ALOAD (25) and INSTANCEOF (193) anymore. The method MethodNode.getDebugMetadataInfo() in classTransformer.kt assumes this.

The following code searches for two consecutive ALOAD/INSTANCEOF instructions with the same conditions as previously. It replaces the second part of the body starting with "val firstInstructions: ".

return instructions.asSequence().filter {
        val next = it.next
        it is VarInsnNode && it.opcode == Opcodes.ALOAD && it.`var` == continuationIndex
                && next != null && next is TypeInsnNode && next.opcode == Opcodes.INSTANCEOF
    }
        .firstOrNull()?.let {
            val continuationClassName = (it.next as TypeInsnNode).desc.replace('/', '.')
            decoroutinatorJvmAgentRegistry.metadataInfoResolver.getDebugMetadataInfo(continuationClassName)
        }
Anamorphosee commented 1 year ago

@p4654545 May be you could make a PR?

p4654545 commented 1 year ago

19

Anamorphosee commented 1 year ago

Thanks. Fix was released in 2.3.5