[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-25 Thread Paul Kirth via lldb-commits

ilovepi wrote:

Hi, I think we're seeing some breakage in our CI after this patch.

We see the lldb-api :: tools/lldb-dap/console/TestDAP_console.py test failing.

https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-linux-arm64/b8749666263730294449/overview

```
 TEST 'lldb-api :: 
tools/lldb-dap/console/TestDAP_console.py' FAILED 
Script:
--
/b/s/w/ir/x/w/lldb_install/python3/bin/python3 
/b/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS 
--env ARCHIVER=/b/s/w/ir/x/w/cipd/bin/llvm-ar --env 
OBJCOPY=/b/s/w/ir/x/w/cipd/bin/llvm-objcopy --env 
LLVM_LIBS_DIR=/b/s/w/ir/x/w/llvm_build/./lib --env 
LLVM_INCLUDE_DIR=/b/s/w/ir/x/w/llvm_build/include --env 
LLVM_TOOLS_DIR=/b/s/w/ir/x/w/llvm_build/./bin --libcxx-include-dir 
/b/s/w/ir/x/w/llvm_build/include/c++/v1 --libcxx-include-target-dir 
/b/s/w/ir/x/w/llvm_build/include/aarch64-unknown-linux-gnu/c++/v1 
--libcxx-library-dir /b/s/w/ir/x/w/llvm_build/./lib/aarch64-unknown-linux-gnu 
--arch aarch64 --build-dir /b/s/w/ir/x/w/llvm_build/lldb-test-build.noindex 
--lldb-module-cache-dir 
/b/s/w/ir/x/w/llvm_build/lldb-test-build.noindex/module-cache-lldb/lldb-api 
--clang-module-cache-dir 
/b/s/w/ir/x/w/llvm_build/lldb-test-build.noindex/module-cache-clang/lldb-api 
--executable /b/s/w/ir/x/w/llvm_build/./bin/lldb --compiler 
/b/s/w/ir/x/w/llvm_build/./bin/clang --dsymutil 
/b/s/w/ir/x/w/llvm_build/./bin/dsymutil --llvm-tools-dir 
/b/s/w/ir/x/w/llvm_build/./bin --lldb-libs-dir /b/s/w/ir/x/w/llvm_build/./lib 
--skip-category=pexpect 
/b/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/tools/lldb-dap/console -p 
TestDAP_console.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 19.0.0git (https://llvm.googlesource.com/a/llvm-project revision 
5fb59e744783cf686e6a355c8331eeab90678c00)
  clang revision 5fb59e744783cf686e6a355c8331eeab90678c00
  llvm revision 5fb59e744783cf686e6a355c8331eeab90678c00
Skipping the following test categories: ['pexpect', 'dsym', 'gmodules', 
'debugserver', 'objc']

--
Command Output (stderr):
--
Traceback (most recent call last):
  File "/b/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/dotest.py", line 8, in 

lldbsuite.test.run_suite()
  File 
"/b/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/dotest.py",
 line 1039, in run_suite
visit("Test", dirpath, filenames)
  File 
"/b/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/dotest.py",
 line 700, in visit
visit_file(dir, name)
  File 
"/b/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/dotest.py",
 line 643, in visit_file
module = __import__(base)
 
  File 
"/b/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py",
 line 7, in 
import psutil
ModuleNotFoundError: No module named 'psutil'

--
```
would you mind taking a look. CC: @mysterymath since he's the most familiar w/ 
our lldb build

https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-25 Thread via lldb-commits

github-actions[bot] wrote:



@mbucko Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-25 Thread via lldb-commits

https://github.com/jeffreytan81 closed 
https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-25 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/89405

>From edefccebc44296d9be29ddde2c48174feb5d2911 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 19 Apr 2024 08:08:02 -0700
Subject: [PATCH] Report exit status message in lldb-dap, same as lldb cli

Summary:
When the target inferior process that is being debugged exits in lldb command 
line, it emits following message:
Process 4049526 exited with status = -1 (0x) debugserver died with 
signal SIGTERM
lldb-dap on the other hand does not emit a similar message.
This PR adds the same status message to lldb-dap.

Test Plan:
In VSCode debug any target and hit stop mode, kill lldb-server and observe an 
exit status message similar to the following:
Process 2167677 exited with status = -1 (0x) debugserver died with 
signal SIGTERM

Reviewers:

Subscribers:

Tasks:
lldb-dap

Tags:
---
 lldb/include/lldb/API/SBProcess.h |  2 +
 lldb/source/API/SBProcess.cpp |  8 +++
 .../tools/lldb-dap/console/TestDAP_console.py | 58 +++
 lldb/tools/lldb-dap/lldb-dap.cpp  |  5 ++
 4 files changed, 73 insertions(+)

diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index 7da3335a7234b7..f1b5d1fb92ce29 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -562,6 +562,8 @@ class LLDB_API SBProcess {
 
   lldb::SBScriptObject GetScriptedImplementation();
 
+  void GetStatus(SBStream );
+
 protected:
   friend class SBAddress;
   friend class SBBreakpoint;
diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index c73348fde3f74d..c37c111c5a58e0 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -928,6 +928,14 @@ size_t SBProcess::WriteMemory(addr_t addr, const void 
*src, size_t src_len,
   return bytes_written;
 }
 
+void SBProcess::GetStatus(SBStream ) {
+  LLDB_INSTRUMENT_VA(this, status);
+
+  ProcessSP process_sp(GetSP());
+  if (process_sp)
+process_sp->GetStatus(status.ref());
+}
+
 bool SBProcess::GetDescription(SBStream ) {
   LLDB_INSTRUMENT_VA(this, description);
 
diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index ffa0dc943e0693..8f456aaf890c7f 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,11 +4,23 @@
 
 import dap_server
 import lldbdap_testcase
+import psutil
+from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
 
+def get_subprocess(process_name):
+queue = deque([psutil.Process(os.getpid())])
+while queue:
+process = queue.popleft()
+if process.name() == process_name:
+return process
+queue.extend(process.children())
+
+self.assertTrue(False, "No subprocess with name %s found" % process_name)
+
 class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
 def check_lldb_command(
 self, lldb_command, contains_string, assert_msg, 
command_escape_prefix="`"
@@ -104,3 +116,49 @@ def test_empty_escape_prefix(self):
 "Help can be invoked",
 command_escape_prefix="",
 )
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_sigterm(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+breakpoint1_line = line_number(source, "// breakpoint 1")
+breakpoint_ids = self.set_source_breakpoints(source, 
[breakpoint1_line])
+self.continue_to_breakpoints(breakpoint_ids)
+
+# Kill lldb-server process.
+process_name = (
+"debugserver" if platform.system() in ["Darwin"] else "lldb-server"
+)
+process = get_subprocess(process_name)
+process.terminate()
+process.wait()
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = -1 (0x) debugserver died with signal 
SIGTERM",
+console_output,
+"Exit status does not contain message 'exited with status'",
+)
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_ok(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+self.continue_to_exit()
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = 0 (0x)",
+console_output,
+"Exit status does not contain message 'exited with status'",
+   

[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-24 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere approved this pull request.


https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-23 Thread via lldb-commits

https://github.com/jeffreytan81 approved this pull request.


https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/89405

>From d0ed0c618aeaf81dd471fc31c9f14d4b207effaa Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 19 Apr 2024 08:08:02 -0700
Subject: [PATCH] Report exit status message in lldb-dap, same as lldb cli

Summary:
When the target inferior process that is being debugged exits in lldb command 
line, it emits following message:
Process 4049526 exited with status = -1 (0x) debugserver died with 
signal SIGTERM
lldb-dap on the other hand does not emit a similar message.
This PR adds the same status message to lldb-dap.

Test Plan:
In VSCode debug any target and hit stop mode, kill lldb-server and observe an 
exit status message similar to the following:
Process 2167677 exited with status = -1 (0x) debugserver died with 
signal SIGTERM

Reviewers:

Subscribers:

Tasks:
lldb-dap

Tags:
---
 lldb/include/lldb/API/SBProcess.h |  2 +
 lldb/source/API/SBProcess.cpp |  8 +++
 .../tools/lldb-dap/console/TestDAP_console.py | 58 +++
 lldb/tools/lldb-dap/lldb-dap.cpp  |  5 ++
 4 files changed, 73 insertions(+)

diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index 7da3335a7234b7..f1b5d1fb92ce29 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -562,6 +562,8 @@ class LLDB_API SBProcess {
 
   lldb::SBScriptObject GetScriptedImplementation();
 
+  void GetStatus(SBStream );
+
 protected:
   friend class SBAddress;
   friend class SBBreakpoint;
diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index b80664882ebcac..cf1ac1ae6b3377 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -928,6 +928,14 @@ size_t SBProcess::WriteMemory(addr_t addr, const void 
*src, size_t src_len,
   return bytes_written;
 }
 
+void SBProcess::GetStatus(SBStream ) {
+  LLDB_INSTRUMENT_VA(this, status);
+
+  ProcessSP process_sp(GetSP());
+  if (process_sp)
+process_sp->GetStatus(status.ref());
+}
+
 bool SBProcess::GetDescription(SBStream ) {
   LLDB_INSTRUMENT_VA(this, description);
 
diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index ffa0dc943e0693..8f456aaf890c7f 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,11 +4,23 @@
 
 import dap_server
 import lldbdap_testcase
+import psutil
+from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
 
+def get_subprocess(process_name):
+queue = deque([psutil.Process(os.getpid())])
+while queue:
+process = queue.popleft()
+if process.name() == process_name:
+return process
+queue.extend(process.children())
+
+self.assertTrue(False, "No subprocess with name %s found" % process_name)
+
 class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
 def check_lldb_command(
 self, lldb_command, contains_string, assert_msg, 
command_escape_prefix="`"
@@ -104,3 +116,49 @@ def test_empty_escape_prefix(self):
 "Help can be invoked",
 command_escape_prefix="",
 )
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_sigterm(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+breakpoint1_line = line_number(source, "// breakpoint 1")
+breakpoint_ids = self.set_source_breakpoints(source, 
[breakpoint1_line])
+self.continue_to_breakpoints(breakpoint_ids)
+
+# Kill lldb-server process.
+process_name = (
+"debugserver" if platform.system() in ["Darwin"] else "lldb-server"
+)
+process = get_subprocess(process_name)
+process.terminate()
+process.wait()
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = -1 (0x) debugserver died with signal 
SIGTERM",
+console_output,
+"Exit status does not contain message 'exited with status'",
+)
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_ok(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+self.continue_to_exit()
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = 0 (0x)",
+console_output,
+"Exit status does not contain message 'exited with status'",
+   

[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/89405

>From 4c22c237dae73f3fbac22c0d725ae4fa449170df Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 19 Apr 2024 08:08:02 -0700
Subject: [PATCH] Report exit status message in lldb-dap, same as lldb cli

Summary:
When the target inferior process that is being debugged exits in lldb command 
line, it emits following message:
Process 4049526 exited with status = -1 (0x) debugserver died with 
signal SIGTERM
lldb-dap on the other hand does not emit a similar message.
This PR adds the same status message to lldb-dap.

Test Plan:
In VSCode debug any target and hit stop mode, kill lldb-server and observe an 
exit status message similar to the following:
Process 2167677 exited with status = -1 (0x) debugserver died with 
signal SIGTERM

Reviewers:

Subscribers:

Tasks:
lldb-dap

Tags:
---
 lldb/include/lldb/API/SBProcess.h |  2 +
 lldb/source/API/SBProcess.cpp |  8 +++
 .../tools/lldb-dap/console/TestDAP_console.py | 57 +++
 lldb/tools/lldb-dap/lldb-dap.cpp  |  5 ++
 4 files changed, 72 insertions(+)

diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index 7da3335a7234b7..f1b5d1fb92ce29 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -562,6 +562,8 @@ class LLDB_API SBProcess {
 
   lldb::SBScriptObject GetScriptedImplementation();
 
+  void GetStatus(SBStream );
+
 protected:
   friend class SBAddress;
   friend class SBBreakpoint;
diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index b80664882ebcac..cf1ac1ae6b3377 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -928,6 +928,14 @@ size_t SBProcess::WriteMemory(addr_t addr, const void 
*src, size_t src_len,
   return bytes_written;
 }
 
+void SBProcess::GetStatus(SBStream ) {
+  LLDB_INSTRUMENT_VA(this, status);
+
+  ProcessSP process_sp(GetSP());
+  if (process_sp)
+process_sp->GetStatus(status.ref());
+}
+
 bool SBProcess::GetDescription(SBStream ) {
   LLDB_INSTRUMENT_VA(this, description);
 
diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index ffa0dc943e0693..8c71ca1777b9dd 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,10 +4,21 @@
 
 import dap_server
 import lldbdap_testcase
+import psutil
+from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
+def get_subprocess(process_name):
+queue = deque([psutil.Process(os.getpid())])
+while queue:
+process = queue.popleft()
+if process.name() == process_name:
+return process
+queue.extend(process.children())
+
+self.assertTrue(False, "No subprocess with name %s found" % process_name)
 
 class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
 def check_lldb_command(
@@ -104,3 +115,49 @@ def test_empty_escape_prefix(self):
 "Help can be invoked",
 command_escape_prefix="",
 )
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_sigterm(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+breakpoint1_line = line_number(source, "// breakpoint 1")
+breakpoint_ids = self.set_source_breakpoints(source, 
[breakpoint1_line])
+self.continue_to_breakpoints(breakpoint_ids)
+
+# Kill lldb-server process.
+process_name = (
+"debugserver" if platform.system() in ["Darwin"] else "lldb-server"
+)
+process = get_subprocess(process_name)
+process.terminate()
+process.wait()
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = -1 (0x) debugserver died with signal 
SIGTERM",
+console_output,
+"Exit status does not contain message 'exited with status'",
+)
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_ok(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+self.continue_to_exit()
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = 0 (0x)",
+console_output,
+"Exit status does not contain message 'exited with status'",
+)
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp 

[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread Miro Bucko via lldb-commits


@@ -4,10 +4,30 @@
 
 import dap_server
 import lldbdap_testcase
+import psutil
+from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
+def get_subprocess_pid(process_name):
+queue = deque([psutil.Process(os.getpid())])
+while queue:
+process = queue.popleft()
+if process.name() == process_name:
+return process.pid
+queue.extend(process.children())

mbucko wrote:

The lldb-server is not a direct subprocess of these tests. It's actually 
llvm-lit -> lldb-dap -> lldb-server. And also, lldb-dap has already been 
renamed once.

https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread via lldb-commits


@@ -104,3 +115,49 @@ def test_empty_escape_prefix(self):
 "Help can be invoked",
 command_escape_prefix="",
 )
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_sigterm(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+breakpoint1_line = line_number(source, "// breakpoint 1")
+breakpoint_ids = self.set_source_breakpoints(source, 
[breakpoint1_line])
+self.continue_to_breakpoints(breakpoint_ids)
+
+# Kill lldb-server process.
+process_name = (
+"debugserver" if platform.platform() == "MacOS" else "lldb-server"
+)
+process = get_subprocess(process_name)
+process.terminate()

jeffreytan81 wrote:

I wish we can create a crash packet so that we can initiate 
lldb-server/debugserver crash for testing purpose without this kind of hack...

https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread via lldb-commits


@@ -503,6 +503,14 @@ void EventThreadFunction() {
 SendContinuedEvent();
 break;
   case lldb::eStateExited:
+const int exit_status = process.GetExitStatus();
+const char *const exit_description = process.GetExitDescription();
+g_dap.SendFormattedOutput(
+OutputType::Console,
+"Process %" PRIu64 " exited with status = %i (0x%8.8x) %s\n",
+process.GetProcessID(), exit_status, exit_status,
+exit_description ? exit_description : "");
+

jeffreytan81 wrote:

This code seems to be a duplication of `Process::GetStatus`. Maybe we should 
expose `Process::GetStatus` in SBPorcess to ensure lldb-dap and lldb output are 
not out of sync if future modification is added to `Process::GetStatus`. 

https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread via lldb-commits


@@ -104,3 +115,49 @@ def test_empty_escape_prefix(self):
 "Help can be invoked",
 command_escape_prefix="",
 )
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_sigterm(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+breakpoint1_line = line_number(source, "// breakpoint 1")
+breakpoint_ids = self.set_source_breakpoints(source, 
[breakpoint1_line])
+self.continue_to_breakpoints(breakpoint_ids)
+
+# Kill lldb-server process.
+process_name = (
+"debugserver" if platform.platform() == "MacOS" else "lldb-server"
+)
+process = get_subprocess(process_name)
+process.terminate()
+process.wait(timeout=5)
+
+# Get the console output
+console_output = self.collect_console(1.0)

jeffreytan81 wrote:

I am not big fan of adding timeout in test for synchronization. It can always 
cause race condition in super busy machine. 

Instead, I would suggest wait for process to exit and get all the output which 
should guarantee to have all the output ready. This way also tests that 
exit/terminated events are sent after this exit message. 

https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere edited 
https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread Jonas Devlieghere via lldb-commits


@@ -104,3 +115,49 @@ def test_empty_escape_prefix(self):
 "Help can be invoked",
 command_escape_prefix="",
 )
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_sigterm(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+breakpoint1_line = line_number(source, "// breakpoint 1")
+breakpoint_ids = self.set_source_breakpoints(source, 
[breakpoint1_line])
+self.continue_to_breakpoints(breakpoint_ids)
+
+# Kill lldb-server process.
+process_name = (
+"debugserver" if platform.platform() == "MacOS" else "lldb-server"

JDevlieghere wrote:

On macOS, `platform.platform()` returns something like 
'macOS-14.5-arm64-arm-64bit'. What you want to check here is 
`platform.system()` and check that it's "Darwin":

```
"debugserver" if platform.system() in ["Darwin"] else "lldb-server"
```

https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/89405

>From b20ef7c68e23835ebf2c31f836407a0fb9f875a0 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 19 Apr 2024 08:08:02 -0700
Subject: [PATCH] Report exit status message in lldb-dap, same as lldb cli

Summary:
When the target inferior process that is being debugged exits in lldb command 
line, it emits following message:
Process 4049526 exited with status = -1 (0x) debugserver died with 
signal SIGTERM
lldb-dap on the other hand does not emit a similar message.
This PR adds the same status message to lldb-dap.

Test Plan:
In VSCode debug any target and hit stop mode, kill lldb-server and observe an 
exit status message similar to the following:
Process 2167677 exited with status = -1 (0x) debugserver died with 
signal SIGTERM

Reviewers:

Subscribers:

Tasks:
lldb-dap

Tags:
---
 .../tools/lldb-dap/console/TestDAP_console.py | 57 +++
 lldb/tools/lldb-dap/lldb-dap.cpp  |  8 +++
 2 files changed, 65 insertions(+)

diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index ffa0dc943e0693..2ffb67ac84c86c 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,10 +4,21 @@
 
 import dap_server
 import lldbdap_testcase
+import psutil
+from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
+def get_subprocess(process_name):
+queue = deque([psutil.Process(os.getpid())])
+while queue:
+process = queue.popleft()
+if process.name() == process_name:
+return process
+queue.extend(process.children())
+
+self.assertTrue(False, "No subprocess with name %s found" % process_name)
 
 class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
 def check_lldb_command(
@@ -104,3 +115,49 @@ def test_empty_escape_prefix(self):
 "Help can be invoked",
 command_escape_prefix="",
 )
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_sigterm(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+breakpoint1_line = line_number(source, "// breakpoint 1")
+breakpoint_ids = self.set_source_breakpoints(source, 
[breakpoint1_line])
+self.continue_to_breakpoints(breakpoint_ids)
+
+# Kill lldb-server process.
+process_name = (
+"debugserver" if platform.platform() == "MacOS" else "lldb-server"
+)
+process = get_subprocess(process_name)
+process.terminate()
+process.wait(timeout=5)
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = -1 (0x) debugserver died with signal 
SIGTERM",
+console_output,
+"Exit status does not contain message 'exited with status'",
+)
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_ok(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+self.continue_to_exit()
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = 0 (0x)",
+console_output,
+"Exit status does not contain message 'exited with status'",
+)
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 25c5ad56e3d6fe..124e5a087618a7 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -503,6 +503,14 @@ void EventThreadFunction() {
 SendContinuedEvent();
 break;
   case lldb::eStateExited:
+const int exit_status = process.GetExitStatus();
+const char *const exit_description = process.GetExitDescription();
+g_dap.SendFormattedOutput(
+OutputType::Console,
+"Process %" PRIu64 " exited with status = %i (0x%8.8x) %s\n",
+process.GetProcessID(), exit_status, exit_status,
+exit_description ? exit_description : "");
+
 // When restarting, we can get an "exited" event for the process we
 // just killed with the old PID, or even with no PID. In that case
 // we don't have to terminate the session.

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread via lldb-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
3a4bc11b675c0511319c2843221133e986825b3b...5e270c26adbb1e8febb72fc74d348d4f9619c7bf
 lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
``





View the diff from darker here.


``diff
--- TestDAP_console.py  2024-04-22 14:41:55.00 +
+++ TestDAP_console.py  2024-04-22 14:58:08.749412 +
@@ -7,10 +7,11 @@
 import psutil
 from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
+
 
 def get_subprocess(process_name):
 queue = deque([psutil.Process(os.getpid())])
 while queue:
 process = queue.popleft()
@@ -125,11 +126,13 @@
 breakpoint1_line = line_number(source, "// breakpoint 1")
 breakpoint_ids = self.set_source_breakpoints(source, 
[breakpoint1_line])
 self.continue_to_breakpoints(breakpoint_ids)
 
 # Kill lldb-server process.
-process_name = "debugserver" if platform.platform() == "MacOS" else 
"lldb-server"
+process_name = (
+"debugserver" if platform.platform() == "MacOS" else "lldb-server"
+)
 process = get_subprocess(process_name)
 process.terminate()
 process.wait(timeout=5)
 
 # Get the console output
@@ -137,11 +140,11 @@
 
 # Verify the exit status message is printed.
 self.assertIn(
 "exited with status = -1 (0x) debugserver died with signal 
SIGTERM",
 console_output,
-"Exit status does not contain message 'exited with status'"
+"Exit status does not contain message 'exited with status'",
 )
 
 @skipIfWindows
 @skipIfRemote
 def test_exit_status_message_ok(self):
@@ -155,7 +158,7 @@
 
 # Verify the exit status message is printed.
 self.assertIn(
 "exited with status = 0 (0x)",
 console_output,
-"Exit status does not contain message 'exited with status'"
+"Exit status does not contain message 'exited with status'",
 )

``




https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread Walter Erquinigo via lldb-commits

https://github.com/walter-erquinigo edited 
https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits