- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 JDI 重新编码方法中的变量状态。根据教程,我没有找到如何获取 objectReference 值,例如 List、Map 或我的自定义类。它只是可以获得PrimtiveValue。
StackFrame stackFrame = ((BreakpointEvent) event).thread().frame(0);
Map<LocalVariable, Value> visibleVariables = (Map<LocalVariable, Value>) stackFrame
.getValues(stackFrame.visibleVariables());
for (Map.Entry<LocalVariable, Value> entry : visibleVariables.entrySet()) {
System.out.println("console->>" + entry.getKey().name() + " = " + entry.getValue());
}
}
如果LocalVariable是PrimtiveValue类型,如int a = 10;
,那么它将打印
console->> a = 10
如果LocalVariable是ObjectReference类型,如Map data = new HashMap();data.pull("a",10)
,那么它会打印
console->> data = instance of java.util.HashMap(id=101)
但我想得到如下结果
console->> data = {a:10} // as long as get the data of reference value
谢谢!
最佳答案
ObjectReference
没有“值” 。它本身就是 Value
的一个实例.
您可能想要的是获取此 ObjectReference
引用的对象的字符串表示形式。在这种情况下,您需要对该对象调用 toString()
方法。
调用ObjectReference.invokeMethod
为 toString()
传递一个Method
。结果,您将获得一个 StringReference
实例,然后您可以在该实例上调用 value()
以获得所需的字符串表示形式。
for (Map.Entry<LocalVariable, Value> entry : visibleVariables.entrySet()) {
String name = entry.getKey().name();
Value value = entry.getValue();
if (value instanceof ObjectReference) {
ObjectReference ref = (ObjectReference) value;
Method toString = ref.referenceType()
.methodsByName("toString", "()Ljava/lang/String;").get(0);
try {
value = ref.invokeMethod(thread, toString, Collections.emptyList(), 0);
} catch (Exception e) {
// Handle error
}
}
System.out.println(name + " : " + value);
}
关于java - JDI:如何获取ObjectReference值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59010599/
当我尝试在我的设备上调试时,有时会出现错误并且调试器不会在任何断点处停止。此外,该应用程序甚至无法正常启动,它只是在有点黑屏的情况下卡住,顶部有应用程序图标和名称。 错误是 Eclipse 中的弹出窗
我刚刚开始了解一些用于创建自定义调试器的 JDI。我一直在尝试将引用对象转换为真实对象,这样我就可以在不使用调用的情况下访问它们的字段或方法。我将 jar 从目标虚拟机包含到项目中,这样我就可以访问所
我正在使用 JDI 重新编码方法中的变量状态。根据教程,我没有找到如何获取 objectReference 值,例如 List、Map 或我的自定义类。它只是可以获得PrimtiveValue。 St
我正在创建一个 MethodEntryRequest,我想将此请求仅应用于两个类模式的方法,例如:- "java.*" 和 “太阳。*”。为此,我编写了以下代码。 MethodEntryRequest
我希望使用 java debug interface 构建调试器. 我的目标是设置断点并获取变量的值。 我找到了this回答接近我正在寻找的内容,我知道我必须使用以下接口(interface):- V
我已经声明并初始化了这些哈希表: Hashtable ht = new Hashtable(); ht.put("due", 2); ht.put("tre", 3); ht.put
在JDI中,有一个API可以从JPDA使用的JVM中处理的事件中排除事件。这是使用以下方法完成的: addExclusionFilter(String)排除某些模式;例如addExclusionFil
所以我正在尝试将自己投入到 JDI 中。通过首先使用 VM 命令启动被调试程序,我已经成功地将我的调试器应用程序 Hook 到我的被调试程序中: -agentlib:jdwp=transport=dt
我正在使用 JDI 来调试程序。我正在尝试更改某个对象引用中字段的值。我有 Field 对象,因为我可以通过 找到它 ObjectReference.referencetype().allFields
com.sun.jdi 是一个包,可让您获取有关正在运行的 VM 的信息、添加断点、查看堆栈帧等。 如何获取另一个实例的封闭实例?例如,下面是一些创建内部类 Garfield.Lasagna 的 4
一段时间以来,每个项目中都出现了附加的错误消息。错误发生在调试时,在调试器停止时的断点处。 Step over 和 Step into 然后不工作(一直按 step over 或 into 弹出错误消
我正在使用 JDI 调试另一个正在运行的 java 应用程序。 我所做的有效: 使用 Eclipse 运行两个应用程序。调试器使用以下 VM 选项启动: -Xdebug -Xrunjdwp:trans
我正在将我的应用程序从 JDK 7 迁移到 JDK 8。在执行过程中,我遇到了一个异常 com.sun.jdi.InvocationException occurred invoking method
我在包 com.sun.jdi 中找到了一些专为调试而设计的类,例如 VirtualMachine , 但我不能使用它,因为 Sun JDK7 中似乎不存在包。 如何使用这个包? 顺便说一句。 lib
我正在运行 Eclipse for Java。我创建了一个 XML 文件的 DOM 版本。现在我想更改文件中元素的属性。我在控制 DOM 的类中调用了一个调用方法的方法,在调试时出现了一个对话框,提示
我的代码有错误: xmldata = mContext.getResources().getStringArray(R.array.map1); for(int y = 0; y 13
我一直在编写一个使用 JDI 的 Java 客户端在远程 JVM 中创建和修改对象(通过连接到在远程 JVM 中运行的 JDWP 基于代理的服务器)。我的项目的要求之一是我无法挂起远程 JVM 中的所
我想了解如何使用 jdi 调试 java 代码,但我不知道在哪里可以获得它的源代码。是jdk里的吗?我用eclipse导入了jdk中的src.zip,但似乎没有包含jdi的信息,在哪里可以找到它? 最
我在调试时遇到了这个 eclipse 错误: org.eclipse.jdi.TimeOutException: Timeout occurred while waiting for packet 2
我正在寻找潜在的 JDI API,以便在 JVM 执行期间的任意点暂停 JVM。看着 BreakPointRequest createBreakpointRequest 方法需要一个特定的位置。是否有
我是一名优秀的程序员,十分优秀!