Search in sources :

Example 16 with LineNumberNode

use of org.objectweb.asm.tree.LineNumberNode in project bytecode-viewer by Konloch.

the class InstructionSearcher method search.

public boolean search() {
    for (AbstractInsnNode ain : insns.toArray()) {
        if (ain instanceof LineNumberNode || ain instanceof FrameNode)
            continue;
        if (pattern.accept(ain)) {
            matches.add(pattern.getLastMatch());
            pattern.resetMatch();
        }
    }
    return size() != 0;
}
Also used : FrameNode(org.objectweb.asm.tree.FrameNode) LineNumberNode(org.objectweb.asm.tree.LineNumberNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 17 with LineNumberNode

use of org.objectweb.asm.tree.LineNumberNode in project atlas by alibaba.

the class TBIncrementalSupportVisitor method visitMethod.

/**
 * Insert Constructor specific logic({@link ConstructorRedirection} and
 * {@link ConstructorBuilder}) for constructor redirecting or
 * normal method redirecting ({@link MethodRedirection}) for other methods.
 */
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    access = transformAccessForInstantRun(access);
    MethodVisitor defaultVisitor = super.visitMethod(access, name, desc, signature, exceptions);
    MethodNode method = checkNotNull(getMethodByNameInClass(name, desc, classNode), "Method found by visitor but not in the pre-parsed class node.");
    if (!supportAddCallSuper) {
        method.instructions.accept(new MethodVisitor(api) {

            @Override
            public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
                if (opcode == Opcodes.INVOKESPECIAL && !owner.equals(visitedClassName)) {
                    visitSuperMethods.add(name + "." + desc);
                }
                super.visitMethodInsn(opcode, owner, name, desc, itf);
            }
        });
    }
    if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
        return defaultVisitor;
    }
    boolean hasIncompatibleChange = InstantRunMethodVerifier.verifyMethod(method) != InstantRunVerifierStatus.COMPATIBLE;
    if (hasIncompatibleChange || disableRedirectionForClass || !isAccessCompatibleWithInstantRun(access) || name.equals(ByteCodeUtils.CLASS_INITIALIZER)) {
        return defaultVisitor;
    } else {
        ArrayList<Type> args = new ArrayList<>(Arrays.asList(Type.getArgumentTypes(desc)));
        boolean isStatic = (access & Opcodes.ACC_STATIC) != 0;
        if (!isStatic) {
            args.add(0, Type.getType(Object.class));
        }
        // Install the Jsr/Ret inliner adapter, we have had reports of code still using the
        // Jsr/Ret deprecated byte codes.
        // see https://code.google.com/p/android/issues/detail?id=220019
        JSRInlinerAdapter jsrInlinerAdapter = new JSRInlinerAdapter(defaultVisitor, access, name, desc, signature, exceptions);
        ISMethodVisitor mv = new ISMethodVisitor(jsrInlinerAdapter, access, name, desc);
        if (name.equals(ByteCodeUtils.CONSTRUCTOR)) {
            if (patchInitMethod) {
                Constructor constructor = ConstructorBuilder.build(visitedClassName, method);
                LabelNode start = new LabelNode();
                method.instructions.insert(constructor.loadThis, start);
                if (constructor.lineForLoad != -1) {
                    // Record the line number from the start of LOAD_0 for uninitialized 'this'.
                    // This allows a breakpoint to be set at the line with this(...) or super(...)
                    // call in the constructor.
                    method.instructions.insert(constructor.loadThis, new LineNumberNode(constructor.lineForLoad, start));
                }
                mv.addRedirection(new TBConstructorRedirection(start, constructor, args));
            } else {
                return defaultVisitor;
            }
        } else {
            mv.addRedirection(new TBMethodRedirection(new LabelNode(mv.getStartLabel()), name + "." + desc, args, Type.getReturnType(desc)));
        }
        method.accept(mv);
        return null;
    }
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) LineNumberNode(org.objectweb.asm.tree.LineNumberNode) JSRInlinerAdapter(org.objectweb.asm.commons.JSRInlinerAdapter) MethodNode(org.objectweb.asm.tree.MethodNode)

Aggregations

LineNumberNode (org.objectweb.asm.tree.LineNumberNode)17 LabelNode (org.objectweb.asm.tree.LabelNode)10 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)8 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)6 FrameNode (org.objectweb.asm.tree.FrameNode)5 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)3 LocalVariable (org.develnext.jphp.core.compiler.jvm.misc.LocalVariable)2 InsnList (org.objectweb.asm.tree.InsnList)2 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)2 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)2 MethodNode (org.objectweb.asm.tree.MethodNode)2 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)2 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 VariableExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.VariableExprToken)1 CaseStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.CaseStmtToken)1 ExprStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken)1 ControlDependenceGraph (org.evosuite.graphs.cdg.ControlDependenceGraph)1