Example #1
0
        private void Uninitialize(
            IntPtr self)
        {
            Trace.TraceInformation("HostServices.Uninitialize");
            try
            {
                DestroyTarget(self);

                if (DebuggerServices != null)
                {
                    DebuggerServices.Release();
                    DebuggerServices = null;
                }

                // Send shutdown event on exit
                OnShutdownEvent.Fire();

                // Release the host services wrapper
                Release();

                // Clear HostService instance
                Instance = null;
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
            }
        }
Example #2
0
        /// <summary>
        /// Create a target instance from IDataReader
        /// </summary>
        internal TargetFromDebuggerServices(DebuggerServices debuggerServices, IHost host)
            : base(host, dumpPath: null)
        {
            Debug.Assert(debuggerServices != null);

            HResult hr = debuggerServices.GetOperatingSystem(out DebuggerServices.OperatingSystem operatingSystem);

            Debug.Assert(hr == HResult.S_OK);
            OperatingSystem = operatingSystem switch
            {
                DebuggerServices.OperatingSystem.Windows => OSPlatform.Windows,
                DebuggerServices.OperatingSystem.Linux => OSPlatform.Linux,
                DebuggerServices.OperatingSystem.OSX => OSPlatform.OSX,
                _ => throw new PlatformNotSupportedException($"Operating system not supported: {operatingSystem}"),
            };

            hr = debuggerServices.GetDebuggeeType(out DEBUG_CLASS debugClass, out DEBUG_CLASS_QUALIFIER qualifier);
            Debug.Assert(hr == HResult.S_OK);
            if (qualifier >= DEBUG_CLASS_QUALIFIER.USER_WINDOWS_SMALL_DUMP)
            {
                IsDump = true;
            }

            hr = debuggerServices.GetExecutingProcessorType(out IMAGE_FILE_MACHINE type);
            if (hr == HResult.S_OK)
            {
                Architecture = type switch
                {
                    IMAGE_FILE_MACHINE.I386 => Architecture.X86,
                    IMAGE_FILE_MACHINE.ARM => Architecture.Arm,
                    IMAGE_FILE_MACHINE.THUMB => Architecture.Arm,
                    IMAGE_FILE_MACHINE.THUMB2 => Architecture.Arm,
                    IMAGE_FILE_MACHINE.AMD64 => Architecture.X64,
                    IMAGE_FILE_MACHINE.ARM64 => Architecture.Arm64,
                    _ => throw new PlatformNotSupportedException($"Machine type not supported: {type}"),
                };
            }
            else
            {
                throw new PlatformNotSupportedException($"GetExecutingProcessorType() FAILED {hr:X8}");
            }

            hr = debuggerServices.GetCurrentProcessId(out uint processId);
            if (hr == HResult.S_OK)
            {
                ProcessId = processId;
            }
            else
            {
                Trace.TraceError("GetCurrentThreadId() FAILED {0:X8}", hr);
            }

            // Add the thread, memory, and module services
            ServiceProvider.AddServiceFactory <IModuleService>(() => new ModuleServiceFromDebuggerServices(this, debuggerServices));
            ServiceProvider.AddServiceFactory <IThreadService>(() => new ThreadServiceFromDebuggerServices(this, debuggerServices));
            ServiceProvider.AddServiceFactory <IMemoryService>(() => new MemoryServiceFromDebuggerServices(this, debuggerServices));
        }
Example #3
0
        private void Uninitialize(
            IntPtr self)
        {
            Trace.TraceInformation("HostServices.Uninitialize");
            _hostWrapper.DestroyTarget();
            if (_target != null)
            {
                _target.Close();
                _target = null;
            }
            DebuggerServices.Release();
            DebuggerServices = null;

            // Send shutdown event on exit
            OnShutdownEvent.Fire();
        }
Example #4
0
        private void Uninitialize(
            IntPtr self)
        {
            Trace.TraceInformation("HostServices.Uninitialize");
            DestroyTarget(self);

            if (DebuggerServices != null)
            {
                DebuggerServices.Release();
                DebuggerServices = null;
            }

            // Send shutdown event on exit
            OnShutdownEvent.Fire();

            // Release the host services wrapper
            Release();
        }
        /// <summary>
        /// Memory service constructor
        /// </summary>
        /// <param name="target">target instance</param>
        /// <param name="debuggerServices">native debugger services</param>
        internal MemoryServiceFromDebuggerServices(ITarget target, DebuggerServices debuggerServices)
        {
            Debug.Assert(target != null);
            Debug.Assert(debuggerServices != null);
            _target           = target;
            _debuggerServices = debuggerServices;

            switch (target.Architecture)
            {
            case Architecture.X64:
            case Architecture.Arm64:
                PointerSize = 8;
                break;

            case Architecture.X86:
            case Architecture.Arm:
                PointerSize = 4;
                break;
            }
        }
 internal ModuleServiceFromDebuggerServices(ITarget target, DebuggerServices debuggerServices)
     : base(target)
 {
     Debug.Assert(debuggerServices != null);
     _debuggerServices = debuggerServices;
 }
