コード例 #1
0
        /// <summary>
        /// This is the main managed entry point that the native hosting code calls. It needs to be a single function
        /// and is restricted to just a string parameter because host APIs (i.e. desktop clr) have this narrow interface.
        /// </summary>
        /// <param name="extensionPath">Path and filename of native extensions to callback</param>
        /// <returns>hresult</returns>
        public static int Initialize(
            [MarshalAs(UnmanagedType.LPStr)] string extensionPath)
        {
            IntPtr extensionLibrary = default;

            try
            {
                extensionLibrary = DataTarget.PlatformFunctions.LoadLibrary(extensionPath);
            }
            catch (Exception ex) when(ex is DllNotFoundException || ex is BadImageFormatException)
            {
            }
            if (extensionLibrary == default)
            {
                return(HResult.E_FAIL);
            }
            var initialializeCallback = SOSHost.GetDelegateFunction <InitializeCallbackDelegate>(extensionLibrary, "InitializeHostServices");

            if (initialializeCallback == null)
            {
                return(HResult.E_FAIL);
            }
            Instance = new HostServices();
            return(initialializeCallback(Instance.IHostServices));
        }
コード例 #2
0
ファイル: TestDbgEng.cs プロジェクト: mikem8361/diagnostics
            internal DbgEngController(string dbgengPath, string dumpPath, string sosPath)
            {
                Trace.TraceInformation($"DbgEngController: {dbgengPath} {dumpPath} {sosPath}");
                _converter = new CharToLineConverter((text) => {
                    Trace.TraceInformation(text);
                });
                IntPtr dbgengLibrary = DataTarget.PlatformFunctions.LoadLibrary(dbgengPath);
                var    debugCreate   = SOSHost.GetDelegateFunction <DebugCreateDelegate>(dbgengLibrary, "DebugCreate");

                if (debugCreate == null)
                {
                    throw new DiagnosticsException($"DebugCreate export not found");
                }
                Guid    iid = _iidClient;
                HResult hr  = debugCreate(ref iid, out object client);

                if (hr != HResult.S_OK)
                {
                    throw new DiagnosticsException($"DebugCreate FAILED {hr:X8}");
                }
                Client  = (IDebugClient)client;
                Control = (IDebugControl)client;
                Symbols = (IDebugSymbols2)client;

                hr = Client.SetOutputCallbacks(this);
                if (hr != HResult.S_OK)
                {
                    throw new DiagnosticsException($"SetOutputCallbacks FAILED {hr:X8}");
                }

                // Automatically enable/adjust symbol server support. Override the default cache path so
                // the cache isn't created in the debugger binaries .nuget package cache directory.
                string cachePath = Path.Combine(Environment.GetEnvironmentVariable("PROGRAMDATA"), "dbg", "sym");
                string sympath   = $"{Path.GetDirectoryName(dumpPath)};cache*{cachePath};SRV*https://msdl.microsoft.com/download/symbols";

                hr = Symbols.SetSymbolPath(sympath);
                if (hr != HResult.S_OK)
                {
                    Trace.TraceError($"SetSymbolPath({sympath}) FAILED {hr:X8}");
                }

                // Load dump file
                hr = Client.OpenDumpFile(dumpPath);
                if (hr != HResult.S_OK)
                {
                    throw new DiagnosticsException($"OpenDumpFile({dumpPath} FAILED {hr:X8}");
                }
                ProcessEvents();

                // Load the sos extensions
                hr = Control.Execute(DEBUG_OUTCTL.ALL_CLIENTS, $".load {sosPath}", DEBUG_EXECUTE.DEFAULT);
                if (hr != HResult.S_OK)
                {
                    throw new DiagnosticsException($"Loading {sosPath} FAILED {hr:X8}");
                }

                // Initialize the extension host
                hr = HostServices.Initialize(sosPath);
                if (hr != HResult.S_OK)
                {
                    throw new DiagnosticsException($"HostServices.Initialize({sosPath}) FAILED {hr:X8}");
                }

                var symbolService = Host.Services.GetService <ISymbolService>();

                Trace.TraceInformation($"SymbolService: {symbolService}");
            }