Skip to content

[lldb] Fixed an invalid error message in the DAP disconnect response #92345

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 2 commits into from
May 16, 2024

Conversation

slydiman
Copy link
Contributor

The disconnect response contains the error message with invalid characters (a junk data). To reproduce this issue it is enough to run the TestDAP_commands test on Windows host and Linux target. The test will fail to run ELF file on Windows and dap_server will be disconnected unexpectedly.

Note dap_server hangs if read_packet() cannot decode JSON with invalid characters. read_packet() must return None in this case instead of an exception. But dap_server does not require any fix after this patch.

The `disconnect` response contains the `error` message with invalid characters (a junk data).
To reproduce this issue it is enough to run the TestDAP_commands test on Windows host and Linux target. The test will fail to run ELF file on Windows and dap_server will be disconnected unexpectedly.

Note dap_server hangs if read_packet() cannot decode JSON with invalid characters. read_packet() must return None in this case instead of an exception. But dap_server does not require any fix after this patch.
@slydiman slydiman requested a review from JDevlieghere as a code owner May 16, 2024 04:11
@llvmbot llvmbot added the lldb label May 16, 2024
@slydiman slydiman requested review from labath and DavidSpickett May 16, 2024 04:11
@llvmbot
Copy link
Member

llvmbot commented May 16, 2024

@llvm/pr-subscribers-lldb

Author: Dmitry Vasilyev (slydiman)

Changes

The disconnect response contains the error message with invalid characters (a junk data). To reproduce this issue it is enough to run the TestDAP_commands test on Windows host and Linux target. The test will fail to run ELF file on Windows and dap_server will be disconnected unexpectedly.

Note dap_server hangs if read_packet() cannot decode JSON with invalid characters. read_packet() must return None in this case instead of an exception. But dap_server does not require any fix after this patch.


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

1 Files Affected:

  • (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+1-1)
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 96da458be21d1..e9810f83678eb 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -977,7 +977,7 @@ void request_disconnect(const llvm::json::Object &request) {
     g_dap.debugger.SetAsync(false);
     lldb::SBError error = terminateDebuggee ? process.Kill() : process.Detach();
     if (!error.Success())
-      response.try_emplace("error", error.GetCString());
+      response.try_emplace("error", std::string(error.GetCString()));
     g_dap.debugger.SetAsync(true);
     break;
   }

@@ -977,7 +977,7 @@ void request_disconnect(const llvm::json::Object &request) {
g_dap.debugger.SetAsync(false);
lldb::SBError error = terminateDebuggee ? process.Kill() : process.Detach();
if (!error.Success())
response.try_emplace("error", error.GetCString());
response.try_emplace("error", std::string(error.GetCString()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

EmplaceSafeString sounds like the right thing to use here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated the patch. Thanks.

@slydiman slydiman requested a review from labath May 16, 2024 13:08
@slydiman slydiman merged commit f579dcf into llvm:main May 16, 2024
4 checks passed
@slydiman slydiman deleted the fix-lldb-dap-disconnect-error-msg branch July 25, 2024 21:30
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.

4 participants