/// <summary> /// all debug events end up here /// </summary> /// <param name="ea"></param> private void debugEngine_OnDbgEvent(DbgCallbackEventArgs ea) { switch (ea.DebugEvent.dwDebugEventCode) { case DbgEventCode.Exception: Console.WriteLine("exception at 0x" + ea.DebugEvent.Exception.ExceptionRecord.ExceptionAddress.ToString("X") + " in thread: 0x" + ea.DebugEvent.dwThreadId.ToString("X") + " code: 0x" + ea.DebugEvent.Exception.ExceptionRecord.ExceptionCode.ToString("X")); if (continueAfterException_) { ea.ContinueMethod = DbgContinueMethod.Continue; } else { ea.ContinueMethod = DbgContinueMethod.ExceptionNotHandled; } //uint addr = (uint)ea.DebugEvent.Exception.ExceptionRecord.ExceptionAddress.ToInt32(); //addr -= 4; //IntPtr written; //byte[] buf = new byte[12]; //ReadProcessMemory(debugEngine_.ProcessInfo.hProcess, (IntPtr)addr, buf, 12, out written); //Console.WriteLine("memory dump:"); //for (int i = 0; i < 12; ++i) //{ // Console.WriteLine("[0x" + addr.ToString("X") + "] " + buf[i].ToString("X")); // ++addr; //} break; case DbgEventCode.ProcessExited: CodeCoverageFinished(new CoverageFinishedEventArgs(activeRecording_)); break; case DbgEventCode.LoadDLL: if (!addRuntimeModule(ea.DebugEvent.LoadDll.hFile, ea.DebugEvent.LoadDll.lpBaseOfDll) && verbose_) { string modulePath = getRuntimePath(ea.DebugEvent.LoadDll.hFile, ea.DebugEvent.LoadDll.lpBaseOfDll); NonRelevantModuleLoaded(new ModuleLoadedEventArgs(modulePath, (uint)ea.DebugEvent.LoadDll.lpBaseOfDll)); } break; case DbgEventCode.ProcessCreated: // search for matching module of the main process addRuntimeModule(ea.DebugEvent.CreateProcessInfo.hFile, ea.DebugEvent.CreateProcessInfo.lpBaseOfImage); //// process executable is always the first module //exeName_ = Path.GetFileName(activeRecording_.Modules[0].Path); exeName_ = getRuntimePath(ea.DebugEvent.CreateProcessInfo.hFile, ea.DebugEvent.CreateProcessInfo.lpBaseOfImage); break; default: break; } }
private void codeCoverage_CodeCoverageDbgEvent(DbgCallbackEventArgs e) { switch (e.DebugEvent.dwDebugEventCode) { case DbgEventCode.LoadDLL: try { log("Loaded DLL from: " + codeCoverage_.getRuntimePath(e.DebugEvent.LoadDll.hFile, e.DebugEvent.LoadDll.lpBaseOfDll) + " at 0x" + e.DebugEvent.LoadDll.lpBaseOfDll.ToString("X")); } catch (Exception) { log("Warning: unable to resolve path of loaded DLL at 0x" + e.DebugEvent.LoadDll.lpBaseOfDll.ToString("X")); } break; case DbgEventCode.ProcessExited: log("Debuggee exited"); break; case DbgEventCode.Exception: switch (e.DebugEvent.Exception.ExceptionRecord.ExceptionCode) { case DbgExceptionCode.AccessViolation: log("access violation debug event!"); break; case DbgExceptionCode.BreakPoint: log("breakpoint debug event!"); break; default: log("other exception!"); break; } break; case DbgEventCode.ProcessCreated: log("Created proces at 0x" + e.DebugEvent.CreateProcessInfo.lpBaseOfImage.ToString("X")); break; default: log("other debug event!"); break; } }
/// <summary> /// all debug events end up here /// </summary> /// <param name="ea"></param> private void debugEngine_OnDbgEvent(DbgCallbackEventArgs ea) { switch (ea.DebugEvent.dwDebugEventCode) { case DbgEventCode.Exception: Console.WriteLine("exception at 0x" + ea.DebugEvent.Exception.ExceptionRecord.ExceptionAddress.ToString("X") + " in thread: 0x" + ea.DebugEvent.dwThreadId.ToString("X") + " code: 0x" + ea.DebugEvent.Exception.ExceptionRecord.ExceptionCode.ToString("X")); if (continueAfterException_) ea.ContinueMethod = DbgContinueMethod.Continue; else ea.ContinueMethod = DbgContinueMethod.ExceptionNotHandled; //uint addr = (uint)ea.DebugEvent.Exception.ExceptionRecord.ExceptionAddress.ToInt32(); //addr -= 4; //IntPtr written; //byte[] buf = new byte[12]; //ReadProcessMemory(debugEngine_.ProcessInfo.hProcess, (IntPtr)addr, buf, 12, out written); //Console.WriteLine("memory dump:"); //for (int i = 0; i < 12; ++i) //{ // Console.WriteLine("[0x" + addr.ToString("X") + "] " + buf[i].ToString("X")); // ++addr; //} break; case DbgEventCode.ProcessExited: CodeCoverageFinished(new CoverageFinishedEventArgs(activeRecording_)); break; case DbgEventCode.LoadDLL: if (!addRuntimeModule(ea.DebugEvent.LoadDll.hFile, ea.DebugEvent.LoadDll.lpBaseOfDll) && verbose_) { string modulePath = getRuntimePath(ea.DebugEvent.LoadDll.hFile, ea.DebugEvent.LoadDll.lpBaseOfDll); NonRelevantModuleLoaded(new ModuleLoadedEventArgs(modulePath, (uint)ea.DebugEvent.LoadDll.lpBaseOfDll)); } break; case DbgEventCode.ProcessCreated: // search for matching module of the main process addRuntimeModule(ea.DebugEvent.CreateProcessInfo.hFile, ea.DebugEvent.CreateProcessInfo.lpBaseOfImage); //// process executable is always the first module //exeName_ = Path.GetFileName(activeRecording_.Modules[0].Path); exeName_ = getRuntimePath(ea.DebugEvent.CreateProcessInfo.hFile, ea.DebugEvent.CreateProcessInfo.lpBaseOfImage); break; default: break; } }
/// <summary> /// one of our breakpoints was hit /// </summary> /// <param name="ea"></param> private void debugEngine_OnBreakPoint(DbgCallbackEventArgs ea) { activeRecording_.addHit((uint)ea.DebugEvent.Exception.ExceptionRecord.ExceptionAddress); Console.WriteLine("BP hit at 0x" + ea.DebugEvent.Exception.ExceptionRecord.ExceptionAddress.ToString("X") + " in thread: 0x" + ea.DebugEvent.dwThreadId.ToString("X")); }