diff --git a/src/CxbxDebugger/Debugger/Debugger.cs b/src/CxbxDebugger/Debugger/Debugger.cs index c4f955bb1..d62cea98c 100644 --- a/src/CxbxDebugger/Debugger/Debugger.cs +++ b/src/CxbxDebugger/Debugger/Debugger.cs @@ -46,6 +46,7 @@ namespace CxbxDebugger KernelProvider KernelSymbolProvider; bool bContinue = true; + WinDebug.CONTINUE_STATUS ContinueStatus = WinDebug.CONTINUE_STATUS.DBG_CONTINUE; private void Init() { @@ -436,9 +437,18 @@ namespace CxbxDebugger { Thread.UpdateContext(); + bool OverrideContinue = bContinue; + foreach (IDebuggerExceptionEvents Event in ExceptionEvents) { - Event.OnAccessViolation(Thread, DebugInfo.ExceptionRecord.ExceptionAddress); + OverrideContinue |= Event.OnAccessViolation(Thread, DebugInfo.ExceptionRecord.ExceptionAddress); + } + + // Attempt to skip this exception if requested + if (OverrideContinue) + { + bContinue = true; + ContinueStatus = WinDebug.CONTINUE_STATUS.DBG_EXCEPTION_NOT_HANDLED; } } } @@ -527,8 +537,7 @@ namespace CxbxDebugger public void RunThreaded() { WinDebug.DEBUG_EVENT DbgEvt = new WinDebug.DEBUG_EVENT(); - - WinDebug.CONTINUE_STATUS ContinueStatus = WinDebug.CONTINUE_STATUS.DBG_CONTINUE; + ContinueStatus = WinDebug.CONTINUE_STATUS.DBG_CONTINUE; foreach (IDebuggerGeneralEvents Event in GeneralEvents) { @@ -586,6 +595,7 @@ namespace CxbxDebugger // TODO: Stop doing this once we raise an exception WinDebug.NativeMethods.ContinueDebugEvent(DbgEvt.dwProcessId, DbgEvt.dwThreadId, ContinueStatus); + ContinueStatus = WinDebug.CONTINUE_STATUS.DBG_CONTINUE; } State = RunState.Ended; diff --git a/src/CxbxDebugger/Debugger/DebuggerEventInterfaces.cs b/src/CxbxDebugger/Debugger/DebuggerEventInterfaces.cs index 1a6dfa321..25ae9f6a8 100644 --- a/src/CxbxDebugger/Debugger/DebuggerEventInterfaces.cs +++ b/src/CxbxDebugger/Debugger/DebuggerEventInterfaces.cs @@ -36,7 +36,7 @@ namespace CxbxDebugger public interface IDebuggerExceptionEvents { - void OnAccessViolation(DebuggerThread Thread, IntPtr Address); + bool OnAccessViolation(DebuggerThread Thread, IntPtr Address); } public interface IDebuggerFileEvents diff --git a/src/CxbxDebugger/Form1.cs b/src/CxbxDebugger/Form1.cs index bd739d76a..6765bb707 100644 --- a/src/CxbxDebugger/Form1.cs +++ b/src/CxbxDebugger/Form1.cs @@ -150,6 +150,11 @@ namespace CxbxDebugger } } + private bool DebugAsk(string Message) + { + return MessageBox.Show(Message, "Cxbx Debugger", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes; + } + private void SetDebugProcessActive(bool Active) { if (InvokeRequired) @@ -272,9 +277,15 @@ namespace CxbxDebugger frm.DebugLog(string.Format("OutputDebugString \"{0}\"", Message)); } - public void OnAccessViolation(DebuggerThread Thread, IntPtr Address) + public bool OnAccessViolation(DebuggerThread Thread, IntPtr Address) { - string ProcessName = Path.GetFileName(Thread.OwningProcess.Path); + string ProcessName = "??"; + + var Module = frm.DebuggerInst.ResolveModule((uint)Address); + if( Module != null ) + { + ProcessName = Path.GetFileName(Module.Path); + } // TODO Include GetLastError string string ExceptionMessage = string.Format("Access violation thrown in {0} 0x{1:X8}", ProcessName, (uint)Address); @@ -283,6 +294,8 @@ namespace CxbxDebugger // Already suspended at this point, so we can rebuild the callstack list frm.PopulateThreadList(frm.cbThreads.Items, Thread); + + return frm.DebugAsk(ExceptionMessage + "\nTry to skip this error?"); } public void OnFileOpened(DebuggerMessages.FileOpened Info)