Exemplo n.º 1
0
        public string Execute(string cmd)
        {
            DEBUG_OUTPUT mask = _outputMask;

            _output.Clear();
            _outputMask = DEBUG_OUTPUT.NORMAL | DEBUG_OUTPUT.SYMBOLS | DEBUG_OUTPUT.ERROR | DEBUG_OUTPUT.WARNING | DEBUG_OUTPUT.DEBUGGEE;

            string result = null;

            try
            {
                int hr = _control.Execute(DEBUG_OUTCTL.ALL_CLIENTS, cmd, DEBUG_EXECUTE.DEFAULT);
                if (hr < 0)
                {
                    _output.Append(string.Format("Command encountered an error.  HRESULT={0:X8}", hr));
                }

                result = _output.ToString();
            }
            finally
            {
                _outputMask = mask;
                _output.Clear();
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Executes the specified command on the debug client
        /// </summary>
        /// <param name="command">The command to run.</param>
        /// <returns>The result of the command</returns>
        /// <exception cref="COMException">Error executing " + command</exception>
        /// <example>!runaway</example>
        /// <example>!dumpheap -stat</example>
        /// <example>!dlk</example>
        public string Execute(string command, TimeSpan?waitTimeout = null)
        {
            try
            {
                if (waitTimeout.HasValue)
                {
                    if (!ResetEvent.WaitOne(waitTimeout.Value))
                    {
                        throw new TimeoutException($"Command {command} did not get a chance to use the proxy before its timeout of {waitTimeout} expired");
                    }
                }
                else
                {
                    ResetEvent.WaitOne();
                }

                Builder.Clear();
                Log.Information("Executing {Command}", command);
                var hr = Control.Execute(DEBUG_OUTCTL.ALL_CLIENTS, command, DEBUG_EXECUTE.NOT_LOGGED);
                return(Builder.ToString());
            }
            catch (Exception e)
            {
                Log.Error(e, "Error executing {Command}", command);
                throw new COMException("Error executing " + command, e);
            }
            finally
            {
                ResetEvent.Set();
            }
        }
Exemplo n.º 3
0
 public string Execute(IDebugClient Client, IDebugControl Control, string Command)
 {
     try
     {
         Clear();
         Client.SetOutputMask(SupportedMasks);
         Client.SetOutputCallbacks(this);
         //Application.DoEvents();
         //DEBUG_STATUS status;
         //Control.GetExecutionStatus(out status);
         //DebugApi.WriteLine("Execution status {0}", status.ToString());
         Control.Execute(DEBUG_OUTCTL.THIS_CLIENT |
                         DEBUG_OUTCTL.NOT_LOGGED, Command, DEBUG_EXECUTE.NOT_LOGGED |
                         DEBUG_EXECUTE.NO_REPEAT);
         //int res = 0;
         //do
         //{
         //    res = Control.WaitForEvent(DEBUG_WAIT.DEFAULT, 10000);
         //    if(res == 1) WinApi.SetStatusBarMessage("10 seconds elapsed");
         //    //DebugApi.DebugWriteLine("10 seconds elapsed");
         //} while (res == 1  /* ResultCom.S_FALSE */);
     }
     finally
     {
         Client.SetOutputCallbacks(null);
     }
     return(Text);
 }
Exemplo n.º 4
0
        /// <summary>
        ///     Executes the specified command.
        /// </summary>
        /// <param name="cmd">The command.</param>
        /// <returns>System.String.</returns>
        public virtual string Execute(string cmd)
        {
            lock (_builder)
            {
                _builder.Clear();
            }

            var hr = _control.Execute(DEBUG_OUTCTL.THIS_CLIENT, cmd, DEBUG_EXECUTE.NOT_LOGGED);

            lock (_builder)
            {
                return(_builder.ToString());
            }
        }
Exemplo n.º 5
0
        public string Execute(string cmd, DebugOutputCallback callback = null)
        {
            HResult hr;
            IDebugOutputCallbacks origCallback;
            var sb = new StringBuilder();

            lock (executeLock)
            {
                hr = client.GetOutputCallbacks(out origCallback);
                if (!hr.IsOK)
                {
                    origCallback = null;
                }

                if (null == callback)
                {
                    callback = (m, t) =>
                    {
                        sb.Append(t);
                        return(0);
                    }
                }
                ;

                hr = client.SetOutputCallbacks(new DebugOutputCallbacks(callback));
                if (!hr.IsOK)
                {
                    sb.AppendLine(string.Format("SetOutputCallbacks failed. HRESULT={0:x}.", hr));
                }
                else
                {
                    hr = control.Execute(DEBUG_OUTCTL.THIS_CLIENT, cmd, DEBUG_EXECUTE.DEFAULT);
                    if (!hr.IsOK)
                    {
                        sb.AppendLine(string.Format("Command encountered an error. HRESULT={0:x}.", hr));
                    }
                }

                if (origCallback != null)
                {
                    client.SetOutputCallbacks(origCallback);
                }
            }

            return(sb.ToString());
        }
    }
Exemplo n.º 6
0
        /// <summary>
        ///     Executes the specified command.
        /// </summary>
        /// <param name="cmd">The command.</param>
        /// <returns>System.String.</returns>
        public string Execute(string cmd)
        {
            lock (_builder)
            {
                _builder.Clear();
            }

            var hr = _control.Execute(DEBUG_OUTCTL.THIS_CLIENT, cmd, DEBUG_EXECUTE.NOT_LOGGED);

            Debug.Assert(hr == 0);
            //todo:  Something with hr, it may be an error legitimately.

            lock (_builder)
            {
                return(_builder.ToString());
            }
        }
Exemplo n.º 7
0
            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}");
            }
Exemplo n.º 8
0
 public int StepOut()
 {
     return(_control.Execute(DEBUG_OUTCTL.THIS_CLIENT, _stepOutCommand, DEBUG_EXECUTE.DEFAULT));
 }