2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System ;
5
+ using System . Collections . Generic ;
5
6
using Microsoft . Diagnostics . DataContractReader . Data ;
6
7
7
8
namespace Microsoft . Diagnostics . DataContractReader . Contracts ;
@@ -23,6 +24,71 @@ ModuleHandle ILoader.GetModuleHandle(TargetPointer modulePointer)
23
24
return new ModuleHandle ( modulePointer ) ;
24
25
}
25
26
27
+ List < ModuleHandle > ILoader . GetAssemblies ( TargetPointer appDomain , AssemblyIterationFlags iterationFlags )
28
+ {
29
+ if ( appDomain == TargetPointer . Null )
30
+ throw new ArgumentNullException ( nameof ( appDomain ) ) ;
31
+
32
+ Data . AppDomain domain = _target . ProcessedData . GetOrAdd < Data . AppDomain > ( appDomain ) ;
33
+ ArrayListBase arrayList = _target . ProcessedData . GetOrAdd < ArrayListBase > ( domain . DomainAssemblyList ) ;
34
+
35
+ List < ModuleHandle > handles = [ ] ;
36
+ foreach ( TargetPointer pAssembly in arrayList . Elements )
37
+ {
38
+ TargetPointer assemblyAddr = _target . ReadPointer ( pAssembly ) ;
39
+ Data . Assembly assembly = _target . ProcessedData . GetOrAdd < Data . Assembly > ( assemblyAddr ) ;
40
+
41
+ // following logic is based on AppDomain::AssemblyIterator::Next_Unlocked in appdomain.cpp
42
+
43
+ if ( assembly . IsError && ! iterationFlags . HasFlag ( AssemblyIterationFlags . IncludeFailedToLoad ) )
44
+ continue ; // skip assemblies with errors
45
+
46
+ if ( ( assembly . NotifyFlags & 0x1 /*PROFILER_NOTIFIED*/ ) != 0 && ! iterationFlags . HasFlag ( AssemblyIterationFlags . IncludeAvailableToProfilers ) )
47
+ {
48
+ // The assembly has reached the state at which we would notify profilers,
49
+ // and we're supposed to include such assemblies in the enumeration. So
50
+ // don't reject it (i.e., noop here, and don't bother with the rest of
51
+ // the load status checks). Check for this first, since
52
+ // IncludeAvailableToProfilers contains some loaded AND loading
53
+ // assemblies.
54
+ }
55
+ else if ( assembly . IsLoaded )
56
+ {
57
+ if ( ! iterationFlags . HasFlag ( AssemblyIterationFlags . IncludeLoaded ) )
58
+ continue ; // skip loaded assemblies
59
+ }
60
+ else
61
+ {
62
+ if ( ! iterationFlags . HasFlag ( AssemblyIterationFlags . IncludeLoading ) )
63
+ continue ; // skip loading assemblies
64
+ }
65
+
66
+ // Next, reject assemblies whose execution status is
67
+ // not to be included in the enumeration
68
+
69
+ if ( ! iterationFlags . HasFlag ( AssemblyIterationFlags . IncludeExecution ) )
70
+ continue ; // skip assemblies with execution status
71
+
72
+ if ( assembly . IsCollectible != 0 )
73
+ {
74
+ if ( iterationFlags . HasFlag ( AssemblyIterationFlags . ExcludeCollectible ) )
75
+ continue ; // skip collectible assemblies
76
+
77
+ Module module = _target . ProcessedData . GetOrAdd < Data . Module > ( assembly . Module ) ;
78
+ if ( ( ( ModuleFlags ) module . Flags ) . HasFlag ( ModuleFlags . Tenured ) )
79
+ continue ; // skip tenured modules
80
+
81
+ LoaderAllocator loaderAllocator = _target . ProcessedData . GetOrAdd < Data . LoaderAllocator > ( module . LoaderAllocator ) ;
82
+ if ( ! loaderAllocator . IsAlive && ! iterationFlags . HasFlag ( AssemblyIterationFlags . IncludeCollected ) )
83
+ continue ; // skip collected assemblies
84
+ }
85
+
86
+ handles . Add ( new ( assembly . Module ) ) ;
87
+ }
88
+
89
+ return handles ;
90
+ }
91
+
26
92
TargetPointer ILoader . GetRootAssembly ( )
27
93
{
28
94
TargetPointer appDomainPointer = _target . ReadGlobalPointer ( Constants . Globals . AppDomain ) ;
@@ -192,4 +258,11 @@ bool ILoader.IsCollectible(ModuleHandle handle)
192
258
Data . Assembly la = _target . ProcessedData . GetOrAdd < Data . Assembly > ( assembly ) ;
193
259
return la . IsCollectible != 0 ;
194
260
}
261
+
262
+ bool ILoader . IsAssemblyLoaded ( ModuleHandle handle )
263
+ {
264
+ Data . Module module = _target . ProcessedData . GetOrAdd < Data . Module > ( handle . Address ) ;
265
+ Data . Assembly assembly = _target . ProcessedData . GetOrAdd < Data . Assembly > ( module . Assembly ) ;
266
+ return assembly . IsLoaded ;
267
+ }
195
268
}
0 commit comments