[英]What would be the best way to instrument Java classes in order to create a reverse Java debugger?
I'd like to create a reverse debugger (a debugger where it is possible to go backwards in program execution) for Java and for this I need to store variable data alongside program execution.我想为 Java 创建一个反向调试器(一个可以在程序执行中向后 go 的调试器),为此我需要在程序执行的同时存储变量数据。 I will use a global cache for this and a static method which updates the cache.
我将为此使用全局缓存和更新缓存的 static 方法。
I'd like to instrument loaded classes in such a way that after each field/variable modification, my static method will be called: eg:我想以这样一种方式检测加载的类,即在每次修改字段/变量后,我的 static 方法将被调用:例如:
public static void updateCache(String fullVarName, Object value){...}
What I observed is that when a field is updated, a putfield
instruction is executed.我观察到的是,当更新字段时,会执行
putfield
指令。 When a local variable is updated, an (I)STORE
instruction is used.更新局部变量时,使用
(I)STORE
指令。 So I thought of instrumenting the classes and whenever such an opcode is found, I simply insert another getfield
or ILOAD
after, to get the value of the updated field/variable and then I use an invokestatic
to call my static method with all the necessary information.所以我想对类进行检测,每当找到这样的操作码时,我只需在之后插入另一个
getfield
或ILOAD
,以获取更新的字段/变量的值,然后我使用invokestatic
调用我的 static 方法以及所有必要的信息.
The problem is that there are other use cases where variables are collections or arrays and they are updated with specific methods like when updating a HashMap
with map.put(key, value)
. The problem is that there are other use cases where variables are collections or arrays and they are updated with specific methods like when updating a
HashMap
with map.put(key, value)
. So I need to intercept these calls as well, but there are a high number of such methods and I need to find and hardcode them all...所以我也需要拦截这些调用,但是有很多这样的方法,我需要找到它们并对其进行硬编码......
Is there a workaround?有解决方法吗? Or maybe I am missing something and there is a simpler solution.
或者,也许我遗漏了一些东西,并且有一个更简单的解决方案。
Edit: I've also looked into JVMTI before and ran some benchmarks.编辑:我之前也研究过 JVMTI 并运行了一些基准测试。 It seemed that it is too slow for my use case eg adds an 7-100x slowdown to my program.....
它似乎对我的用例来说太慢了,例如为我的程序增加了 7-100 倍的减速.....
If your goal is to get only the possibility for reverse debugging, you can try Jive ( https://cse.buffalo.edu/jive/ ).如果您的目标是只获得反向调试的可能性,您可以尝试 Jive ( https://cse.buffalo.edu/jive/ )。 It can be used together with Eclipse.
它可以与Eclipse一起使用。
But if your goal is to create a reverse debugging tool by yourself this article may help you: https://www.researchgate.net/publication/220093333_Back_to_the_Future_Omniscient_Debugging但是,如果您的目标是自己创建一个反向调试工具,这篇文章可能会对您有所帮助: https://www.researchgate.net/publication/220093333_Back_to_the_Future_Omniscient_Debugging
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.