I am using the JDI to recode the variable status in the method. According to the tutorial, I am not found how to get objectReference value, like List, Map or my custom class. It just can get 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());
}
}
if LocalVariable is PrimtiveValue type, like int a = 10;
, then it will print
console->> a = 10
if LocalVariable is ObjectReference type, like Map data = new HashMap();data.pull("a",10)
, then it will print
console->> data = instance of java.util.HashMap(id=101)
But I want to get result like below
console->> data = {a:10} // as long as get the data of reference value
Thanks!
visibleVariables()
business will give you nothing unless the code was compiled withjavac -g
, which most production code won't be. – Eldaelden