[Lldb-commits] [PATCH] D147805: [lldb-vscode] Fix two issues with runInTerminal test.

Jorge Gorbe Moya via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Apr 7 12:48:17 PDT 2023


jgorbe created this revision.
jgorbe added reviewers: clayborg, wallace.
jgorbe added a project: LLDB.
Herald added subscribers: JDevlieghere, krytarowski.
Herald added a project: All.
jgorbe requested review of this revision.

With ptrace_scope = 1 the kernel only allows tracing descendants of a process.
When using runInTerminal, the target process is not launched by the debugger,
so we need to modify `LaunchRunInTerminal` to explicitly allow tracing.
This should fix a problem reported in https://reviews.llvm.org/D84974#3903716

Also, remove a special case from the `launch` method in the lldbvscode_testcase
test harness. The existing test was using stopOnEntry, so the first stop didn't
happen at the expected breakpoint unless the harness did configurationDone
first.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147805

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
  lldb/test/API/tools/lldb-vscode/runInTerminal/TestVSCode_runInTerminal.py
  lldb/tools/lldb-vscode/lldb-vscode.cpp


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===================================================================
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -32,6 +32,10 @@
 #include <unistd.h>
 #endif
 
+#if defined(__linux__)
+#include <sys/prctl.h>
+#endif
+
 #include <algorithm>
 #include <chrono>
 #include <fstream>
@@ -3146,6 +3150,14 @@
   llvm::errs() << "runInTerminal is only supported on POSIX systems\n";
   exit(EXIT_FAILURE);
 #else
+
+  // On Linux with the Yama security module enabled, a process can only attach
+  // to its descendants by default. In the runInTerminal case the target
+  // process is launched by the client so we need to allow tracing explicitly.
+#if defined(__linux__)
+  (void)prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0);
+#endif
+
   RunInTerminalLauncherCommChannel comm_channel(comm_file);
   if (llvm::Error err = comm_channel.NotifyPid()) {
     llvm::errs() << llvm::toString(std::move(err)) << "\n";
Index: lldb/test/API/tools/lldb-vscode/runInTerminal/TestVSCode_runInTerminal.py
===================================================================
--- lldb/test/API/tools/lldb-vscode/runInTerminal/TestVSCode_runInTerminal.py
+++ lldb/test/API/tools/lldb-vscode/runInTerminal/TestVSCode_runInTerminal.py
@@ -57,8 +57,7 @@
         program = self.getBuildArtifact("a.out")
         source = 'main.c'
         self.build_and_launch(
-            program, stopOnEntry=True, runInTerminal=True, args=["foobar"],
-            env=["FOO=bar"])
+            program, runInTerminal=True, args=["foobar"], env=["FOO=bar"])
 
         breakpoint_line = line_number(source, '// breakpoint')
 
@@ -88,7 +87,7 @@
             return
         self.build_and_create_debug_adaptor()
         response = self.launch(
-            "INVALIDPROGRAM", stopOnEntry=True, runInTerminal=True, args=["foobar"], env=["FOO=bar"], expectFailure=True)
+            "INVALIDPROGRAM", runInTerminal=True, args=["foobar"], env=["FOO=bar"], expectFailure=True)
         self.assertFalse(response['success'])
         self.assertIn("Could not create a target for a program 'INVALIDPROGRAM': unable to find executable",
             response['message'])
Index: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
@@ -331,10 +331,6 @@
         if not (response and response['success']):
             self.assertTrue(response['success'],
                             'launch failed (%s)' % (response['message']))
-        # We need to trigger a request_configurationDone after we've successfully
-        # attached a runInTerminal process to finish initialization.
-        if runInTerminal:
-            self.vscode.request_configurationDone()
         return response
 
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147805.511764.patch
Type: text/x-patch
Size: 2995 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230407/b2124c2a/attachment.bin>


More information about the lldb-commits mailing list