我正在使用Java Debug Interface API编写自定义程序来调试我编写的 Java 应用程序。我可以使用以下代码将断点添加到所需方法调用的开头:
ReferenceType classRef = vm.classesByName(className).get(0);
Method meth = classRef.methodsByName(methodName).get(0);
BreakpointRequest brF1 = vm.eventRequestManager().createBreakpointRequest(meth.location());
brF1.enable();
但是我无法弄清楚如何获取源文件中任意位置的 Location 对象。
最佳答案
有多种方法可以检索源文件中其他位置的位置
。
E.例如,Method
为此有几个操作:
allLineLocations()
+ 1 次重载locationsOfLine(int line)
+ 几个重载
ReferenceType 也有这方面的操作。只需浏览Location
的用法即可。
关于Java调试接口(interface): put the breakpoints at arbitrary locations in the code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8700988/