From ffdf1273de812a45f240f21ed17e040f40b6142d Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Fri, 20 Feb 2015 07:39:31 -0600 Subject: [PATCH] Fix expression evaluation when toString() returns null Fixes #29 --- .../ObjectReference.cs | 4 +++ .../Debugger/JavaDebugProperty.cs | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Tvl.Java.DebugInterface.Client/ObjectReference.cs b/Tvl.Java.DebugInterface.Client/ObjectReference.cs index bbf4ebb2..a72e83b8 100644 --- a/Tvl.Java.DebugInterface.Client/ObjectReference.cs +++ b/Tvl.Java.DebugInterface.Client/ObjectReference.cs @@ -118,6 +118,10 @@ public IStrongValueHandle InvokeMethod(IThreadReference thread, IMethod throw new NotImplementedException(); } + Value returnValueMirror = VirtualMachine.GetMirrorOf(returnValue); + if (returnValueMirror == null) + return null; + return new StrongValueHandle(VirtualMachine.GetMirrorOf(returnValue)); } diff --git a/Tvl.VisualStudio.Language.Java/Debugger/JavaDebugProperty.cs b/Tvl.VisualStudio.Language.Java/Debugger/JavaDebugProperty.cs index aa36a794..0b7b780c 100644 --- a/Tvl.VisualStudio.Language.Java/Debugger/JavaDebugProperty.cs +++ b/Tvl.VisualStudio.Language.Java/Debugger/JavaDebugProperty.cs @@ -629,6 +629,32 @@ public int GetPropertyInfo(enum_DEBUGPROP_INFO_FLAGS dwFields, uint dwRadix, uin displayValue = stringReference.GetValue(); } } + + if (displayValue == null) + { + IClassType objectClass = classType; + while (true) + { + IClassType parentClass = objectClass.GetSuperclass(); + if (parentClass != null) + objectClass = parentClass; + else + break; + } + + IMethod objectToStringMethod = objectClass.GetConcreteMethod("toString", "()Ljava/lang/String;"); + + // fall back to a non-virtual call + using (IStrongValueHandle result = objectReference.InvokeMethod(null, objectToStringMethod, InvokeOptions.NonVirtual | InvokeOptions.SingleThreaded)) + { + if (result != null) + { + stringReference = result.Value as IStringReference; + if (stringReference != null) + displayValue = stringReference.GetValue(); + } + } + } } pPropertyInfo[0].bstrValue = "{" + displayValue + "}";