protected override void ProcessRecord() { base.ProcessRecord(); using (var disposer = new ExceptionGuard(Debugger.HandleDbgEngOutput(_ConsumeLine))) { // Failure to load an extension should be a terminating error. // // Because the only reason to load an extension is so that you can call // commands in it. And if you didn't load it, then none of those commands // will work. string providerPath = PathOrName; if (providerPath.IndexOfAny(sm_dirSeparators) >= 0) { // We support PS paths. // // (we don't want to call GetUnresolvedProviderPathFromPSPath if it's // just a bare name, else PS will interpret that as a relative path, // which would be wrong) providerPath = GetUnresolvedProviderPathFromPSPath(PathOrName); } MsgLoop.Prepare(); var t = Debugger.AddExtensionAsync(providerPath); t.ContinueWith((x) => { disposer.Dispose(); SignalDone(); }); MsgLoop.Run(); var elr = Util.Await(t); // in case it threw if (!string.IsNullOrEmpty(elr.LoadOutput)) { SafeWriteObject(elr.LoadOutput); } SafeWriteVerbose("Loaded extension: {0}", PathOrName); } // end using( disposer ) } // end ProcessRecord()
// We used to only load DbgShellExt once, but the problem with that is that // somebody might have unloaded it later (whether explicitly or by killing and // restarting the target) (and if DbgShell.exe is the host, then the static flag // keeping track of it would not get cleared away with appdomain unload). private void _LoadDbgShellExt() { if (String.IsNullOrEmpty(sm_dbgShellExtPath)) { string dir = Path.GetDirectoryName( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); sm_dbgShellExtPath = Path.Combine(dir, "DbgShellExt.dll"); } // We don't want to print the load output since we're alredy in // DbgShell anyway. var elr = Util.Await(Debugger.AddExtensionAsync(sm_dbgShellExtPath)); if (elr.hExt == 0) { Util.Fail("We should always be able to load DbgShellExt."); throw new DbgProviderException(Util.Sprintf("Attempt to load DbgShellExt.dll failed. Path used: {0}.", sm_dbgShellExtPath), "FailedToAutoLoadDbgShellExt", ErrorCategory.OpenError, sm_dbgShellExtPath); } } // end _LoadDbgShellExt()