Example #7
0
        private HResult RegisterDebuggerServices(
            IntPtr self,
            IntPtr iunk)
        {
            if (iunk == IntPtr.Zero || DebuggerServices != null)
            {
                return(HResult.E_FAIL);
            }
            // Create the wrapper for the host debugger services
            try
            {
                DebuggerServices = new DebuggerServices(iunk, HostType);
            }
            catch (InvalidCastException ex)
            {
                Trace.TraceError(ex.Message);
                return(HResult.E_NOINTERFACE);
            }
            try
            {
                var remoteMemoryService = new RemoteMemoryService(iunk);
                _serviceProvider.AddService <IRemoteMemoryService>(remoteMemoryService);
            }
            catch (InvalidCastException)
            {
            }
            HResult hr;

            try
            {
                var consoleService = new ConsoleServiceFromDebuggerServices(DebuggerServices);
                _serviceProvider.AddService <IConsoleService>(consoleService);
                _serviceProvider.AddServiceFactory <IThreadUnwindService>(() => new ThreadUnwindServiceFromDebuggerServices(DebuggerServices));
                Trace.TraceInformation("HostServices.RegisterDebuggerServices");

                // Add each extension command to the native debugger
                foreach ((string name, string help, IEnumerable <string> aliases) in _commandProcessor.Commands)
                {
                    hr = DebuggerServices.AddCommand(name, help, aliases);
                    if (hr != HResult.S_OK)
                    {
                        Trace.TraceWarning($"Cannot add extension command {hr:X8} {name} - {help}");
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                return(HResult.E_FAIL);
            }
            hr = DebuggerServices.GetSymbolPath(out string symbolPath);
            if (hr == HResult.S_OK)
            {
                if (!_symbolService.ParseSymbolPath(symbolPath))
                {
                    Trace.TraceError("ParseSymbolPath FAILED: {0}", symbolPath);
                }
            }
            else
            {
                Trace.TraceError("DebuggerServices.GetSymbolPath FAILED: {0:X8}", hr);
            }
            return(HResult.S_OK);
        }
Example #8
0
        /// <summary>
        /// Create a target instance from IDataReader
        /// </summary>
        internal TargetFromDebuggerServices(DebuggerServices debuggerServices, IHost host, int id)
            : base(host, id, dumpPath: null)
        {
            Debug.Assert(debuggerServices != null);

            HResult hr = debuggerServices.GetOperatingSystem(out DebuggerServices.OperatingSystem operatingSystem);

            Debug.Assert(hr == HResult.S_OK);
            OperatingSystem = operatingSystem switch
            {
                DebuggerServices.OperatingSystem.Windows => OSPlatform.Windows,
                DebuggerServices.OperatingSystem.Linux => OSPlatform.Linux,
                DebuggerServices.OperatingSystem.OSX => OSPlatform.OSX,
                _ => throw new PlatformNotSupportedException($"Operating system not supported: {operatingSystem}"),
            };

            hr = debuggerServices.GetDebuggeeType(out DEBUG_CLASS debugClass, out DEBUG_CLASS_QUALIFIER qualifier);
            Debug.Assert(hr == HResult.S_OK);
            if (qualifier >= DEBUG_CLASS_QUALIFIER.USER_WINDOWS_SMALL_DUMP)
            {
                IsDump = true;
            }

            hr = debuggerServices.GetExecutingProcessorType(out IMAGE_FILE_MACHINE type);
            if (hr == HResult.S_OK)
            {
                Architecture = type switch
                {
                    IMAGE_FILE_MACHINE.I386 => Architecture.X86,
                    IMAGE_FILE_MACHINE.ARM => Architecture.Arm,
                    IMAGE_FILE_MACHINE.THUMB => Architecture.Arm,
                    IMAGE_FILE_MACHINE.THUMB2 => Architecture.Arm,
                    IMAGE_FILE_MACHINE.AMD64 => Architecture.X64,
                    IMAGE_FILE_MACHINE.ARM64 => Architecture.Arm64,
                    _ => throw new PlatformNotSupportedException($"Machine type not supported: {type}"),
                };
            }
            else
            {
                throw new PlatformNotSupportedException($"GetExecutingProcessorType() FAILED {hr:X8}");
            }

            hr = debuggerServices.GetCurrentProcessId(out uint processId);
            if (hr == HResult.S_OK)
            {
                ProcessId = processId;
            }
            else
            {
                Trace.TraceError("GetCurrentThreadId() FAILED {0:X8}", hr);
            }

            // Add the thread, memory, and module services
            IMemoryService rawMemoryService = new MemoryServiceFromDebuggerServices(this, debuggerServices);

            ServiceProvider.AddServiceFactory <IModuleService>(() => new ModuleServiceFromDebuggerServices(this, rawMemoryService, debuggerServices));
            ServiceProvider.AddServiceFactory <IThreadService>(() => new ThreadServiceFromDebuggerServices(this, debuggerServices));
            ServiceProvider.AddServiceFactory <IMemoryService>(() => {
                Debug.Assert(Host.HostType != HostType.DotnetDump);
                IMemoryService memoryService = rawMemoryService;
                if (IsDump && Host.HostType == HostType.Lldb)
                {
                    // 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 (< 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).
                    return(new MetadataMappingMemoryService(this, memoryService));
                }
                return(memoryService);
            });
        }
 internal ModuleServiceFromDebuggerServices(ITarget target, IMemoryService rawMemoryService, DebuggerServices debuggerServices)
     : base(target, rawMemoryService)
 {
     Debug.Assert(debuggerServices != null);
     _debuggerServices = debuggerServices;
 }
Example #10
0
 public ConsoleServiceFromDebuggerServices(DebuggerServices debuggerServices)
 {
     _debuggerServices = debuggerServices;
 }
Example #11
0
 public ThreadUnwindServiceFromDebuggerServices(DebuggerServices debuggerServices)
 {
     _debuggerServices = debuggerServices;
 }
Example #12
0
 internal ContextServiceFromDebuggerServices(IHost host, DebuggerServices debuggerServices)
     : base(host)
 {
     Debug.Assert(debuggerServices != null);
     _debuggerServices = debuggerServices;
 }