Fix a bug: no stop at Debugger.Break() call.
authorKirill Frolov <k.frolov@samsung.com>
Thu, 1 Oct 2020 12:04:03 +0000 (15:04 +0300)
committerAlexander Soldatov/Platform Lab /SRR/Staff Engineer/Samsung Electronics <soldatov.a@samsung.com>
Tue, 24 Nov 2020 16:03:13 +0000 (19:03 +0300)
This commit fixes issue #264.

It is expected, if the program running under debuggers control, call to
System.Diagnostics.Debugger.Break() should stop the program (as if the
breakpoint is set).

src/debug/netcoredbg/cliprotocol.cpp
src/debug/netcoredbg/manageddebugger.cpp
src/debug/netcoredbg/miprotocol.cpp
src/debug/netcoredbg/protocol.h
src/debug/netcoredbg/vscodeprotocol.cpp

index e42b20d52f7ebdcb4eca6ba82d22d30377adf789..80132ee2dede21908cee6e6f032379305cc877af 100644 (file)
@@ -287,6 +287,12 @@ void CLIProtocol::EmitStoppedEvent(StoppedEvent event)
                 int(event.threadId), frameLocation.c_str());
             break;
         }
+        case StopBreak:
+        {
+            printf("\nstopped, reason: Debugger.Break, thread id: %i, stopped threads: all, frame={%s\n}\n",
+                  int(event.threadId), frameLocation.c_str());
+            break;
+        }
         default:
             return;
     }
index 402a6f080d29c333e4e2a495e30bb38b83ef4440..2473fb272b137be7eb11f8469cfb254e0e828fb1 100644 (file)
@@ -596,7 +596,22 @@ public:
             /* [in] */ ICorDebugThread *thread)
         {
             LogFuncEntry();
-            return E_NOTIMPL;
+            ThreadId threadId(getThreadId(thread));
+
+            m_debugger.SetLastStoppedThread(thread);
+
+            StoppedEvent event(StopBreak, threadId);
+
+            ToRelease<ICorDebugFrame> pFrame;
+            if (SUCCEEDED(thread->GetActiveFrame(&pFrame)) && pFrame != nullptr)
+            {
+                StackFrame stackFrame;
+                if (m_debugger.GetFrameLocation(pFrame, threadId, FrameLevel{0}, stackFrame) == S_OK)
+                    event.frame = stackFrame;
+            }
+
+            m_debugger.m_protocol->EmitStoppedEvent(event);
+            return S_OK;
         }
 
         virtual HRESULT STDMETHODCALLTYPE Exception(
index f9776ebcef424ab856ba2d22071c08b74608e370..b916c32ae7353f4936aa164e52e27b18e1af60f6 100644 (file)
@@ -553,6 +553,12 @@ void MIProtocol::EmitStoppedEvent(StoppedEvent event)
                 int(event.threadId), frameLocation.c_str());
             break;
         }
+        case StopBreak:
+        {
+            MIProtocol::Printf("*stopped,reason=\"Debugger.Break\",thread-id=\"%i\",stopped-threads=\"all\",frame={%s}\n",
+                int(event.threadId), frameLocation.c_str());
+            break;
+        }
         default:
             return;
     }
index c8a132cf7b9b9e10af62f8bb6dd3ec4637649ad4..21485988cfb4d73d8fbe47b9d241096e71b152f3 100644 (file)
@@ -247,7 +247,8 @@ enum StopReason
     StopBreakpoint,
     StopException,
     StopPause,
-    StopEntry
+    StopEntry,
+    StopBreak
 };
 
 struct StoppedEvent
index cddca70fba26db34dd39df42151fcfdeab083ecd..db797348f7b63cac927edcad70a6664f6c135d44 100644 (file)
@@ -158,6 +158,9 @@ void VSCodeProtocol::EmitStoppedEvent(StoppedEvent event)
         case StopEntry:
             body["reason"] = "entry";
             break;
+        case StopBreak:
+            body["reason"] = "Debugger.Break";
+            break;
     }
 
     body["description"] = event.description;