/// <summary> /// Creates an enumerator for properties associated with the stack frame, such as local variables. /// </summary> /// <param name="dwFields">A combination of flags from the DEBUGPROP_INFO_FLAGS enumeration that specifies which fields in the enumerated DEBUG_PROPERTY_INFO structures are to be filled in.</param> /// <param name="nRadix">The radix to be used in formatting any numerical information.</param> /// <param name="guidFilter">A GUID of a filter used to select which DEBUG_PROPERTY_INFO structures are to be enumerated, such as guidFilterLocals.</param> /// <param name="dwTimeout">Maximum time, in milliseconds, to wait before returning from this method. Use INFINITE to wait indefinitely.</param> /// <param name="pcelt">Returns the number of properties enumerated. This is the same as calling the IEnumDebugPropertyInfo2::GetCount method.</param> /// <param name="ppEnum">Returns an IEnumDebugPropertyInfo2 object containing a list of the desired properties.</param> /// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns> /// <remarks> /// Because this method allows all selected properties to be retrieved with a single call, it is faster than /// sequentially calling the IDebugStackFrame2.GetDebugProperty and IDebugProperty2.EnumChildren methods. /// </remarks> public int EnumProperties(enum_DEBUGPROP_INFO_FLAGS dwFields, uint nRadix, ref Guid guidFilter, uint dwTimeout, out uint pcelt, out IEnumDebugPropertyInfo2 ppEnum) { pcelt = 0; ppEnum = null; if (_nativeMethod || !_stackFrame.GetHasVariableInfo()) { return(VSConstants.E_FAIL); } ReadOnlyCollection <ILocalVariable> locals = _stackFrame.GetVisibleVariables(); bool getFullName = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME) != 0; bool getName = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME) != 0; bool getType = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE) != 0; bool getValue = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE) != 0; bool getAttributes = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB) != 0; bool getProperty = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_PROP) != 0; bool useAutoExpandValue = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_AUTOEXPAND) != 0; bool noFormatting = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_RAW) != 0; bool noToString = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_NO_TOSTRING) != 0; List <DEBUG_PROPERTY_INFO> properties = new List <DEBUG_PROPERTY_INFO>(); DEBUG_PROPERTY_INFO[] propertyInfo = new DEBUG_PROPERTY_INFO[1]; if (!_nativeMethod && !_stackFrame.GetLocation().GetMethod().GetIsStatic()) { // get the 'this' property propertyInfo[0] = default(DEBUG_PROPERTY_INFO); if (getValue || getProperty) { string name = "this"; IType propertyType = _stackFrame.GetLocation().GetDeclaringType(); IValue value = _stackFrame.GetThisObject(); JavaDebugProperty property = new JavaDebugProperty(_debugProperty, name, name, propertyType, value, false); int hr = property.GetPropertyInfo(dwFields, nRadix, dwTimeout, null, 0, propertyInfo); if (ErrorHandler.Failed(hr)) { return(hr); } properties.Add(propertyInfo[0]); } else { if (getFullName) { propertyInfo[0].bstrFullName = "this"; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME; } if (getName) { propertyInfo[0].bstrName = "this"; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME; } if (getType) { propertyInfo[0].bstrType = _stackFrame.GetLocation().GetDeclaringType().GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE; } if (getAttributes) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_READONLY; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB; } } } foreach (var local in locals) { propertyInfo[0] = default(DEBUG_PROPERTY_INFO); if (getValue || getProperty) { string name = local.GetName(); IType propertyType = local.GetLocalType(); IValue value = _stackFrame.GetValue(local); JavaDebugProperty property = new JavaDebugProperty(_debugProperty, name, name, propertyType, value, false); int hr = property.GetPropertyInfo(dwFields, nRadix, dwTimeout, null, 0, propertyInfo); if (ErrorHandler.Failed(hr)) { return(hr); } properties.Add(propertyInfo[0]); continue; } else { if (getFullName) { propertyInfo[0].bstrFullName = local.GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME; } if (getName) { propertyInfo[0].bstrName = local.GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME; } if (getType) { propertyInfo[0].bstrType = local.GetLocalTypeName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE; } if (getAttributes) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_READONLY; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB; #if false bool expandable; bool hasId; bool canHaveId; bool readOnly; bool error; bool sideEffect; bool overloadedContainer; bool boolean; bool booleanTrue; bool invalid; bool notAThing; bool autoExpanded; bool timeout; bool rawString; bool customViewer; bool accessNone; bool accessPrivate; bool accessProtected; bool accessPublic; bool storageNone; bool storageGlobal; bool storageStatic; bool storageRegister; bool noModifiers; bool @virtual; bool constant; bool synchronized; bool @volatile; bool dataField; bool method; bool property; bool @class; bool baseClass; bool @interface; bool innerClass; bool mostDerived; bool multiCustomViewers; #endif } } } ppEnum = new EnumDebugPropertyInfo(properties); pcelt = (uint)properties.Count; return(VSConstants.S_OK); }
public int EnumChildren(enum_DEBUGPROP_INFO_FLAGS dwFields, uint dwRadix, ref Guid guidFilter, enum_DBG_ATTRIB_FLAGS dwAttribFilter, string pszNameFilter, uint dwTimeout, out IEnumDebugPropertyInfo2 ppEnum) { Stopwatch stopwatch = Stopwatch.StartNew(); bool infinite = dwTimeout == unchecked ((uint)Timeout.Infinite); TimeSpan timeout = infinite ? TimeSpan.Zero : TimeSpan.FromMilliseconds(dwTimeout); IObjectReference objectReference = _evaluatedExpression.Value as IObjectReference; IReferenceType referenceType = _evaluatedExpression.ValueType as IReferenceType; if (objectReference == null || referenceType == null) { ppEnum = new EnumDebugPropertyInfo(Enumerable.Empty <DEBUG_PROPERTY_INFO>()); return(VSConstants.S_OK); } ppEnum = null; bool getFullName = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME) != 0; bool getName = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME) != 0; bool getType = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE) != 0; bool getValue = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE) != 0; bool getAttributes = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB) != 0; bool getProperty = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_PROP) != 0; bool useAutoExpandValue = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_AUTOEXPAND) != 0; bool noFormatting = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_RAW) != 0; bool noToString = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_NO_TOSTRING) != 0; List <DEBUG_PROPERTY_INFO> properties = new List <DEBUG_PROPERTY_INFO>(); DEBUG_PROPERTY_INFO[] propertyInfo = new DEBUG_PROPERTY_INFO[1]; bool isCollection = false; int collectionSize = 0; bool haveCollectionValues = false; ReadOnlyCollection <IValue> collectionValues = null; IType componentType = null; if (!_useRawValues) { isCollection = TryGetCollectionSize(objectReference, out collectionSize); if (isCollection && (getValue || getProperty)) { haveCollectionValues = TryGetCollectionValues(objectReference, out collectionValues, out componentType); } } if (isCollection) { for (int i = 0; i < collectionSize; i++) { propertyInfo[0] = default(DEBUG_PROPERTY_INFO); if (haveCollectionValues) { string name = "[" + i + "]"; IType propertyType = componentType; IValue value = collectionValues[i]; JavaDebugProperty property = new JavaDebugProperty(this, name, _evaluatedExpression.FullName + name, propertyType, value, _evaluatedExpression.HasSideEffects); bool timedout = !infinite && timeout < stopwatch.Elapsed; enum_DEBUGPROP_INFO_FLAGS fields = dwFields; if (timedout) { fields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_NO_TOSTRING; } int hr = property.GetPropertyInfo(fields, dwRadix, dwTimeout, null, 0, propertyInfo); if (ErrorHandler.Failed(hr)) { return(hr); } if (timedout) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_TIMEOUT; } properties.Add(propertyInfo[0]); continue; } else { if (getFullName) { propertyInfo[0].bstrFullName = _evaluatedExpression.FullName + "[" + i + "]"; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME; } if (getName) { propertyInfo[0].bstrName = "[" + i + "]"; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME; } if (getType) { propertyInfo[0].bstrType = componentType.GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE; } if (getAttributes) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_AUTOEXPANDED; propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_READONLY; if (_evaluatedExpression.HasSideEffects) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_SIDE_EFFECT; } propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB; } } } bool useRawValues = referenceType is IClassType; if (useRawValues) { if (_rawValuesProperty == null) { _rawValuesProperty = new JavaDebugProperty(this, "Raw Values") { _useRawValues = true }; } propertyInfo[0] = default(DEBUG_PROPERTY_INFO); ErrorHandler.ThrowOnFailure(_rawValuesProperty.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); properties.Add(propertyInfo[0]); } } else { ReadOnlyCollection <IField> fields = referenceType.GetFields(false); List <IField> staticFields = new List <IField>(fields.Where(i => i.GetIsStatic())); bool useMostDerived = !_preventMostDerived && _evaluatedExpression.Value != null && !_evaluatedExpression.Value.GetValueType().Equals(referenceType); if (useMostDerived) { if (_mostDerivedProperty == null) { _mostDerivedProperty = new JavaDebugProperty(this, string.Format("[{0}]", _evaluatedExpression.Value.GetValueType().GetName()), _evaluatedExpression.Value.GetValueType()) { _preventMostDerived = true }; } propertyInfo[0] = default(DEBUG_PROPERTY_INFO); ErrorHandler.ThrowOnFailure(_mostDerivedProperty.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); properties.Add(propertyInfo[0]); } bool useSuper = false; if (!useMostDerived) { IClassType valueType = _evaluatedExpression.ValueType as IClassType; if (valueType != null) { IClassType superClass = valueType.GetSuperclass(); useSuper = superClass != null && superClass.GetName() != "java.lang.Object"; if (useSuper) { if (_superProperty == null) { _superProperty = new JavaDebugProperty(this, "[super]", superClass) { _preventMostDerived = true }; } propertyInfo[0] = default(DEBUG_PROPERTY_INFO); ErrorHandler.ThrowOnFailure(_superProperty.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); properties.Add(propertyInfo[0]); } } } foreach (var field in fields) { if (field.GetIsStatic()) { continue; } propertyInfo[0] = default(DEBUG_PROPERTY_INFO); if (getValue || getProperty) { IDebugProperty2 property; try { string name = field.GetName(); IType propertyType = field.GetFieldType(); IValue value = objectReference.GetValue(field); property = new JavaDebugProperty(this, name, _evaluatedExpression.FullName + "." + name, propertyType, value, _evaluatedExpression.HasSideEffects, field); ErrorHandler.ThrowOnFailure(property.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); } catch (Exception e) { if (ErrorHandler.IsCriticalException(e)) { throw; } string name = field.GetName(); IType propertyType = field.GetFieldType(); IValue value = field.GetVirtualMachine().GetMirrorOf(0); property = new JavaDebugProperty(this, name, _evaluatedExpression.FullName + "." + name, propertyType, value, _evaluatedExpression.HasSideEffects, field); ErrorHandler.ThrowOnFailure(property.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); } } else { if (getFullName) { propertyInfo[0].bstrFullName = _evaluatedExpression.FullName + "." + field.GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME; } if (getName) { propertyInfo[0].bstrName = field.GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME; } if (getType) { propertyInfo[0].bstrType = field.GetFieldTypeName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE; } if (getAttributes) { if (field.GetIsStatic()) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_STORAGE_STATIC; } if (field.GetIsPrivate()) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_PRIVATE; } if (field.GetIsProtected()) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_PROTECTED; } if (field.GetIsPublic()) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_PUBLIC; } propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_READONLY; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB; #if false bool expandable; bool hasId; bool canHaveId; bool readOnly; bool error; bool sideEffect; bool overloadedContainer; bool boolean; bool booleanTrue; bool invalid; bool notAThing; bool autoExpanded; bool timeout; bool rawString; bool customViewer; bool accessNone; bool accessPrivate; bool accessProtected; bool accessPublic; bool storageNone; bool storageGlobal; bool storageStatic; bool storageRegister; bool noModifiers; bool @virtual; bool constant; bool synchronized; bool @volatile; bool dataField; bool method; bool property; bool @class; bool baseClass; bool @interface; bool innerClass; bool mostDerived; bool multiCustomViewers; #endif } } properties.Add(propertyInfo[0]); continue; } if (staticFields.Count > 0) { propertyInfo[0] = default(DEBUG_PROPERTY_INFO); JavaDebugStaticMembersPseudoProperty property = new JavaDebugStaticMembersPseudoProperty(this, referenceType, staticFields); ErrorHandler.ThrowOnFailure(property.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); properties.Add(propertyInfo[0]); } } ppEnum = new EnumDebugPropertyInfo(properties); return(VSConstants.S_OK); }
public int EnumChildren(enum_DEBUGPROP_INFO_FLAGS dwFields, uint dwRadix, ref Guid guidFilter, enum_DBG_ATTRIB_FLAGS dwAttribFilter, string pszNameFilter, uint dwTimeout, out IEnumDebugPropertyInfo2 ppEnum) { ppEnum = null; bool getFullName = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME) != 0; bool getName = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME) != 0; bool getType = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE) != 0; bool getValue = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE) != 0; bool getAttributes = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB) != 0; bool getProperty = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_PROP) != 0; bool useAutoExpandValue = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_AUTOEXPAND) != 0; bool noFormatting = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_RAW) != 0; bool noToString = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_NO_TOSTRING) != 0; List<DEBUG_PROPERTY_INFO> properties = new List<DEBUG_PROPERTY_INFO>(); DEBUG_PROPERTY_INFO[] propertyInfo = new DEBUG_PROPERTY_INFO[1]; IList<IField> fields = _fields; if (fields == null) { ReadOnlyCollection<IField> allFields = _referenceType.GetFields(false); fields = new List<IField>(allFields.Where(i => i.GetIsStatic())); } string typeName = _referenceType.GetName(); foreach (var field in fields) { propertyInfo[0] = default(DEBUG_PROPERTY_INFO); if (getValue || getProperty) { IDebugProperty2 property; try { string name = field.GetName(); IType propertyType = field.GetFieldType(); IValue value = _referenceType.GetValue(field); property = new JavaDebugProperty(this, name, typeName + "." + name, propertyType, value, false, field); ErrorHandler.ThrowOnFailure(property.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); } catch (Exception e) { if (ErrorHandler.IsCriticalException(e)) throw; string name = field.GetName(); IType propertyType = field.GetFieldType(); IValue value = field.GetVirtualMachine().GetMirrorOf(0); property = new JavaDebugProperty(this, name, typeName + "." + name, propertyType, value, false, field); ErrorHandler.ThrowOnFailure(property.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); } } else { if (getFullName) { propertyInfo[0].bstrFullName = typeName + "." + field.GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME; } if (getName) { propertyInfo[0].bstrName = field.GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME; } if (getType) { propertyInfo[0].bstrType = field.GetFieldTypeName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE; } if (getAttributes) { if (field.GetIsStatic()) propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_STORAGE_STATIC; if (field.GetIsPrivate()) propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_PRIVATE; if (field.GetIsProtected()) propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_PROTECTED; if (field.GetIsPublic()) propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_PUBLIC; propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_READONLY; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB; #if false bool expandable; bool hasId; bool canHaveId; bool readOnly; bool error; bool sideEffect; bool overloadedContainer; bool boolean; bool booleanTrue; bool invalid; bool notAThing; bool autoExpanded; bool timeout; bool rawString; bool customViewer; bool accessNone; bool accessPrivate; bool accessProtected; bool accessPublic; bool storageNone; bool storageGlobal; bool storageStatic; bool storageRegister; bool noModifiers; bool @virtual; bool constant; bool synchronized; bool @volatile; bool dataField; bool method; bool property; bool @class; bool baseClass; bool @interface; bool innerClass; bool mostDerived; bool multiCustomViewers; #endif } } properties.Add(propertyInfo[0]); continue; } ppEnum = new EnumDebugPropertyInfo(properties); return VSConstants.S_OK; }
/// <summary> /// Creates an enumerator for properties associated with the stack frame, such as local variables. /// </summary> /// <param name="dwFields">A combination of flags from the DEBUGPROP_INFO_FLAGS enumeration that specifies which fields in the enumerated DEBUG_PROPERTY_INFO structures are to be filled in.</param> /// <param name="nRadix">The radix to be used in formatting any numerical information.</param> /// <param name="guidFilter">A GUID of a filter used to select which DEBUG_PROPERTY_INFO structures are to be enumerated, such as guidFilterLocals.</param> /// <param name="dwTimeout">Maximum time, in milliseconds, to wait before returning from this method. Use INFINITE to wait indefinitely.</param> /// <param name="pcelt">Returns the number of properties enumerated. This is the same as calling the IEnumDebugPropertyInfo2::GetCount method.</param> /// <param name="ppEnum">Returns an IEnumDebugPropertyInfo2 object containing a list of the desired properties.</param> /// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns> /// <remarks> /// Because this method allows all selected properties to be retrieved with a single call, it is faster than /// sequentially calling the IDebugStackFrame2.GetDebugProperty and IDebugProperty2.EnumChildren methods. /// </remarks> public int EnumProperties(enum_DEBUGPROP_INFO_FLAGS dwFields, uint nRadix, ref Guid guidFilter, uint dwTimeout, out uint pcelt, out IEnumDebugPropertyInfo2 ppEnum) { pcelt = 0; ppEnum = null; if (_nativeMethod || !_stackFrame.GetHasVariableInfo()) return VSConstants.E_FAIL; ReadOnlyCollection<ILocalVariable> locals = _stackFrame.GetVisibleVariables(); bool getFullName = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME) != 0; bool getName = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME) != 0; bool getType = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE) != 0; bool getValue = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE) != 0; bool getAttributes = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB) != 0; bool getProperty = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_PROP) != 0; bool useAutoExpandValue = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_AUTOEXPAND) != 0; bool noFormatting = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_RAW) != 0; bool noToString = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_NO_TOSTRING) != 0; List<DEBUG_PROPERTY_INFO> properties = new List<DEBUG_PROPERTY_INFO>(); DEBUG_PROPERTY_INFO[] propertyInfo = new DEBUG_PROPERTY_INFO[1]; if (!_nativeMethod && !_stackFrame.GetLocation().GetMethod().GetIsStatic()) { // get the 'this' property propertyInfo[0] = default(DEBUG_PROPERTY_INFO); if (getValue || getProperty) { string name = "this"; IType propertyType = _stackFrame.GetLocation().GetDeclaringType(); IValue value = _stackFrame.GetThisObject(); JavaDebugProperty property = new JavaDebugProperty(_debugProperty, name, name, propertyType, value, false); int hr = property.GetPropertyInfo(dwFields, nRadix, dwTimeout, null, 0, propertyInfo); if (ErrorHandler.Failed(hr)) return hr; properties.Add(propertyInfo[0]); } else { if (getFullName) { propertyInfo[0].bstrFullName = "this"; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME; } if (getName) { propertyInfo[0].bstrName = "this"; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME; } if (getType) { propertyInfo[0].bstrType = _stackFrame.GetLocation().GetDeclaringType().GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE; } if (getAttributes) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_READONLY; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB; } } } foreach (var local in locals) { propertyInfo[0] = default(DEBUG_PROPERTY_INFO); if (getValue || getProperty) { string name = local.GetName(); IType propertyType = local.GetLocalType(); IValue value = _stackFrame.GetValue(local); JavaDebugProperty property = new JavaDebugProperty(_debugProperty, name, name, propertyType, value, false); int hr = property.GetPropertyInfo(dwFields, nRadix, dwTimeout, null, 0, propertyInfo); if (ErrorHandler.Failed(hr)) return hr; properties.Add(propertyInfo[0]); continue; } else { if (getFullName) { propertyInfo[0].bstrFullName = local.GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME; } if (getName) { propertyInfo[0].bstrName = local.GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME; } if (getType) { propertyInfo[0].bstrType = local.GetLocalTypeName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE; } if (getAttributes) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_READONLY; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB; #if false bool expandable; bool hasId; bool canHaveId; bool readOnly; bool error; bool sideEffect; bool overloadedContainer; bool boolean; bool booleanTrue; bool invalid; bool notAThing; bool autoExpanded; bool timeout; bool rawString; bool customViewer; bool accessNone; bool accessPrivate; bool accessProtected; bool accessPublic; bool storageNone; bool storageGlobal; bool storageStatic; bool storageRegister; bool noModifiers; bool @virtual; bool constant; bool synchronized; bool @volatile; bool dataField; bool method; bool property; bool @class; bool baseClass; bool @interface; bool innerClass; bool mostDerived; bool multiCustomViewers; #endif } } } ppEnum = new EnumDebugPropertyInfo(properties); pcelt = (uint)properties.Count; return VSConstants.S_OK; }
public int EnumChildren(enum_DEBUGPROP_INFO_FLAGS dwFields, uint dwRadix, ref Guid guidFilter, enum_DBG_ATTRIB_FLAGS dwAttribFilter, string pszNameFilter, uint dwTimeout, out IEnumDebugPropertyInfo2 ppEnum) { ppEnum = null; bool getFullName = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME) != 0; bool getName = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME) != 0; bool getType = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE) != 0; bool getValue = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE) != 0; bool getAttributes = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB) != 0; bool getProperty = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_PROP) != 0; bool useAutoExpandValue = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_AUTOEXPAND) != 0; bool noFormatting = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_RAW) != 0; bool noToString = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_NO_TOSTRING) != 0; List <DEBUG_PROPERTY_INFO> properties = new List <DEBUG_PROPERTY_INFO>(); DEBUG_PROPERTY_INFO[] propertyInfo = new DEBUG_PROPERTY_INFO[1]; IList <IField> fields = _fields; if (fields == null) { ReadOnlyCollection <IField> allFields = _referenceType.GetFields(false); fields = new List <IField>(allFields.Where(i => i.GetIsStatic())); } string typeName = _referenceType.GetName(); foreach (var field in fields) { propertyInfo[0] = default(DEBUG_PROPERTY_INFO); if (getValue || getProperty) { IDebugProperty2 property; try { string name = field.GetName(); IType propertyType = field.GetFieldType(); IValue value = _referenceType.GetValue(field); property = new JavaDebugProperty(this, name, typeName + "." + name, propertyType, value, false, field); ErrorHandler.ThrowOnFailure(property.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); } catch (Exception e) { if (ErrorHandler.IsCriticalException(e)) { throw; } string name = field.GetName(); IType propertyType = field.GetFieldType(); IValue value = field.GetVirtualMachine().GetMirrorOf(0); property = new JavaDebugProperty(this, name, typeName + "." + name, propertyType, value, false, field); ErrorHandler.ThrowOnFailure(property.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); } } else { if (getFullName) { propertyInfo[0].bstrFullName = typeName + "." + field.GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME; } if (getName) { propertyInfo[0].bstrName = field.GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME; } if (getType) { propertyInfo[0].bstrType = field.GetFieldTypeName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE; } if (getAttributes) { if (field.GetIsStatic()) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_STORAGE_STATIC; } if (field.GetIsPrivate()) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_PRIVATE; } if (field.GetIsProtected()) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_PROTECTED; } if (field.GetIsPublic()) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_PUBLIC; } propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_READONLY; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB; #if false bool expandable; bool hasId; bool canHaveId; bool readOnly; bool error; bool sideEffect; bool overloadedContainer; bool boolean; bool booleanTrue; bool invalid; bool notAThing; bool autoExpanded; bool timeout; bool rawString; bool customViewer; bool accessNone; bool accessPrivate; bool accessProtected; bool accessPublic; bool storageNone; bool storageGlobal; bool storageStatic; bool storageRegister; bool noModifiers; bool @virtual; bool constant; bool synchronized; bool @volatile; bool dataField; bool method; bool property; bool @class; bool baseClass; bool @interface; bool innerClass; bool mostDerived; bool multiCustomViewers; #endif } } properties.Add(propertyInfo[0]); continue; } ppEnum = new EnumDebugPropertyInfo(properties); return(VSConstants.S_OK); }
public int EnumChildren(enum_DEBUGPROP_INFO_FLAGS dwFields, uint dwRadix, ref Guid guidFilter, enum_DBG_ATTRIB_FLAGS dwAttribFilter, string pszNameFilter, uint dwTimeout, out IEnumDebugPropertyInfo2 ppEnum) { Stopwatch stopwatch = Stopwatch.StartNew(); bool infinite = dwTimeout == unchecked((uint)Timeout.Infinite); TimeSpan timeout = infinite ? TimeSpan.Zero : TimeSpan.FromMilliseconds(dwTimeout); IObjectReference objectReference = _evaluatedExpression.Value as IObjectReference; IReferenceType referenceType = _evaluatedExpression.ValueType as IReferenceType; if (objectReference == null || referenceType == null) { ppEnum = new EnumDebugPropertyInfo(Enumerable.Empty<DEBUG_PROPERTY_INFO>()); return VSConstants.S_OK; } ppEnum = null; bool getFullName = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME) != 0; bool getName = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME) != 0; bool getType = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE) != 0; bool getValue = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE) != 0; bool getAttributes = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB) != 0; bool getProperty = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_PROP) != 0; bool useAutoExpandValue = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_AUTOEXPAND) != 0; bool noFormatting = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_RAW) != 0; bool noToString = (dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_NO_TOSTRING) != 0; List<DEBUG_PROPERTY_INFO> properties = new List<DEBUG_PROPERTY_INFO>(); DEBUG_PROPERTY_INFO[] propertyInfo = new DEBUG_PROPERTY_INFO[1]; bool isCollection = false; int collectionSize = 0; bool haveCollectionValues = false; ReadOnlyCollection<IValue> collectionValues = null; IType componentType = null; if (!_useRawValues) { isCollection = TryGetCollectionSize(objectReference, out collectionSize); if (isCollection && (getValue || getProperty)) { haveCollectionValues = TryGetCollectionValues(objectReference, out collectionValues, out componentType); } } if (isCollection) { for (int i = 0; i < collectionSize; i++) { propertyInfo[0] = default(DEBUG_PROPERTY_INFO); if (haveCollectionValues) { string name = "[" + i + "]"; IType propertyType = componentType; IValue value = collectionValues[i]; JavaDebugProperty property = new JavaDebugProperty(this, name, _evaluatedExpression.FullName + name, propertyType, value, _evaluatedExpression.HasSideEffects); bool timedout = !infinite && timeout < stopwatch.Elapsed; enum_DEBUGPROP_INFO_FLAGS fields = dwFields; if (timedout) fields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_NO_TOSTRING; int hr = property.GetPropertyInfo(fields, dwRadix, dwTimeout, null, 0, propertyInfo); if (ErrorHandler.Failed(hr)) return hr; if (timedout) propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_TIMEOUT; properties.Add(propertyInfo[0]); continue; } else { if (getFullName) { propertyInfo[0].bstrFullName = _evaluatedExpression.FullName + "[" + i + "]"; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME; } if (getName) { propertyInfo[0].bstrName = "[" + i + "]"; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME; } if (getType) { propertyInfo[0].bstrType = componentType.GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE; } if (getAttributes) { propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_AUTOEXPANDED; propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_READONLY; if (_evaluatedExpression.HasSideEffects) propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_SIDE_EFFECT; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB; } } } bool useRawValues = referenceType is IClassType; if (useRawValues) { if (_rawValuesProperty == null) { _rawValuesProperty = new JavaDebugProperty(this, "Raw Values") { _useRawValues = true }; } propertyInfo[0] = default(DEBUG_PROPERTY_INFO); ErrorHandler.ThrowOnFailure(_rawValuesProperty.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); properties.Add(propertyInfo[0]); } } else { ReadOnlyCollection<IField> fields = referenceType.GetFields(false); List<IField> staticFields = new List<IField>(fields.Where(i => i.GetIsStatic())); bool useMostDerived = !_preventMostDerived && _evaluatedExpression.Value != null && !_evaluatedExpression.Value.GetValueType().Equals(referenceType); if (useMostDerived) { if (_mostDerivedProperty == null) { _mostDerivedProperty = new JavaDebugProperty(this, string.Format("[{0}]", _evaluatedExpression.Value.GetValueType().GetName()), _evaluatedExpression.Value.GetValueType()) { _preventMostDerived = true }; } propertyInfo[0] = default(DEBUG_PROPERTY_INFO); ErrorHandler.ThrowOnFailure(_mostDerivedProperty.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); properties.Add(propertyInfo[0]); } bool useSuper = false; if (!useMostDerived) { IClassType valueType = _evaluatedExpression.ValueType as IClassType; if (valueType != null) { IClassType superClass = valueType.GetSuperclass(); useSuper = superClass != null && superClass.GetName() != "java.lang.Object"; if (useSuper) { if (_superProperty == null) { _superProperty = new JavaDebugProperty(this, "[super]", superClass) { _preventMostDerived = true }; } propertyInfo[0] = default(DEBUG_PROPERTY_INFO); ErrorHandler.ThrowOnFailure(_superProperty.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); properties.Add(propertyInfo[0]); } } } foreach (var field in fields) { if (field.GetIsStatic()) continue; propertyInfo[0] = default(DEBUG_PROPERTY_INFO); if (getValue || getProperty) { IDebugProperty2 property; try { string name = field.GetName(); IType propertyType = field.GetFieldType(); IValue value = objectReference.GetValue(field); property = new JavaDebugProperty(this, name, _evaluatedExpression.FullName + "." + name, propertyType, value, _evaluatedExpression.HasSideEffects, field); ErrorHandler.ThrowOnFailure(property.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); } catch (Exception e) { if (ErrorHandler.IsCriticalException(e)) throw; string name = field.GetName(); IType propertyType = field.GetFieldType(); IValue value = field.GetVirtualMachine().GetMirrorOf(0); property = new JavaDebugProperty(this, name, _evaluatedExpression.FullName + "." + name, propertyType, value, _evaluatedExpression.HasSideEffects, field); ErrorHandler.ThrowOnFailure(property.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); } } else { if (getFullName) { propertyInfo[0].bstrFullName = _evaluatedExpression.FullName + "." + field.GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME; } if (getName) { propertyInfo[0].bstrName = field.GetName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME; } if (getType) { propertyInfo[0].bstrType = field.GetFieldTypeName(); propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE; } if (getAttributes) { if (field.GetIsStatic()) propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_STORAGE_STATIC; if (field.GetIsPrivate()) propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_PRIVATE; if (field.GetIsProtected()) propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_PROTECTED; if (field.GetIsPublic()) propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_PUBLIC; propertyInfo[0].dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_READONLY; propertyInfo[0].dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB; #if false bool expandable; bool hasId; bool canHaveId; bool readOnly; bool error; bool sideEffect; bool overloadedContainer; bool boolean; bool booleanTrue; bool invalid; bool notAThing; bool autoExpanded; bool timeout; bool rawString; bool customViewer; bool accessNone; bool accessPrivate; bool accessProtected; bool accessPublic; bool storageNone; bool storageGlobal; bool storageStatic; bool storageRegister; bool noModifiers; bool @virtual; bool constant; bool synchronized; bool @volatile; bool dataField; bool method; bool property; bool @class; bool baseClass; bool @interface; bool innerClass; bool mostDerived; bool multiCustomViewers; #endif } } properties.Add(propertyInfo[0]); continue; } if (staticFields.Count > 0) { propertyInfo[0] = default(DEBUG_PROPERTY_INFO); JavaDebugStaticMembersPseudoProperty property = new JavaDebugStaticMembersPseudoProperty(this, referenceType, staticFields); ErrorHandler.ThrowOnFailure(property.GetPropertyInfo(dwFields, dwRadix, dwTimeout, null, 0, propertyInfo)); properties.Add(propertyInfo[0]); } } ppEnum = new EnumDebugPropertyInfo(properties); return VSConstants.S_OK; }