Ejemplo n.º 1
0
        public Runtime(ITarget target, IRuntimeService runtimeService, ClrInfo clrInfo, int id)
        {
            Trace.TraceInformation($"Creating runtime #{id} {clrInfo.Flavor} {clrInfo}");
            _target         = target;
            _runtimeService = runtimeService;
            _clrInfo        = clrInfo;
            Id = id;

            RuntimeType = RuntimeType.Unknown;
            if (clrInfo.Flavor == ClrFlavor.Core)
            {
                RuntimeType = RuntimeType.NetCore;
            }
            else if (clrInfo.Flavor == ClrFlavor.Desktop)
            {
                RuntimeType = RuntimeType.Desktop;
            }
            RuntimeModule = target.Services.GetService <IModuleService>().GetModuleFromBaseAddress(clrInfo.ModuleInfo.ImageBase);

            ServiceProvider = new ServiceProvider();
            ServiceProvider.AddService <ClrInfo>(clrInfo);
            ServiceProvider.AddServiceFactoryWithNoCaching <ClrRuntime>(() => CreateRuntime());

            target.OnFlushEvent.Register(() => {
                _clrRuntime?.DacLibrary.DacPrivateInterface.Flush();
                _metadataMappingMemoryService?.Flush();
            });

            // This is a special memory service that maps the managed assemblies' metadata into
            // the address space. The lldb debugger returns zero's (instead of failing the memory
            // read) for missing pages in core dumps that older (less than 5.0) createdumps generate
            // so it needs this special metadata mapping memory service. dotnet-dump needs this logic
            // for clrstack -i (uses ICorDebug data targets).
            if (target.IsDump &&
                (target.OperatingSystem != OSPlatform.Windows) &&
                (target.Host.HostType == HostType.Lldb ||
                 target.Host.HostType == HostType.DotnetDump))
            {
                ServiceProvider.AddServiceFactoryWithNoCaching <IMemoryService>(() => {
                    if (_metadataMappingMemoryService == null)
                    {
                        _metadataMappingMemoryService = new MetadataMappingMemoryService(this, MemoryService, SymbolService);
                        target.DisposeOnClose(SymbolService.OnChangeEvent.Register(_metadataMappingMemoryService.Flush));
                    }
                    return(_metadataMappingMemoryService);
                });
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a target instance from IDataReader
        /// </summary>
        /// <param name="dataReader">IDataReader</param>
        /// <param name="targetOS">target operating system</param>
        /// <param name="host">the host instance</param>
        /// <param name="id">target id</param>
        /// <param name="dumpPath">path of dump for this target</param>
        public TargetFromDataReader(IDataReader dataReader, OSPlatform targetOS, IHost host, int id, string dumpPath)
            : base(host, id, dumpPath)
        {
            _dataReader = dataReader;

            OperatingSystem = targetOS;
            IsDump          = true;
            OnFlushEvent.Register(dataReader.FlushCachedData);

            Architecture = dataReader.Architecture switch
            {
                Microsoft.Diagnostics.Runtime.Architecture.Amd64 => Architecture.X64,
                Microsoft.Diagnostics.Runtime.Architecture.X86 => Architecture.X86,
                Microsoft.Diagnostics.Runtime.Architecture.Arm => Architecture.Arm,
                Microsoft.Diagnostics.Runtime.Architecture.Arm64 => Architecture.Arm64,
                _ => throw new PlatformNotSupportedException($"{dataReader.Architecture}"),
            };

            if (dataReader.ProcessId != -1)
            {
                ProcessId = (uint)dataReader.ProcessId;
            }

            // Add the thread, memory, and module services
            IMemoryService rawMemoryService = new MemoryServiceFromDataReader(_dataReader);

            ServiceProvider.AddServiceFactory <IThreadService>(() => new ThreadServiceFromDataReader(this, _dataReader));
            ServiceProvider.AddServiceFactory <IModuleService>(() => new ModuleServiceFromDataReader(this, rawMemoryService, _dataReader));
            ServiceProvider.AddServiceFactory <IMemoryService>(() => {
                IMemoryService memoryService = rawMemoryService;
                if (IsDump)
                {
                    memoryService = new ImageMappingMemoryService(this, memoryService);
                    // Any dump created for a MacOS target does not have managed assemblies in the module service so
                    // we need to use the metadata mapping memory service to make sure the metadata is available.
                    if (targetOS == OSPlatform.OSX)
                    {
                        memoryService = new MetadataMappingMemoryService(this, memoryService);
                    }
                }
                return(memoryService);
            });
        }
 internal MetadataRegion(MetadataMappingMemoryService memoryService, ClrModule module)
 {
     _memoryService = memoryService;
     _module        = module;
 }