[Lldb-commits] [lldb] 576105c - [lldb-vscode] stop read loop after termination

Walter Erquinigo via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 20 14:39:15 PDT 2020


Author: Walter Erquinigo
Date: 2020-03-20T14:38:49-07:00
New Revision: 576105c322b6b9cd48c82c8551be45707044a83d

URL: https://github.com/llvm/llvm-project/commit/576105c322b6b9cd48c82c8551be45707044a83d
DIFF: https://github.com/llvm/llvm-project/commit/576105c322b6b9cd48c82c8551be45707044a83d.diff

LOG: [lldb-vscode] stop read loop after termination

Summary:
On Linux, when executing lldb-vscode on a remote machine, lldb-vscode doesn't die after the debug session ends. It keeps trying to read JSON input to no avail.
This diff indicates lldb-vscode to stop reading after a termination event has been processed.

Reviewers: clayborg, aadsm, kusmour

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76314

Added: 
    

Modified: 
    lldb/test/API/tools/lldb-vscode/launch/TestVSCode_launch.py
    lldb/tools/lldb-vscode/lldb-vscode.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/test/API/tools/lldb-vscode/launch/TestVSCode_launch.py b/lldb/test/API/tools/lldb-vscode/launch/TestVSCode_launch.py
index b63170ee6b8c..0d20dd0987ac 100644
--- a/lldb/test/API/tools/lldb-vscode/launch/TestVSCode_launch.py
+++ b/lldb/test/API/tools/lldb-vscode/launch/TestVSCode_launch.py
@@ -9,6 +9,7 @@
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
 import lldbvscode_testcase
+import time
 import os
 
 
@@ -35,6 +36,31 @@ def test_default(self):
         self.assertTrue(program in lines[0],
                         "make sure program path is in first argument")
 
+    @skipIfWindows
+    @skipIfRemote
+    def test_termination(self):
+        '''
+            Tests the correct termination of lldb-vscode upon a 'disconnect'
+            request.
+        '''
+        self.create_debug_adaptor()
+        # The underlying lldb-vscode process must be alive
+        self.assertEqual(self.vscode.process.poll(), None)
+
+        # The lldb-vscode process should finish even though
+        # we didn't close the communication socket explicitly
+        self.vscode.request_disconnect()
+
+        # Wait until the underlying lldb-vscode process dies.
+        # We need to do this because the popen.wait function in python2.7
+        # doesn't have a timeout argument.
+        for _ in range(10):
+            time.sleep(1)
+            if self.vscode.process.poll() is not None:
+                break
+        # Check the return code
+        self.assertEqual(self.vscode.process.poll(), 0)
+
     @skipIfWindows
     @skipIfRemote
     def test_stopOnEntry(self):

diff  --git a/lldb/tools/lldb-vscode/lldb-vscode.cpp b/lldb/tools/lldb-vscode/lldb-vscode.cpp
index ff4a6af22af4..8c68dd0e7055 100644
--- a/lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ b/lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -2818,7 +2818,7 @@ int main(int argc, char *argv[]) {
   }
   auto request_handlers = GetRequestHandlers();
   uint32_t packet_idx = 0;
-  while (true) {
+  while (!g_vsc.sent_terminated_event) {
     std::string json = g_vsc.ReadJSON();
     if (json.empty())
       break;


        


More information about the lldb-commits mailing list