Skip to content

[lldb-dap] Report exit status message in lldb-dap, same as lldb cli #89405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

mbucko
Copy link
Contributor

@mbucko mbucko commented Apr 19, 2024

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 (0xffffffff) 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 (0xffffffff) debugserver died with signal SIGTERM

Reviewers:
@jeffreytan81,@clayborg,@kusmour,

Subscribers:

Tasks:
lldb-dap

Tags:

@mbucko mbucko requested a review from JDevlieghere as a code owner April 19, 2024 15:38
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the lldb label Apr 19, 2024
@llvmbot
Copy link
Member

llvmbot commented Apr 19, 2024

@llvm/pr-subscribers-lldb

Author: Miro Bucko (mbucko)

Changes

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 (0xffffffff) 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 (0xffffffff) debugserver died with signal SIGTERM

Reviewers:
jeffreytan81,clayborg,kusmour,

Subscribers:

Tasks:
lldb-dap

Tags:


Full diff: https://github.com/llvm/llvm-project/pull/89405.diff

1 Files Affected:

  • (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+7)
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 25c5ad56e3d6fe..76c7fb17a793cb 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -503,6 +503,13 @@ 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.

@kevinfrei
Copy link
Contributor

You generally have to tag people with an at sign to get their attention :) @jeffreytan81 @clayborg @kusmour

@JDevlieghere
Copy link
Member

Is it possible to test this, for example by explicitly killing the debug stub?

@walter-erquinigo
Copy link
Member

Yep, please write a python test. A possible idea is to have a target that does nothing for 10 seconds, during which you kill the debug server (lldb-server or debugserver) and then you assert on the final message sent by lldb-vscode.

Copy link
Member

@walter-erquinigo walter-erquinigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Thank you!

I've wanted this feature for a while, tbh, because the user doesn't know if the program terminated successfully or if the debugger crashed.

@walter-erquinigo walter-erquinigo changed the title Report exit status message in lldb-dap, same as lldb cli [lldb-dap] Report exit status message in lldb-dap, same as lldb cli Apr 22, 2024
Copy link

github-actions bot commented Apr 22, 2024

✅ With the latest revision this PR passed the Python code formatter.

"debugserver" if platform.platform() == "MacOS" else "lldb-server"
)
process = get_subprocess(process_name)
process.terminate()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

@mbucko mbucko force-pushed the exit_status branch 2 times, most recently from 4c22c23 to d0ed0c6 Compare April 22, 2024 18:50
@mbucko mbucko requested a review from JDevlieghere April 24, 2024 00:23
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 (0xffffffff) 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 (0xffffffff) debugserver died with signal SIGTERM

Reviewers:

Subscribers:

Tasks:
lldb-dap

Tags:
@jeffreytan81 jeffreytan81 merged commit ef2ca97 into llvm:main Apr 25, 2024
Copy link

@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. 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.

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. 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!

@ilovepi
Copy link
Contributor

ilovepi commented Apr 25, 2024

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 <module>
    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 <module>
    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

mbucko added a commit to mbucko/llvm-project that referenced this pull request Apr 26, 2024
Summary:
'test_exit_status_message_sigterm' is failing due to 'psutil' dependency introduced in PR llvm#89405. This fix removes 'deque' dependency and checks if 'psutil' can be imported before running the test. If 'psutil' cannot be imported, it emits a warning and skips the test.

Test Plan:
./bin/llvm-lit -sv /path-to-llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py --filter=tools/lldb-dap/console/TestDAP_console.py

Reviewers:
@jeffreytan81,@clayborg,@kusmour, @JDevlieghere,@walter-erquinigo

Subscribers:

Tasks:
lldb-dap

Tags:
mbucko added a commit to mbucko/llvm-project that referenced this pull request Apr 30, 2024
Summary:
'test_exit_status_message_sigterm' is failing due to 'psutil' dependency introduced in PR llvm#89405. This fix removes 'deque' dependency and checks if 'psutil' can be imported before running the test. If 'psutil' cannot be imported, it emits a warning and skips the test.

Test Plan:
./bin/llvm-lit -sv /path-to-llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py --filter=tools/lldb-dap/console/TestDAP_console.py

Reviewers:
@jeffreytan81,@clayborg,@kusmour, @JDevlieghere,@walter-erquinigo

Subscribers:

Tasks:
lldb-dap

Tags:
mbucko added a commit to mbucko/llvm-project that referenced this pull request May 3, 2024
Summary:
'test_exit_status_message_sigterm' is failing due to 'psutil' dependency introduced in PR llvm#89405. This fix removes 'deque' dependency and checks if 'psutil' can be imported before running the test. If 'psutil' cannot be imported, it emits a warning and skips the test.

Test Plan:
./bin/llvm-lit -sv /path-to-llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py --filter=tools/lldb-dap/console/TestDAP_console.py

Reviewers:
@jeffreytan81,@clayborg,@kusmour, @JDevlieghere,@walter-erquinigo

Subscribers:

Tasks:
lldb-dap

Tags:
jeffreytan81 pushed a commit that referenced this pull request May 3, 2024
Summary:
'test_exit_status_message_sigterm' is failing due to 'psutil' dependency
introduced in PR #89405. This fix removes 'deque' dependency and checks
if 'psutil' can be imported before running the test. If 'psutil' cannot
be imported, it emits a warning and skips the test.

Test Plan:
./bin/llvm-lit -sv
/path-to-llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
--filter=tools/lldb-dap/console/TestDAP_console.py

Reviewers:
@jeffreytan81,@clayborg,@kusmour, @JDevlieghere,@walter-erquinigo

Subscribers:

Tasks:
lldb-dap

Tags:
@mbucko mbucko deleted the exit_status branch June 12, 2024 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants