Exemplo n.º 1
0
 /// <summary>
 /// Loads and initializes the SOS module.
 /// </summary>
 private void Initialize()
 {
     if (_sosLibrary == IntPtr.Zero)
     {
         string sos;
         if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
         {
             sos = "sos.dll";
         }
         else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
         {
             sos = "libsos.so";
         }
         else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
         {
             sos = "libsos.dylib";
         }
         else
         {
             throw new PlatformNotSupportedException($"Unsupported operating system: {RuntimeInformation.OSDescription}");
         }
         string sosPath = Path.Combine(SOSPath, sos);
         try
         {
             _sosLibrary = Microsoft.Diagnostics.Runtime.DataTarget.PlatformFunctions.LoadLibrary(sosPath);
         }
         catch (DllNotFoundException ex)
         {
             // This is a workaround for the Microsoft SDK docker images. Can fail when LoadLibrary uses libdl.so to load the SOS module.
             if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
             {
                 throw new DllNotFoundException("Problem loading SOS module. Try installing libc6-dev (apt-get install libc6-dev) to work around this problem.", ex);
             }
             else
             {
                 throw;
             }
         }
         if (_sosLibrary == IntPtr.Zero)
         {
             throw new FileNotFoundException($"SOS module {sosPath} not found");
         }
         var initializeFunc = SOSHost.GetDelegateFunction <SOSInitializeDelegate>(_sosLibrary, SOSInitialize);
         if (initializeFunc == null)
         {
             throw new EntryPointNotFoundException($"Can not find SOS module initialization function: {SOSInitialize}");
         }
         int result = initializeFunc(_hostWrapper.IHost);
         if (result != 0)
         {
             throw new InvalidOperationException($"SOS initialization FAILED 0x{result:X8}");
         }
         Trace.TraceInformation("SOS initialized: sosPath '{0}'", sosPath);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Shutdown/clean up the native SOS module.
        /// </summary>
        private void Uninitialize()
        {
            Trace.TraceInformation("SOSHost: Uninitialize");
            if (_sosLibrary != IntPtr.Zero)
            {
                var uninitializeFunc = SOSHost.GetDelegateFunction <SOSUninitializeDelegate>(_sosLibrary, SOSUninitialize);
                uninitializeFunc?.Invoke();

                Microsoft.Diagnostics.Runtime.DataTarget.PlatformFunctions.FreeLibrary(_sosLibrary);
                _sosLibrary = IntPtr.Zero;
            }
            _hostWrapper.Release();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Execute a SOS command.
        /// </summary>
        /// <param name="client">client interface</param>
        /// <param name="command">just the command name</param>
        /// <param name="arguments">the command arguments and options</param>
        public void ExecuteCommand(IntPtr client, string command, string arguments)
        {
            Debug.Assert(_sosLibrary != IntPtr.Zero);

            var commandFunc = SOSHost.GetDelegateFunction <SOSCommandDelegate>(_sosLibrary, command);

            if (commandFunc == null)
            {
                throw new EntryPointNotFoundException($"Can not find SOS command: {command}");
            }
            int result = commandFunc(client, arguments ?? "");

            if (result != HResult.S_OK)
            {
                Trace.TraceError($"SOS command FAILED 0x{result:X8}");
            }
        }