Skip to content

Commit 3c3db32

Browse files
committed
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
1 parent 291a892 commit 3c3db32

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/CodingWithCalvin.BreakpointNotifier/DebuggerEvents.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
using System.Windows.Forms;
1+
using System;
2+
using System.Windows.Forms;
23
using Microsoft;
34
using Microsoft.VisualStudio;
5+
using Microsoft.VisualStudio.Debugger.Interop;
46
using Microsoft.VisualStudio.Shell;
57
using Microsoft.VisualStudio.Shell.Interop;
68

79
namespace CodingWithCalvin.BreakpointNotifier
810
{
9-
public sealed class DebuggerEvents : IVsDebuggerEvents
11+
public sealed class DebuggerEvents : IVsDebuggerEvents, IDebugEventCallback2
1012
{
1113
private DebuggerEvents()
1214
{
@@ -16,6 +18,7 @@ private DebuggerEvents()
1618
ServiceProvider.GlobalProvider.GetService(typeof(IVsDebugger));
1719
Assumes.Present(debugger);
1820
debugger.AdviseDebuggerEvents(this, out _);
21+
debugger.AdviseDebugEventCallback(this);
1922
}
2023

2124
public static DebuggerEvents Initialize()
@@ -25,11 +28,23 @@ public static DebuggerEvents Initialize()
2528

2629
public int OnModeChange(DBGMODE dbgmodeNew)
2730
{
28-
switch (dbgmodeNew)
31+
// No longer showing message here - we use IDebugEventCallback2 instead
32+
// to specifically detect breakpoint hits vs. step operations
33+
return VSConstants.S_OK;
34+
}
35+
36+
public int Event(
37+
IDebugEngine2 pEngine,
38+
IDebugProcess2 pProcess,
39+
IDebugProgram2 pProgram,
40+
IDebugThread2 pThread,
41+
IDebugEvent2 pEvent,
42+
ref Guid riidEvent,
43+
uint dwAttrib)
44+
{
45+
if (pEvent is IDebugBreakpointEvent2)
2946
{
30-
case DBGMODE.DBGMODE_Break:
31-
MessageBox.Show("Breakpoint Hit!");
32-
break;
47+
MessageBox.Show("Breakpoint Hit!");
3348
}
3449

3550
return VSConstants.S_OK;

0 commit comments

Comments
 (0)