public void InitNewDebugClientForThisThread() { // Reset our current thread and get a new IDebugClient for the current thread _myThread = Thread.CurrentThread; // Call CreateClient to get a thread-safe IDebugClient IntPtr newIDebugClientPtr; if (_createClientDelegate == null) { InitThreadSafeStuff(this.DebugClientForThreadInit); } if (_createClientDelegate == null) { throw new Exception("_createClientDelegate is null. Did thread Safe initialization fail?"); } int hr = _createClientDelegate(_debugClientPtr, out newIDebugClientPtr); if (FAILED(hr)) { throw new Exception("Failed to _createClientDelegate"); } IDebugClient newClient = null; if (newIDebugClientPtr != IntPtr.Zero) { newClient = (IDebugClient)Marshal.GetObjectForIUnknown(newIDebugClientPtr); Marshal.Release(newIDebugClientPtr); } _debugClient = newClient as IDebugClient5; }
public Debugger(IDebugClient5 client, IDebugControl control) { _client = client; _control = control; client.SetOutputCallbacks(this); }
/// <summary> /// Initializes a new instance of the <see cref="DebugEngineProxy" /> class. /// </summary> /// <param name="control">The control.</param> /// <param name="client">The client.</param> /// <param name="registers">The registers.</param> /// <param name="systemObjects">The system objects.</param> /// <param name="debugDataSpaces">The debug data spaces.</param> public DebugEngineProxy(IDebugControl6 control, IDebugClient5 client, IDebugRegisters2 registers, IDebugSystemObjects systemObjects, IDebugDataSpaces debugDataSpaces, IExecuteWrapper executeWrapper) { Control = control; Client = client; Registers = registers; Dataspaces = debugDataSpaces; ExecuteWrapper = executeWrapper; RegisterEngine = new RegisterEngine(); // todo: inject MemoryEngine = new MemoryEngine(); SystemObjects = systemObjects; Is32Bit = Regex.Match(ExecuteWrapper.Execute("!peb"), @"PEB at (?<peb>[a-fA-F0-9]+)").Groups["peb"].Value .Length == 8; }
private DebugClient(object client, TaskScheduler scheduler) { _scheduler = scheduler; Client = (IDebugClient5)client; Control = (IDebugControl7)client; DataSpaces = (IDebugDataSpaces4)client; SystemObjects = (IDebugSystemObjects2)client; Symbols = (IDebugSymbols5)client; Advanced = (IDebugAdvanced3)client; Client.SetEventCallbacksWide(this).ThrowIfFailed(); Client.SetOutputCallbacksWide(this).ThrowIfFailed(); Control.AddEngineOptions(DEBUG_ENGOPT.INITIAL_BREAK); }
internal static void INIT_API() { LastHR = HRESULT.S_OK; if (client == null) { try { client = (IDebugClient5)CreateIDebugClient(); control = (IDebugControl6)client; } catch { LastHR = HRESULT.E_UNEXPECTED; } } }
/// <summary> /// Create a new DebugUtilities instance /// </summary> /// <param name="debugClient"></param> /// <param name="threadSafe">Make interfaces thread-neutral. Likely performance penalty involved.</param> public DebugUtilities(IDebugClient debugClient, bool threadSafe = false) { _myThread = Thread.CurrentThread; _threadSafe = threadSafe; if (_threadSafe == true) { InitThreadSafeStuff(debugClient); // This has to be done before casting.. } _debugClient = debugClient as IDebugClient5; if (_staticClient5 == null) { _staticClient5 = _debugClient; } if (_dmlCapable == null || _dmlCapable.Value == false) { _dmlCapable = IsDebuggerDMLCapable(); } _preferDML = PreferDML(); }
public UserDebugger() { Guid guid = new Guid("27fe5639-8407-4f47-8364-ee118fb08ac8"); object obj = null; int hr = DebugCreate(ref guid, out obj); if (hr < 0) { Console.WriteLine("SourceFix: Unable to acquire client interface"); return; } _client = obj as IDebugClient5; _control = _client as IDebugControl4; _debugDataSpace = _client as IDebugDataSpaces; _client.SetOutputCallbacks(this); _client.SetEventCallbacksWide(this); }
public void Dispose() { if (_debugDataSpace != null) { Marshal.ReleaseComObject(_debugDataSpace); _debugDataSpace = null; } if (_control != null) { Marshal.ReleaseComObject(_control); _control = null; } if (_client != null) { Marshal.ReleaseComObject(_client); _client = null; } }
/// <summary> /// Create a new DebugUtilities instance /// </summary> /// <param name="debugClient"></param> public DebugUtilities(out IDebugClient debugClient) { _myThread = Thread.CurrentThread; int hr = _staticClient5.CreateClient(out debugClient); if (FAILED(hr)) { OutputVerboseLine("DebugUtilities Failed creating a new debug client for execution: {0:x8}", hr); debugClient = null; return; } _releaseClient = true; _threadSafe = false; _debugClient = debugClient as IDebugClient5; if (_dmlCapable == null || _dmlCapable.Value == false) { _dmlCapable = IsDebuggerDMLCapable(); } _preferDML = PreferDML(); }
public WindowsDebugEngine(string winDbgPath) { logger.Debug("WindowsDebugEngine"); object obj = null; Guid clsid = CLSID(typeof(IDebugClient5)); this.winDbgPath = winDbgPath; hDll = LoadWin32Library(Path.Combine(winDbgPath, "dbgeng.dll")); hProc = GetProcAddress(hDll, "DebugCreate"); DebugCreate debugCreate = (DebugCreate)Marshal.GetDelegateForFunctionPointer(hProc, typeof(DebugCreate)); if (debugCreate(ref clsid, out obj) != 0) { Debugger.Break(); } dbgClient = (IDebugClient5)obj; dbgControl = (IDebugControl4)obj; dbgSymbols = (IDebugSymbols3)obj; dbgSystemObjects = (IDebugSystemObjects)obj; // Reset events loadModules.Reset(); exitProcess.Reset(); handlingException.Reset(); handledException.Reset(); exitDebugger.Reset(); // Reset output output = new StringBuilder(); dbgSymbols.SetSymbolPath(@"SRV*http://msdl.microsoft.com/download/symbols"); dbgClient.SetOutputCallbacks(new OutputCallbacks(this)); dbgClient.SetEventCallbacks(new EventCallbacks(this)); }
public Debugger LaunchProcess(string commandLine, string workingDirectory) { IDebugClient5 client = CreateIDebugClient(); IDebugControl control = (IDebugControl)client; if (string.IsNullOrEmpty(workingDirectory)) { workingDirectory = Environment.CurrentDirectory; } string env = GetEnvironment(); DEBUG_CREATE_PROCESS_OPTIONS options = new DEBUG_CREATE_PROCESS_OPTIONS(); options.CreateFlags = (DEBUG_CREATE_PROCESS)1; int hr = client.CreateProcessAndAttach2(0, commandLine, ref options, (uint)Marshal.SizeOf(typeof(DEBUG_CREATE_PROCESS_OPTIONS)), workingDirectory, env, 0, DEBUG_ATTACH.DEFAULT); if (hr < 0) { throw new Exception(Debugger.GetExceptionString("IDebugClient::CreateProcessAndAttach2", hr)); } Debugger debugger = new Debugger(client, control); hr = client.SetEventCallbacks(debugger); if (hr < 0) { throw new Exception(Debugger.GetExceptionString("IDebugClient::SetEventCallbacks", hr)); } hr = client.SetOutputCallbacks(debugger); if (hr < 0) { throw new Exception(Debugger.GetExceptionString("IDebugClient::SetOutputCallbacks", hr)); } return(debugger); }
/// <summary> /// Initializes the API. /// </summary> /// <param name="log">The log.</param> internal static void InitApi(ILog log = null) { LastHR = HRESULT.S_OK; if (client != null) { return; } try { log?.Debug("Client did not exist. Creating a new client and associated interfaces."); client = (IDebugClient5)CreateIDebugClient(); control = (IDebugControl6)client; registers = (IDebugRegisters2)client; symbols = (IDebugSymbols5)client; systemObjects = (IDebugSystemObjects)client; debugDataSpaces = (IDebugDataSpaces)client; } catch (Exception e) { log?.Fatal("Unable to create debug client. Are you missing DLLs?"); log?.Fatal(e); LastHR = HRESULT.E_UNEXPECTED; } }
private DataTarget CreateDbgEngDataTargetImpl() { if (String.IsNullOrEmpty(DumpFile)) { throw new InvalidOperationException("DbgEng targets can be created only for dump files at this point."); } var target = DataTarget.LoadCrashDump(DumpFile, CrashDumpReader.DbgEng); target.SymbolLocator.SymbolPath = SymbolPath; ((IDebugSymbols)target.DebuggerInterface).SetSymbolPath(SymbolPath); if (DisplayDiagnosticInformation) { ((IDebugControl)target.DebuggerInterface).Execute(DEBUG_OUTCTL.NOT_LOGGED, "!sym noisy", DEBUG_EXECUTE.NOT_LOGGED); } ((IDebugControl)target.DebuggerInterface).Execute(DEBUG_OUTCTL.NOT_LOGGED, ".reload", DEBUG_EXECUTE.NOT_LOGGED); var outputCallbacks = new OutputCallbacks(this); IDebugClient5 client = (IDebugClient5)target.DebuggerInterface; HR.Verify(client.SetOutputCallbacksWide(outputCallbacks)); return(target); }