public static DmdPropertyInfo TryGetProperty(DmdMethodBase method) { var m = method as DmdMethodInfo; if ((object)m == null) { return(null); } var state = GetState(m.DeclaringType); if (state.toProperty.TryGetValue(method, out var property)) { return(property); } return(null); }
public static object GetColor(DmdMethodBase method, bool canBeModule) { if (method is DmdConstructorInfo) { return(GetColor(method.DeclaringType, canBeModule)); } if (method.IsStatic) { if (method.IsDefined("System.Runtime.CompilerServices.ExtensionAttribute", inherit: false)) { return(BoxedTextColor.ExtensionMethod); } return(BoxedTextColor.StaticMethod); } return(BoxedTextColor.InstanceMethod); }
public static bool TryGetKickoffMethod(DmdMethodBase method, out DmdMethodBase kickoffMethod) { var name = method.DeclaringType.Name; char c; if (!string.IsNullOrEmpty(name) && ((c = name[0]) == '<' || (c == 'V' && name.StartsWith("VB$StateMachine_", StringComparison.Ordinal)))) { var type = method.DeclaringType.DeclaringType; if ((object)type != null) { string attrName; // These attributes could be missing from the type (eg. it's a Unity assembly) if (method.DeclaringType.CanCastTo(type.AppDomain.GetWellKnownType(DmdWellKnownType.System_Runtime_CompilerServices_IAsyncStateMachine, isOptional: true))) { attrName = "System.Runtime.CompilerServices.AsyncStateMachineAttribute"; } else if (method.DeclaringType.CanCastTo(type.AppDomain.GetWellKnownType(DmdWellKnownType.System_Collections_IEnumerator, isOptional: true))) { attrName = "System.Runtime.CompilerServices.IteratorStateMachineAttribute"; } else { attrName = null; } if (attrName != null) { foreach (var m in type.DeclaredMethods) { var ca = m.FindCustomAttribute(attrName, false); if (ca == null || ca.ConstructorArguments.Count != 1) { continue; } var smType = ca.ConstructorArguments[0].Value as DmdType; if (smType == method.DeclaringType) { kickoffMethod = m; return(true); } } } } } kickoffMethod = null; return(false); }
void Format(DmdMethodBase method) { if (StateMachineUtils.TryGetKickoffMethod(method, out var kickoffMethod)) { method = kickoffMethod; } var sig = method.GetMethodSignature(); string[] operatorInfo; if (method is DmdConstructorInfo) { operatorInfo = null; } else { operatorInfo = Operators.TryGetOperatorInfo(method.Name); } bool isExplicitOrImplicit = operatorInfo != null && (operatorInfo[0] == "explicit" || operatorInfo[0] == "implicit"); if (!isExplicitOrImplicit) { if (ReturnTypes && !(method is DmdConstructorInfo)) { FormatReturnType(sig.ReturnType, TypeFormatterUtils.IsReadOnlyMethod(method)); WriteSpace(); } } if (DeclaringTypes) { FormatType(method.DeclaringType); WritePeriod(); } if (method is DmdConstructorInfo) { WriteIdentifier(TypeFormatterUtils.RemoveGenericTick(method.DeclaringType.MetadataName), TypeFormatterUtils.GetColor(method, canBeModule: false)); } else { if (TypeFormatterUtils.TryGetMethodName(method.Name, out var containingMethodName, out var localFunctionName)) { var methodColor = TypeFormatterUtils.GetColor(method, canBeModule: false); WriteIdentifier(containingMethodName, methodColor); WritePeriod(); WriteIdentifier(localFunctionName, methodColor); }
public bool TryGetNativeCode(DmdMethodBase method, out DbgDotNetNativeCode nativeCode) { if (Dispatcher.CheckAccess()) { return(TryGetNativeCodeCore(method, out nativeCode)); } return(TryGetNativeCode2(method, out nativeCode)); bool TryGetNativeCode2(DmdMethodBase method2, out DbgDotNetNativeCode nativeCode2) { DbgDotNetNativeCode nativeCodeTmp = default; bool res = Dispatcher.InvokeRethrow(() => TryGetNativeCodeCore(method2, out nativeCodeTmp)); nativeCode2 = nativeCodeTmp; return(res); } }
public override DmdMethodBase[] ReadDeclaredMethods(DmdType declaringType, DmdType reflectedType) { var ridList = reader.Metadata.GetMethodRidList(Rid); if (ridList.Count == 0) { return(Array.Empty <DmdMethodBase>()); } var methods = new DmdMethodBase[ridList.Count]; for (int i = 0; i < methods.Length; i++) { uint rid = ridList[i]; methods[i] = reader.CreateMethodDef(rid, declaringType, reflectedType); } return(methods); }
DbgDotNetValueResult CallCore(DbgDotNetValue obj, bool isCallvirt, DmdMethodBase method, ILValue[] arguments) { var options = isCallvirt ? DotNetClassHookCallOptions.IsCallvirt : DotNetClassHookCallOptions.None; foreach (var anyHook in anyClassHooks) { var res = anyHook.Call(options, obj, method, arguments); if (res != null) { return(new DbgDotNetValueResult(res, valueIsException: false)); } } var type = method.DeclaringType; if (type.IsConstructedGenericType) { type = type.GetGenericTypeDefinition(); } var typeName = DmdTypeName.Create(type); if (classHooks.TryGetValue(typeName, out var hook)) { if (DmdWellKnownTypeUtils.TryGetWellKnownType(typeName, out var wellKnownType)) { if (type != type.AppDomain.GetWellKnownType(wellKnownType, isOptional: true)) { hook = null; } } if (hook != null) { var res = hook.Call(options, obj, method, arguments); if (res != null) { return(new DbgDotNetValueResult(res, valueIsException: false)); } } } if (!canFuncEval) { throw new InterpreterMessageException(PredefinedEvaluationErrorMessages.FuncEvalDisabled); } return(runtime.Call(context, frame, obj, method, Convert(arguments, method.GetMethodSignature().GetParameterTypes()), cancellationToken)); }
DmdMethodBase[] ReadDeclaredMethods_COMThread(DmdType declaringType, DmdType reflectedType) { reader.Dispatcher.VerifyAccess(); var tokens = MDAPI.GetMethodTokens(reader.MetaDataImport, (uint)MetadataToken); if (tokens.Length == 0) { return(Array.Empty <DmdMethodBase>()); } var methods = new DmdMethodBase[tokens.Length]; for (int i = 0; i < methods.Length; i++) { uint rid = tokens[i] & 0x00FFFFFF; methods[i] = reader.CreateMethodDef_COMThread(rid, declaringType, reflectedType); } return(methods); }
protected override void FormatReturnValueMethodName(ITextColorWriter output, DmdMethodBase method, DmdPropertyInfo property) { const Formatters.TypeFormatterOptions options = Formatters.TypeFormatterOptions.IntrinsicTypeKeywords | Formatters.TypeFormatterOptions.Namespaces; var formatter = new Formatters.VisualBasic.VisualBasicTypeFormatter(output, options, null); formatter.Format(method.DeclaringType, null); output.Write(BoxedTextColor.Operator, "."); if ((object)property != null) { output.Write(MemberUtils.GetColor(property), Formatters.VisualBasic.VisualBasicTypeFormatter.GetFormattedIdentifier(property.Name)); output.Write(BoxedTextColor.Operator, "."); output.Write(BoxedTextColor.Keyword, "Get"); } else { output.Write(Formatters.TypeFormatterUtils.GetColor(method, canBeModule: true), Formatters.VisualBasic.VisualBasicTypeFormatter.GetFormattedIdentifier(method.Name)); } }
public static (DmdPropertyInfo property, AccessorKind kind) TryGetProperty(DmdMethodBase method) { if ((object)method == null) { return(null, AccessorKind.None); } foreach (var p in method.DeclaringType.Properties) { if ((object)method == p.GetMethod) { return(p, AccessorKind.Getter); } if ((object)method == p.SetMethod) { return(p, AccessorKind.Setter); } } return(null, AccessorKind.None); }
public static (DmdEventInfo @event, AccessorKind kind) TryGetEvent(DmdMethodBase method) { if ((object)method == null) { return(null, AccessorKind.None); } foreach (var e in method.DeclaringType.Events) { if ((object)method == e.AddMethod) { return(e, AccessorKind.Adder); } if ((object)method == e.RemoveMethod) { return(e, AccessorKind.Remover); } } return(null, AccessorKind.None); }
void WriteGenericArguments(DmdMethodBase method) { var genArgs = method.GetGenericArguments(); if (genArgs.Count == 0) { return; } OutputWrite(GenericsParenOpen, BoxedTextColor.Punctuation); for (int i = 0; i < genArgs.Count; i++) { if (i > 0) { WriteCommaSpace(); } FormatType(genArgs[i]); } OutputWrite(GenericsParenClose, BoxedTextColor.Punctuation); }
public override bool Call(bool isCallvirt, DmdMethodBase method, ILValue[] arguments, out ILValue returnValue) { switch (method.SpecialMethodKind) { case DmdSpecialMethodKind.Array_Get: returnValue = LoadArrayElement(GetZeroBasedIndex(arguments, arguments.Length)); return(returnValue != null); case DmdSpecialMethodKind.Array_Set: StoreArrayElement(GetZeroBasedIndex(arguments, arguments.Length - 1), arguments[arguments.Length - 1]); returnValue = null; return(true); case DmdSpecialMethodKind.Array_Address: returnValue = new ArrayElementAddress(runtime, this, GetZeroBasedIndex(arguments, arguments.Length)); return(true); } return(base.Call(isCallvirt, method, arguments, out returnValue)); }
MethodMirror GetMethodCore(DmdMethodBase method, MonoTypeLoader monoTypeLoader) { MethodMirror monoMethod; var mi = method as DmdMethodInfo; if ((object)mi != null && mi.IsConstructedGenericMethod) { if (toMonoMethod.TryGetValue(method, out monoMethod)) { return(monoMethod); } if (!engine.MonoVirtualMachine.Version.AtLeast(2, 24)) { throw new InvalidOperationException(); } monoMethod = TryGetMethodCore2(mi.GetGenericMethodDefinition(), monoTypeLoader); if (monoMethod != null) { var genArgs = mi.GetGenericArguments(); var monoGenArgs = new TypeMirror[genArgs.Count]; for (int i = 0; i < monoGenArgs.Length; i++) { monoGenArgs[i] = MonoDebugTypeCreator.GetType(engine, genArgs[i], monoTypeLoader); } monoMethod = monoMethod.MakeGenericMethod(monoGenArgs); toMonoMethod[method] = monoMethod; return(monoMethod); } } else { monoMethod = TryGetMethodCore2(method, monoTypeLoader); if (monoMethod != null) { return(monoMethod); } } throw new InvalidOperationException(); }
void Format(DmdMethodBase method, DmdEventInfo @event, AccessorKind accessorKind) { OutputWrite(Keyword_Event, DbgTextColor.Keyword); WriteSpace(); WriteAccessor(accessorKind); WriteToken(method); if (DeclaringTypes) { FormatType(@event.DeclaringType !); WritePeriod(); } WriteIdentifier(@event.Name, TypeFormatterUtils.GetColor(@event)); WriteToken(@event); WriteSpace(); OutputWrite(Keyword_As, DbgTextColor.Keyword); WriteSpace(); FormatType(@event.EventHandlerType); WriteOffset(); }
public static bool IsMatch(DmdMethodBase method, DmdBindingFlags bindingAttr) { var attr = DmdBindingFlags.Default; if (method.IsPublic) { attr |= DmdBindingFlags.Public; } else { attr |= DmdBindingFlags.NonPublic; } if (method.IsStatic) { attr |= DmdBindingFlags.Static; } else { attr |= DmdBindingFlags.Instance; } if ((object)method.ReflectedType != method.DeclaringType) { if (method.IsStatic) { if (method.IsPrivate) { return(false); } attr |= DmdBindingFlags.FlattenHierarchy; } else { if (!(method.IsVirtual || method.IsAbstract) && method.IsPrivate) { return(false); } } } return((attr & bindingAttr) == attr); }
void WriteGenericMethodArguments(IDbgTextWriter output, DmdMethodBase method, Formatters.VisualBasic.VisualBasicTypeFormatter typeFormatter) { var genArgs = method.GetGenericArguments(); if (genArgs.Count == 0) { return; } output.Write(DbgTextColor.Punctuation, GenericsParenOpen); output.Write(DbgTextColor.Keyword, Keyword_Of); output.Write(DbgTextColor.Text, " "); for (int i = 0; i < genArgs.Count; i++) { if (i > 0) { output.Write(DbgTextColor.Punctuation, ","); output.Write(DbgTextColor.Text, " "); } typeFormatter.Format(genArgs[i], null); } output.Write(DbgTextColor.Punctuation, GenericsParenClose); }
protected override void FormatReturnValueMethodName(ITextColorWriter output, DmdMethodBase method, DmdPropertyInfo property) { const Formatters.TypeFormatterOptions options = Formatters.TypeFormatterOptions.IntrinsicTypeKeywords | Formatters.TypeFormatterOptions.Namespaces; var formatter = new Formatters.CSharp.CSharpTypeFormatter(output, options, null); formatter.Format(method.DeclaringType, null); output.Write(BoxedTextColor.Operator, "."); if ((object)property != null) { output.Write(MemberUtils.GetColor(property), Formatters.CSharp.CSharpTypeFormatter.GetFormattedIdentifier(property.Name)); output.Write(BoxedTextColor.Operator, "."); output.Write(BoxedTextColor.Keyword, "get"); } else { var methodColor = MemberUtils.GetColor(method, canBeModule: false); if (TryGetMethodName(method.Name, out var containingMethodName, out var localFunctionName)) { output.Write(methodColor, Formatters.CSharp.CSharpTypeFormatter.GetFormattedIdentifier(containingMethodName)); output.Write(BoxedTextColor.Operator, "."); output.Write(methodColor, Formatters.CSharp.CSharpTypeFormatter.GetFormattedIdentifier(localFunctionName)); }
void EnableBreakpointCore(DbgModule module, DmdMethodBase method, DbgEngineBoundCodeBreakpoint ebp, DbgDotNetCodeLocation location) { debuggerThread.VerifyAccess(); if (ebp.BoundCodeBreakpoint.IsClosed) { return; } using (TempBreak()) { var info = CreateBreakpoint(method.Module, location.Module, location.Token, location.Offset); if (!ebp.BoundCodeBreakpoint.TryGetData(out BoundBreakpointData bpData)) { Debug.Assert(ebp.BoundCodeBreakpoint.IsClosed); return; } Debug.Assert(bpData.Breakpoint == null); bpData.Breakpoint = info.bp; if (bpData.Breakpoint != null) { bpData.Breakpoint.Tag = bpData; } ebp.UpdateMessage(info.error); } }
MethodMirror TryGetMethodCore2(DmdMethodBase method, MonoTypeLoader monoTypeLoader) { if (toMonoMethod.TryGetValue(method, out var monoMethod)) { return(monoMethod); } var monoType = MonoDebugTypeCreator.GetType(engine, method.ReflectedType, monoTypeLoader); var methodDeclType = method.ReflectedType; while (methodDeclType != method.DeclaringType) { methodDeclType = methodDeclType.BaseType; monoType = monoType.BaseType ?? MonoDebugTypeCreator.GetType(engine, method.AppDomain.System_Object, monoTypeLoader); } var monoMethods = monoType.GetMethods(); var methods = methodDeclType.DeclaredMethods; if (monoMethods.Length != methods.Count) { throw new InvalidOperationException(); } for (int i = 0; i < monoMethods.Length; i++) { Debug.Assert(methods[i].Name == monoMethods[i].Name); Debug.Assert(methods[i].GetMethodSignature().GetParameterTypes().Count == monoMethods[i].GetParameters().Length); toMonoMethod[methods[i]] = monoMethods[i]; } if (toMonoMethod.TryGetValue(method, out monoMethod)) { return(monoMethod); } return(null); }
public override bool CallStatic(DmdMethodBase method, ILValue[] arguments, out ILValue returnValue) => Call(null, false, method, arguments, out returnValue);
void WriteMethodParameterListCore(DmdMethodBase method, IList <DmdType> parameterTypes, string openParen, string closeParen, bool showParameterTypes, bool showParameterNames, bool showParameterValues) { if (!showParameterTypes && !showParameterNames && !showParameterValues) { return; } OutputWrite(openParen, BoxedTextColor.Punctuation); int baseIndex = method.IsStatic ? 0 : 1; var parameters = method.GetParameters(); for (int i = 0; i < parameterTypes.Count; i++) { if (i > 0) { WriteCommaSpace(); } var param = i < parameters.Count ? parameters[i] : null; bool needSpace = false; if (showParameterTypes) { needSpace = true; if (param?.IsDefined("System.ParamArrayAttribute", false) == true) { OutputWrite(Keyword_params, BoxedTextColor.Keyword); WriteSpace(); } var parameterType = parameterTypes[i]; WriteRefIfByRef(param); if (parameterType.IsByRef) { parameterType = parameterType.GetElementType(); } FormatType(parameterType); } if (showParameterNames) { if (needSpace) { WriteSpace(); } needSpace = true; if (!string.IsNullOrEmpty(param?.Name)) { WriteIdentifier(param.Name, BoxedTextColor.Parameter); } else { WriteIdentifier("A_" + (baseIndex + i).ToString(), BoxedTextColor.Parameter); } } if (showParameterValues) { needSpace = FormatValue((uint)(baseIndex + i), needSpace); } } OutputWrite(closeParen, BoxedTextColor.Punctuation); }
void WriteMethodParameterList(DmdMethodBase method, string openParen, string closeParen) => WriteMethodParameterListCore(method, GetAllMethodParameterTypes(method.GetMethodSignature()), openParen, closeParen, ParameterTypes, ParameterNames, ParameterValues);
/// <summary> /// Called before executing the method /// </summary> /// <param name="method">Method</param> /// <param name="body">Method body</param> public abstract void Initialize(DmdMethodBase method, DmdMethodBody body);
/// <summary> /// Calls a static method or returns false on failure /// </summary> /// <param name="method">Method to call</param> /// <param name="arguments">Method arguments</param> /// <param name="returnValue">Return value. It's ignored if the method returns <see cref="void"/></param> /// <returns></returns> public abstract bool CallStatic(DmdMethodBase method, ILValue[] arguments, out ILValue returnValue);
/// <summary> /// Creates a <see cref="RuntimeMethodHandle"/> value or returns null on failure /// </summary> /// <param name="method">Method</param> /// <returns></returns> public abstract ILValue CreateRuntimeMethodHandle(DmdMethodBase method);
internal bool CallInstance(DbgDotNetValue objValue, bool isCallvirt, DmdMethodBase method, ILValue[] arguments, out ILValue returnValue) => Call(objValue, isCallvirt, method, arguments, out returnValue);
public override void Initialize(DmdMethodBase method, DmdMethodBody body) { argumentsProvider.Initialize(context, frame, method, body, cancellationToken); localsProvider.Initialize(context, frame, method, body, cancellationToken); }
public override ILValue CreateRuntimeMethodHandle(DmdMethodBase method) { return(null); //TODO: }
public override bool Call(bool isCallvirt, DmdMethodBase method, ILValue[] arguments, out ILValue returnValue) => Collection[Index].Call(isCallvirt, method, arguments, out returnValue);