Avoid event printing dependency on debugged process
authorIgor Kulaychuk <i.kulaychuk@samsung.com>
Thu, 11 Jan 2018 22:17:49 +0000 (01:17 +0300)
committerIgor Kulaychuk <i.kulaychuk@samsung.com>
Thu, 11 Jan 2018 22:21:00 +0000 (01:21 +0300)
src/debug/netcoredbg/breakpoints.cpp
src/debug/netcoredbg/breakpoints.h
src/debug/netcoredbg/commands.cpp
src/debug/netcoredbg/debugger.h
src/debug/netcoredbg/main.cpp
src/debug/netcoredbg/protocol.h

index e7d8eb551ba86b21b7401efeb31132817b093ee7..ff7f492137ebeabeaec5da06a8529a0cbe06395f 100644 (file)
@@ -98,7 +98,7 @@ HRESULT GetCurrentBreakpoint(ICorDebugThread *pThread, Breakpoint &breakpoint)
     return E_FAIL;
 }
 
-HRESULT HitBreakpoint(ICorDebugThread *pThread, ULONG32 &id, ULONG32 &times)
+HRESULT HitBreakpoint(ICorDebugThread *pThread, Breakpoint &breakpoint)
 {
     HRESULT Status;
 
@@ -126,8 +126,8 @@ HRESULT HitBreakpoint(ICorDebugThread *pThread, ULONG32 &id, ULONG32 &times)
             b.linenum == sp.startLine &&
             b.enabled)
         {
-            id = b.id;
-            times = ++b.times;
+            ++b.times;
+            b.ToBreakpoint(breakpoint);
             return S_OK;
         }
     }
index e3e09fbdb6b0c89be6fc8a07511b224b42031959..226f54ebce038a5370cbc991abc73d08df2d4822 100644 (file)
@@ -8,5 +8,5 @@ void InsertExceptionBreakpoint(const std::string &name, Breakpoint &breakpoint);
 HRESULT GetCurrentBreakpoint(ICorDebugThread *pThread, Breakpoint &breakpoint);
 
 void DeleteAllBreakpoints();
-HRESULT HitBreakpoint(ICorDebugThread *pThread, ULONG32 &id, ULONG32 &times);
+HRESULT HitBreakpoint(ICorDebugThread *pThread, Breakpoint &breakpoint);
 void TryResolveBreakpointsForModule(ICorDebugModule *pModule);
index 7c0360f0b5e5628ec481b562fd5e05a0d8aae190..83f2b09be72d3a7403dd750cef5418c77beeff5c 100644 (file)
@@ -149,7 +149,7 @@ static HRESULT PrintBreakpoint(const Breakpoint &b, std::string &output)
     return Status;
 }
 
-HRESULT Debugger::EmitBreakpointEvent(BreakpointEvent event)
+void Debugger::EmitBreakpointEvent(BreakpointEvent event)
 {
     switch(event.reason)
     {
@@ -158,10 +158,10 @@ HRESULT Debugger::EmitBreakpointEvent(BreakpointEvent event)
             std::string output;
             PrintBreakpoint(event.breakpoint, output);
             Debugger::Printf("=breakpoint-modified,%s\n", output.c_str());
-            return S_OK;
+            return;
         }
         default:
-            return S_OK;
+            break;
     }
 }
 
@@ -346,36 +346,26 @@ static HRESULT ThreadInfoCommand(ICorDebugProcess *pProcess, const std::vector<s
     return S_OK;
 }
 
