Exemplo 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);
                });
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Flush the runtime instance
 /// </summary>
 public void Flush()
 {
     _clrRuntime?.DacLibrary.DacPrivateInterface.Flush();
     _metadataMappingMemoryService?.Flush();
 }