--
You received this message because you are subscribed to the Google Groups "Byte Buddy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to byte-buddy+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/byte-buddy/CAAvUidNX16_CB99gmCaogDoKbRJeKJJC3EFZwC9c%2Bm_Y7TuTMg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/byte-buddy/CA%2BDM0AmtX0XwppWJuS0sqTP4cNk67DwjCKFRo38q_uc70zgnhw%40mail.gmail.com.
| ❱ bin/logback-bytebuddy |
| [Byte Buddy] DISCOVERY java.lang.System [null, null, loaded=true] |
| [Byte Buddy] TRANSFORM java.lang.System [null, null, loaded=true] |
| [Byte Buddy] COMPLETE java.lang.System [null, null, loaded=true] |
| 89 TRACE java.lang.System - entering: java.lang.System.setSecurityManager(java.lang.SecurityManager) with arguments=[java.lang.SecurityManager@58c1670b] |
| 91 TRACE java.lang.System - exiting: java.lang.System.setSecurityManager(java.lang.SecurityManager) with arguments=[java.lang.SecurityManager@58c1670b] => returnType=void |
| Security manager is set! |
| 91 TRACE java.lang.System - entering: java.lang.System.setSecurityManager(java.lang.SecurityManager) with arguments=[null] |
| 91 TRACE java.lang.System - exiting: java.lang.System.setSecurityManager(java.lang.SecurityManager) with arguments=[null] => returnType=void |
public static LineNumberNode findLineNumberForInstruction(InsnList insnList, AbstractInsnNode insnNode) {
Validate.notNull(insnList);
Validate.notNull(insnNode);
int idx = insnList.indexOf(insnNode);
Validate.isTrue(idx != -1);
// Get index of labels and insnNode within method
ListIterator<AbstractInsnNode> insnIt = insnList.iterator(idx);
while (insnIt.hasPrevious()) {
AbstractInsnNode node = insnIt.previous();
if (node instanceof LineNumberNode) {
return (LineNumberNode) node;
}
}
return null;
}
To view this discussion on the web visit https://groups.google.com/d/msgid/byte-buddy/CA%2BDM0AnO%2BHZM-bNGCnPW4ZjMtYGswD2t_unqF0SrvxhJQhEBgw%40mail.gmail.com.
public AgentBuilder builderFromConfig(ElementMatcher<? super TypeDescription> typesMatcher,
ElementMatcher<? super MethodDescription> methodsMatcher) {
return new AgentBuilder.Default()
.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
.with(AgentBuilder.InitializationStrategy.NoOp.INSTANCE)
.with(AgentBuilder.TypeStrategy.Default.REDEFINE)
.disableClassFormatChanges() // frozen instrumented types
.type(typesMatcher) // for these classes...
.transform((builder, type, classLoader, module) -> {
// ...apply this advice to these methods.
Advice to = Advice.to(INSTRUMENTATION_ADVICE_CLASS);
AsmVisitorWrapper on = to.on(methodsMatcher);
AsmVisitorWrapper lineWrapper = wrapper(METHOD_INFO_LOOKUP);
return builder.visit(lineWrapper).visit(on);
});
}
private AsmVisitorWrapper wrapper(Consumer<MethodInfo> consumer) {
return new AsmVisitorWrapper.AbstractBase() {
@Override
public ClassVisitor wrap(TypeDescription instrumentedType,
ClassVisitor classVisitor,
Implementation.Context implementationContext,
TypePool typePool,
FieldList<FieldDescription.InDefinedShape> fields,
MethodList<?> methods, int writerFlags, int readerFlags) {
return new ClassVisitor(Opcodes.ASM5, classVisitor) {
private String name;
private String source;
private String debug;
@Override
public void visitSource(String source, String debug) {
this.source = source;
this.debug = debug;
super.visitSource(source, debug);
}
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
this.name = name != null ? name.replace('/', '.') : null;
super.visit(version, access, name, signature, superName, interfaces);
}
@Override
public MethodVisitor visitMethod(int access,
String n,
String d,
String s,
String[] e) {
MethodVisitor methodVisitor = super.visitMethod(access, n, d, s, e);
return new MethodVisitor(Opcodes.ASM5, methodVisitor) {
@Override
public void visitLineNumber(int line, Label start) {
consumer.accept(new MethodInfo(access, n, d, s, e, name, source, debug, line));
super.visitLineNumber(line, start);
}
};
}
};
}
};
}
To view this discussion on the web visit https://groups.google.com/d/msgid/byte-buddy/CA%2BDM0A%3DJy9PuEMWo_0%3DmJtuX7%2BJKz8qem4ASq5Ah6AopoG%2Bdpg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/byte-buddy/CAAvUidN%3DR%2Bow3xZPJbNEtVsYA49MWEig2_BpriYPcZy4JU3_PQ%40mail.gmail.com.
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
protected @interface LineNumber {
}
static class LineNumberMethodVisitor extends MethodVisitor {
public LineNumberMethodVisitor(MethodVisitor methodVisitor) {
super(Opcodes.ASM5, methodVisitor);
}
@Override
public void visitLineNumber(int line, Label start) {
System.out.println("visitLineNumber " + line);
super.visitLineNumber(line, start);
}
public void gotcha() {
System.out.println("gotcha");
// return accumulated state from here
}
}
public static class LineNumberFactory implements Advice.OffsetMapping.Factory<LineNumber> {
@Override
public Class<LineNumber> getAnnotationType() {
return LineNumber.class;
}
@Override
public Advice.OffsetMapping make(ParameterDescription.InDefinedShape target,
AnnotationDescription.Loadable<LineNumber> annotation,
AdviceType adviceType) {
// http://bytebuddy.net/javadoc/1.10.1/net/bytebuddy/asm/Advice.OffsetMapping.html
return new Advice.OffsetMapping() {
@Override
public Target resolve(TypeDescription instrumentedType,
MethodDescription instrumentedMethod,
Assigner assigner,
Advice.ArgumentHandler argumentHandler,
Sort sort) {
System.out.println("resolve: instrumentedMethod " + instrumentedMethod);
// ??? Return a custom stack manipulation here?
return Target.ForStackManipulation.of(instrumentedMethod.asDefined());
};
};
}
}
but then after that it's not clear where the StackManipulation goes from there.
I assume I'm supposed to extend a StackManipulation so I can get access through the method visitor, but the following doesn't work:
return new Advice.OffsetMapping.Target.AbstractReadOnlyAdapter() {
public StackManipulation resolveRead() {
return new StackManipulation() {
@Override
public boolean isValid() {
return true;
}
@Override
public Size apply(MethodVisitor methodVisitor,
Implementation.Context implementationContext) {
System.out.println("apply: methodVisitor");
if (methodVisitor instanceof LineNumberMethodVisitor) {
LineNumberMethodVisitor lnmv = (LineNumberMethodVisitor) methodVisitor;
lnmv.gotcha();
}
return StackSize.ZERO.toIncreasingSize();
}
};
}
To view this discussion on the web visit https://groups.google.com/d/msgid/byte-buddy/CAAvUidN_FL6MX%2BH5NnJHMhrVH%2BnfsEaJkssFqXWgk-D_5np-dQ%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Byte Buddy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to byte-buddy+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/byte-buddy/da2ad48a-9e75-4745-bd7f-2b99e9745087%40googlegroups.com.