-HRESULT Debugger::EmitStoppedEvent(StoppedEvent event)
+void Debugger::EmitStoppedEvent(StoppedEvent event)
 {
     HRESULT Status;
-    ToRelease<ICorDebugThread> pThread;
-    IfFailRet(m_pProcess->GetThread(event.threadId, &pThread));
-
-    StackFrame stackFrame;
-    ToRelease<ICorDebugFrame> pFrame;
-    if (SUCCEEDED(pThread->GetActiveFrame(&pFrame)) && pFrame != nullptr)
-        GetFrameLocation(pFrame, stackFrame);
 
     std::string frameLocation;
-    PrintFrameLocation(stackFrame, frameLocation);
+    PrintFrameLocation(event.frame, frameLocation);
 
     switch(event.reason)
     {
         case StopBreakpoint:
         {
-            Breakpoint b;
-            IfFailRet(GetCurrentBreakpoint(pThread, b));
-
             Debugger::Printf("*stopped,reason=\"breakpoint-hit\",thread-id=\"%i\",stopped-threads=\"all\",bkptno=\"%u\",times=\"%u\",frame={%s}\n",
-                event.threadId, (unsigned int)b.id, (unsigned int)b.hitCount, frameLocation.c_str());
-            return S_OK;
+                event.threadId, (unsigned int)event.breakpoint.id, (unsigned int)event.breakpoint.hitCount, frameLocation.c_str());
+            return;
         }
         case StopStep:
         {
             Debugger::Printf("*stopped,reason=\"end-stepping-range\",thread-id=\"%i\",stopped-threads=\"all\",frame={%s}\n",
                 event.threadId, frameLocation.c_str());
-            return S_OK;
+            return;
         }
         case StopException:
         {
@@ -390,17 +380,16 @@ HRESULT Debugger::EmitStoppedEvent(StoppedEvent event)
                 frameLocation.c_str());
         }
         default:
-            return S_OK;
+            break;
     }
 }
 
-HRESULT Debugger::EmitExitedEvent(ExitedEvent event)
+void Debugger::EmitExitedEvent(ExitedEvent event)
 {
     Debugger::Printf("*stopped,reason=\"exited\",exit-code=\"%i\"\n", event.exitCode);
-    return S_OK;
 }
 
-HRESULT Debugger::EmitThreadEvent(ThreadEvent event)
+void Debugger::EmitThreadEvent(ThreadEvent event)
 {
     const char *reasonText = "";
     switch(event.reason)
@@ -413,10 +402,9 @@ HRESULT Debugger::EmitThreadEvent(ThreadEvent event)
             break;
     }
     Debugger::Printf("=%s,id=\"%i\"\n", reasonText, event.threadId);
-    return S_OK;
 }
 
-HRESULT Debugger::EmitOutputEvent(OutputEvent event)
+void Debugger::EmitOutputEvent(OutputEvent event)
 {
     if (event.source.empty())
         Debugger::Printf("=message,text=\"%s\",send-to=\"output-window\"\"\n",
@@ -425,8 +413,6 @@ HRESULT Debugger::EmitOutputEvent(OutputEvent event)
         Debugger::Printf("=message,text=\"%s\",send-to=\"output-window\",source=\"%s\"\n",
             Debugger::EscapeMIValue(event.output).c_str(),
             Debugger::EscapeMIValue(event.source).c_str());
-
-    return S_OK;
 }
 
 HRESULT Debugger::HandleCommand(std::string command,
index 545db064d560ed7b031e19f47cb996e8e2ce6c01..766b09cd109e3ce358858d26ababc7f1e71803fe 100644 (file)
@@ -54,13 +54,13 @@ class Debugger
                                const std::vector<std::string> &args,
                                std::string &output, StepType stepType);
 
-    HRESULT EmitStoppedEvent(StoppedEvent event);
-    HRESULT EmitExitedEvent(ExitedEvent event);
-    HRESULT EmitThreadEvent(ThreadEvent event);
-    HRESULT EmitOutputEvent(OutputEvent event);
+    static void EmitStoppedEvent(StoppedEvent event);
+    static void EmitExitedEvent(ExitedEvent event);
+    static void EmitThreadEvent(ThreadEvent event);
+    static void EmitOutputEvent(OutputEvent event);
 
 public:
-    static HRESULT EmitBreakpointEvent(BreakpointEvent event);
+    static void EmitBreakpointEvent(BreakpointEvent event);
 
     static bool IsJustMyCode() { return m_justMyCode; }
     static void SetJustMyCode(bool enable) { m_justMyCode = enable; }
index 0f8285eeb84f066fcbf7627b39ed8cd356850cf0..f0a33a6dac914ad274470e057c8bc5b56fcab676 100644 (file)
@@ -342,12 +342,15 @@ public:
             DWORD threadId = 0;
             pThread->GetID(&threadId);
 
-            ULONG32 id = 0;
-            ULONG32 times = 0;
-            HitBreakpoint(pThread, id, times);
+            StoppedEvent event(StopBreakpoint, threadId);
+            HitBreakpoint(pThread, event.breakpoint);
+
+            ToRelease<ICorDebugFrame> pFrame;
+            if (SUCCEEDED(pThread->GetActiveFrame(&pFrame)) && pFrame != nullptr)
+                GetFrameLocation(pFrame, event.frame);
 
             SetLastStoppedThread(pThread);
-            m_debugger->EmitStoppedEvent(StoppedEvent(StopBreakpoint, threadId));
+            m_debugger->EmitStoppedEvent(event);
 
             return S_OK;
         }
