Refactor printing thread star/exit events
authorIgor Kulaychuk <i.kulaychuk@samsung.com>
Thu, 11 Jan 2018 21:19:14 +0000 (00:19 +0300)
committerIgor Kulaychuk <i.kulaychuk@samsung.com>
Thu, 11 Jan 2018 21:48:20 +0000 (00:48 +0300)
src/debug/netcoredbg/commands.cpp
src/debug/netcoredbg/debugger.h
src/debug/netcoredbg/main.cpp
src/debug/netcoredbg/protocol.h

index d382bc5..86aa5e8 100644 (file)
@@ -400,6 +400,22 @@ HRESULT Debugger::EmitExitedEvent(ExitedEvent event)
     return S_OK;
 }
 
+HRESULT Debugger::EmitThreadEvent(ThreadEvent event)
+{
+    const char *reasonText = "";
+    switch(event.reason)
+    {
+        case ThreadStarted:
+            reasonText = "thread-created";
+            break;
+        case ThreadExited:
+            reasonText = "thread-exited";
+            break;
+    }
+    Debugger::Printf("=%s,id=\"%i\"\n", reasonText, event.threadId);
+    return S_OK;
+}
+
 HRESULT Debugger::HandleCommand(std::string command,
                                 const std::vector<std::string> &args,
                                 std::string &output)
index 62615f6..2632ca2 100644 (file)
@@ -56,6 +56,7 @@ class Debugger
 
     HRESULT EmitStoppedEvent(StoppedEvent event);
     HRESULT EmitExitedEvent(ExitedEvent event);
+    HRESULT EmitThreadEvent(ThreadEvent event);
 
 public:
     static HRESULT EmitBreakpointEvent(BreakpointEvent event);
index b882b2f..c3f8620 100644 (file)
@@ -501,7 +501,7 @@ public:
         {
             DWORD threadId = 0;
             thread->GetID(&threadId);
-            Debugger::Printf("=thread-created,id=\"%i\"\n", (int)threadId);
+            m_debugger->EmitThreadEvent(ThreadEvent(ThreadStarted, threadId));
             pAppDomain->Continue(0);
             return S_OK;
         }
@@ -511,7 +511,10 @@ public:
             /* [in] */ ICorDebugThread *thread)
         {
             NotifyEvalComplete(thread, nullptr);
-            HandleEvent(pAppDomain, "ExitThread");
+            DWORD threadId = 0;
+            thread->GetID(&threadId);
+            m_debugger->EmitThreadEvent(ThreadEvent(ThreadExited, threadId));
+            pAppDomain->Continue(0);
             return S_OK;
         }
 
index 7321278..78f4011 100644 (file)
@@ -108,3 +108,17 @@ struct ExitedEvent
 
     ExitedEvent(int exitCode) : exitCode(exitCode) {}
 };
+
+enum ThreadReason
+{
+    ThreadStarted,
+    ThreadExited
+};
+
+struct ThreadEvent
+{
+    ThreadReason reason;
+    int threadId;
+
+    ThreadEvent(ThreadReason reason, int threadId) : reason(reason), threadId(threadId) {}
+};