Java调试接口(interface): put the breakpoints at arbitrary locations in the code

标签 java debugging breakpoints jdi

我正在使用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/

相关文章:

java - 安卓上按住音量键?

java - Spring Boot with websphere 8.5.5 - UOWManager 事务处理失败

java - 无法解析此日期

javascript - 当应用程序在集群模式下运行时,有没有办法调试 pm2 中的工作进程

c++ - QtCreator : breakpoints not working (in debug mode)

java - JAXB 无法使用非参数构造函数编码和解码 Opensaml 和 Openws 对象?

javascript - 这个本地存储代码有问题吗?

PHP (Linux) : list files that have been executed

Java:断点如何阻止小程序绘画而不*被绊倒*?

c++ - cuda-gdb 内核断点不起作用