public static ClrObject GetStaticFldValue(this ClrRuntime runtime, [NotNull] ClrType clrType,
                                                  [NotNull] string fieldName)
        {
            Assert.ArgumentNotNull(clrType, "typeName");
            Assert.ArgumentNotNullOrEmpty(fieldName, "fieldName");

            ClrStaticField fld = clrType.GetStaticFieldByName(fieldName);

            if (fld == null)
            {
                throw new MissingFieldException(clrType.Name, fieldName);
            }

            var domains = runtime.AppDomains.ToArray();

            if ((domains == null) || (domains.Length == 0))
            {
                throw new ArgumentException("No domains are found inside runtime!");
            }

            ulong?resultAddress = (from domain in domains
                                   where !string.IsNullOrWhiteSpace(domain.Name)
                                   where !domain.Name.Contains("Default") && fld.IsInitialized(domain)
                                   select(ulong?) fld.GetValue(domain)).FirstOrDefault();

            return(resultAddress.HasValue ? (new ClrObject(resultAddress.Value, clrType.Heap))
        : ClrObject.NullObject);
        }
Example #2
0
 public override IEnumerable <ObjectInfo> EnumerateTimerTasks()
 {
     if (fieldSQueue.IsInitialized(domain))
     {
         var timeQueue = (ulong)fieldSQueue.GetValue(domain);
         for (ulong timer = (ulong)fieldTimers.GetValue(timeQueue); timer != 0; timer = (ulong)fieldNext.GetValue(timer))
         {
             var state = (ulong)fieldState.GetValue(timer);
             if (state != 0)
             {
                 var typeState = heap.GetObjectType(state);
                 if (typeState == typeDelayPromise)
                 {
                     var continuation = (ulong)fieldTaskContinuationObject.GetValue(state);
                     var target       = (ulong)fieldDelegateTarget.GetValue(continuation);
                     var stateMachine = (ulong)fieldStateMachine.GetValue(target);
                     yield return(new ObjectInfo {
                         Address = stateMachine, Type = heap.GetObjectType(stateMachine)
                     });
                 }
             }
         }
     }
 }
 /// <summary>
 ///     Returns whether this static field has been initialized in a particular AppDomain
 ///     or not.  If a static variable has not been initialized, then its class constructor
 ///     may have not been run yet.  Calling GetFieldValue on an uninitialized static
 ///     will result in returning either NULL or a value of 0.
 /// </summary>
 /// <param name="appDomain">The AppDomain to see if the variable has been initialized.</param>
 /// <returns>
 ///     True if the field has been initialized (even if initialized to NULL or a default
 ///     value), false if the runtime has not initialized this variable.
 /// </returns>
 /// <inheritdoc />
 public bool IsInitialized(IClrAppDomain appDomain) =>
 StaticField.IsInitialized((appDomain as ClrAppDomainAdapter)?.AppDomain);