support MethodInfo binding

pull/1182/head
hengyunabc 5 years ago
parent 9c6cfc9757
commit 360db7dfd3

@ -312,6 +312,21 @@ public abstract class Binding {
}
}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@java.lang.annotation.Target(ElementType.PARAMETER)
@BindingParserHandler(parser = MethodInfoBindingParser.class)
public static @interface MethodInfo {
boolean optional() default false;
}
public static class MethodInfoBindingParser implements BindingParser {
@Override
public Binding parse(Annotation annotation) {
return new MethodDeclarationBinding();
}
}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@java.lang.annotation.Target(ElementType.PARAMETER)

@ -0,0 +1,30 @@
package com.taobao.arthas.bytekit.asm.binding;
import com.alibaba.arthas.deps.org.objectweb.asm.Type;
import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList;
import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode;
import com.taobao.arthas.bytekit.asm.MethodProcessor;
import com.taobao.arthas.bytekit.utils.AsmOpUtils;
/**
* method name | method desc
*
* TODO line number ?
*
* @author hengyunabc 2020-05-16
*
*/
public class MethodInfoBinding extends Binding {
@Override
public void pushOntoStack(InsnList instructions, BindingContext bindingContext) {
MethodProcessor methodProcessor = bindingContext.getMethodProcessor();
MethodNode methodNode = methodProcessor.getMethodNode();
AsmOpUtils.ldc(instructions, methodNode.name + methodNode.desc);
}
@Override
public Type getType(BindingContext bindingContext) {
return Type.getType(String.class);
}
}

@ -92,23 +92,21 @@ public class Enhancer implements ClassFileTransformer {
@AtEnter(inline = true)
public static void atEnter(@Binding.This Object target, @Binding.Class Class<?> clazz,
@Binding.MethodName String methodName, @Binding.MethodDesc String methodDesc,
@Binding.Args Object[] args) {
SpyAPI.atEnter(clazz, methodName, methodDesc, target, args);
@Binding.MethodInfo String methodInfo, @Binding.Args Object[] args) {
SpyAPI.atEnter(clazz, methodInfo, target, args);
}
@AtExit(inline = true)
public static void atExit(@Binding.This Object target, @Binding.Class Class<?> clazz,
@Binding.MethodName String methodName, @Binding.MethodDesc String methodDesc,
@Binding.Args Object[] args, @Binding.Return Object returnObj) {
SpyAPI.atExit(clazz, methodName, methodDesc, target, args, returnObj);
@Binding.MethodInfo String methodInfo, @Binding.Args Object[] args, @Binding.Return Object returnObj) {
SpyAPI.atExit(clazz, methodInfo, target, args, returnObj);
}
@AtExceptionExit(inline = true)
public static void atExceptionExit(@Binding.This Object target, @Binding.Class Class<?> clazz,
@Binding.MethodName String methodName, @Binding.MethodDesc String methodDesc,
@Binding.Args Object[] args, @Binding.Throwable Throwable throwable) {
SpyAPI.atExceptionExit(clazz, methodName, methodDesc, target, args, throwable);
@Binding.MethodInfo String methodInfo, @Binding.Args Object[] args,
@Binding.Throwable Throwable throwable) {
SpyAPI.atExceptionExit(clazz, methodInfo, target, args, throwable);
}
}

@ -32,18 +32,18 @@ public class SpyAPI {
spyInstance = spy;
}
public static void atEnter(Class<?> clazz, String methodName, String methodDesc, Object target, Object[] args) {
spyInstance.atEnter(clazz, methodName, methodDesc, target, args);
public static void atEnter(Class<?> clazz, String methodInfo, Object target, Object[] args) {
spyInstance.atEnter(clazz, methodInfo, target, args);
}
public static void atExit(Class<?> clazz, String methodName, String methodDesc, Object target, Object[] args,
public static void atExit(Class<?> clazz, String methodInfo, Object target, Object[] args,
Object returnObject) {
spyInstance.atExit(clazz, methodName, methodDesc, target, args, returnObject);
spyInstance.atExit(clazz, methodInfo, target, args, returnObject);
}
public static void atExceptionExit(Class<?> clazz, String methodName, String methodDesc, Object target,
public static void atExceptionExit(Class<?> clazz, String methodInfo, Object target,
Object[] args, Throwable throwable) {
spyInstance.atExceptionExit(clazz, methodName, methodDesc, target, args, throwable);
spyInstance.atExceptionExit(clazz, methodInfo, target, args, throwable);
}
public static void atBeforeInvoke(Class<?> clazz, String invokeInfo, Object target) {
@ -59,13 +59,13 @@ public class SpyAPI {
}
public static abstract class AbstractSpy {
public abstract void atEnter(Class<?> clazz, String methodName, String methodDesc, Object target,
public abstract void atEnter(Class<?> clazz, String methodInfo, Object target,
Object[] args);
public abstract void atExit(Class<?> clazz, String methodName, String methodDesc, Object target, Object[] args,
public abstract void atExit(Class<?> clazz, String methodInfo, Object target, Object[] args,
Object returnObject);
public abstract void atExceptionExit(Class<?> clazz, String methodName, String methodDesc, Object target,
public abstract void atExceptionExit(Class<?> clazz, String methodInfo, Object target,
Object[] args, Throwable throwable);
public abstract void atBeforeInvoke(Class<?> clazz, String invokeInfo, Object target);
@ -78,16 +78,16 @@ public class SpyAPI {
static class NopSpy extends AbstractSpy {
@Override
public void atEnter(Class<?> clazz, String methodName, String methodDesc, Object target, Object[] args) {
public void atEnter(Class<?> clazz, String methodInfo, Object target, Object[] args) {
}
@Override
public void atExit(Class<?> clazz, String methodName, String methodDesc, Object target, Object[] args,
public void atExit(Class<?> clazz, String methodInfo, Object target, Object[] args,
Object returnObject) {
}
@Override
public void atExceptionExit(Class<?> clazz, String methodName, String methodDesc, Object target, Object[] args,
public void atExceptionExit(Class<?> clazz, String methodInfo, Object target, Object[] args,
Throwable throwable) {
}

Loading…
Cancel
Save