@@ -376,8 +379,11 @@ public:
                 DWORD threadId = 0;
                 pThread->GetID(&threadId);
 
+                StoppedEvent event(StopStep, threadId);
+                event.frame = stackFrame;
+
                 SetLastStoppedThread(pThread);
-                m_debugger->EmitStoppedEvent(StoppedEvent(StopStep, threadId));
+                m_debugger->EmitStoppedEvent(event);
             }
             return S_OK;
         }
@@ -400,6 +406,11 @@ public:
                 DWORD threadId = 0;
                 pThread->GetID(&threadId);
 
+                StackFrame stackFrame;
+                ToRelease<ICorDebugFrame> pFrame;
+                if (SUCCEEDED(pThread->GetActiveFrame(&pFrame)) && pFrame != nullptr)
+                    GetFrameLocation(pFrame, stackFrame);
+
                 SetLastStoppedThread(pThread);
 
                 std::string details = "An unhandled exception of type '" + excType + "' occurred in " + excModule;
@@ -410,6 +421,7 @@ public:
                     StoppedEvent event(StopException, threadId);
                     event.text = excType;
                     event.description = message.empty() ? details : message;
+                    event.frame = stackFrame;
                     m_debugger->EmitStoppedEvent(event);
                 };
 
index e06f0e536e7302fa71ce02bf3d44f15309109ef0..c7a49cbd21a5b538e3f53ddb569fd2f1ad608e94 100644 (file)
@@ -54,26 +54,6 @@ struct StackFrame
     StackFrame(uint64_t id, std::string name) : id(id), name(name) {}
 };
 
-enum StopReason
-{
-    StopStep,
-    StopBreakpoint,
-    StopException,
-    StopPause,
-    StopEntry
-};
-
-struct StoppedEvent
-{
-    StopReason reason;
-    std::string description;
-    int threadId;
-    std::string text;
-    bool allThreadsStopped;
-
-    StoppedEvent(StopReason reason, int threadId = 0) : reason(reason), threadId(threadId), allThreadsStopped(true) {}
-};
-
 struct Breakpoint
 {
     uint32_t id;
@@ -94,6 +74,29 @@ enum BreakpointReason
     BreakpointRemoved
 };
 
+enum StopReason
+{
+    StopStep,
+    StopBreakpoint,
+    StopException,
+    StopPause,
+    StopEntry
+};
+
+struct StoppedEvent
+{
+    StopReason reason;
+    std::string description;
+    int threadId;
+    std::string text;
+    bool allThreadsStopped;
+
+    StackFrame frame; // exposed for MI protocol
+    Breakpoint breakpoint; // exposed for MI protocol
+
+    StoppedEvent(StopReason reason, int threadId = 0) : reason(reason), threadId(threadId), allThreadsStopped(true) {}
+};
+
 struct BreakpointEvent
 {
     BreakpointReason reason;