/// <summary> /// Checks whether we are dealing with a pointer or not. /// For pointers, it assignes values as Native Visual Studio would do. /// If we have a pointer to a struct, it calls ExtractChildren(), /// since the childValue is an empty string. /// </summary> static async Task <string> UnwrapPointerValueAsync(IVariableInformation varInfo, int charactersLeft) { string value = await varInfo.ValueAsync(); if (!varInfo.IsPointer) { return(value); } // For pointers, the assignment value is equal to the memory address and the // value is the content stored at that location. string plainValue = varInfo.AssignmentValue; string memoryAddress = varInfo.GetMemoryAddressAsHex(); string addressPrefix = FormatSpecifierUtil.SuppressMemoryAddress(varInfo.FormatSpecifier) ? "" : memoryAddress + " "; if (value != "" && plainValue != value) { return(addressPrefix + value); } if (varInfo.IsNullPointer()) { return(addressPrefix + "<NULL>"); } return(addressPrefix + await FormatChildrenListAsync( varInfo, charactersLeft - $"{addressPrefix}{{}}".Length, "???")); }
public void GetPropertyInfoPointerValueEqualsAssignmentValue() { IVariableInformation mockVarInfoChild = Substitute.For <IVariableInformation>(); mockVarInfoChild.AssignmentValue.Returns("1"); mockVarInfoChild.ValueAsync().Returns("1"); mockVarInfoChild.GetCachedView().Returns(mockVarInfoChild); mockVarInfo.Error.Returns(false); mockVarInfo.MightHaveChildren().Returns(true); mockVarInfo.IsPointer.Returns(true); mockVarInfo.AssignmentValue.Returns("0xDEADBEEF"); mockVarInfo.ValueAsync().Returns("0xDEADBEEF"); mockVarInfo.GetMemoryAddressAsHex().Returns("0xDEADBEEF"); mockVarInfo.GetChildAdapter() .Returns(new ListChildAdapter.Factory().Create(new List <IVariableInformation>() { mockVarInfoChild })); DEBUG_PROPERTY_INFO propertyInfo; // Display both the pointer value and the value representation. GetPropertyInfo( enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE | enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_AUTOEXPAND, out propertyInfo); Assert.That(propertyInfo.bstrValue, Is.EqualTo("0xDEADBEEF {1}")); // Display only the pointer. GetPropertyInfo(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE, out propertyInfo); Assert.That(propertyInfo.bstrValue, Is.EqualTo("0xDEADBEEF")); }