From 3c3db32b50a6d7bf916efaa05f98cbb25e0a07c8 Mon Sep 17 00:00:00 2001 From: "Calvin A. Allen" Date: Mon, 22 Dec 2025 17:07:57 -0500 Subject: [PATCH] fix(debugger): only notify on actual breakpoint hits, not step operations Use IDebugBreakpointEvent2 instead of DBGMODE_Break to detect when a breakpoint is hit. This prevents the notification from firing on every step (F10/F11) operation. Fixes #2 --- .../DebuggerEvents.cs | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/CodingWithCalvin.BreakpointNotifier/DebuggerEvents.cs b/src/CodingWithCalvin.BreakpointNotifier/DebuggerEvents.cs index a099710..c82cb5c 100644 --- a/src/CodingWithCalvin.BreakpointNotifier/DebuggerEvents.cs +++ b/src/CodingWithCalvin.BreakpointNotifier/DebuggerEvents.cs @@ -1,12 +1,14 @@ -using System.Windows.Forms; +using System; +using System.Windows.Forms; using Microsoft; using Microsoft.VisualStudio; +using Microsoft.VisualStudio.Debugger.Interop; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; namespace CodingWithCalvin.BreakpointNotifier { - public sealed class DebuggerEvents : IVsDebuggerEvents + public sealed class DebuggerEvents : IVsDebuggerEvents, IDebugEventCallback2 { private DebuggerEvents() { @@ -16,6 +18,7 @@ private DebuggerEvents() ServiceProvider.GlobalProvider.GetService(typeof(IVsDebugger)); Assumes.Present(debugger); debugger.AdviseDebuggerEvents(this, out _); + debugger.AdviseDebugEventCallback(this); } public static DebuggerEvents Initialize() @@ -25,11 +28,23 @@ public static DebuggerEvents Initialize() public int OnModeChange(DBGMODE dbgmodeNew) { - switch (dbgmodeNew) + // No longer showing message here - we use IDebugEventCallback2 instead + // to specifically detect breakpoint hits vs. step operations + return VSConstants.S_OK; + } + + public int Event( + IDebugEngine2 pEngine, + IDebugProcess2 pProcess, + IDebugProgram2 pProgram, + IDebugThread2 pThread, + IDebugEvent2 pEvent, + ref Guid riidEvent, + uint dwAttrib) + { + if (pEvent is IDebugBreakpointEvent2) { - case DBGMODE.DBGMODE_Break: - MessageBox.Show("Breakpoint Hit!"); - break; + MessageBox.Show("Breakpoint Hit!"); } return VSConstants.S_OK;