Skip to content

[lldb-dap] Assorted small fixes for runInTerminal #140908

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

Conversation

SuibianP
Copy link
Contributor

  • CreateRunInTerminalReverseRequest is passed a StringMap by value, whose keys are owned and deallocated after return.
  • Target args are wrongly specified as reverse request (launcher) args.
  • Test case error message did not catch up with a0aa5f8.

All runInTerminal tests are passing with this applied.

- CreateRunInTerminalReverseRequest is passed a StringMap by value, whose keys
  are owned and deallocated after return.
- Target args are wrongly specified as reverse request (launcher) args.
- Test case error message did not catch up with a0aa5f8.

All runInTerminal tests are passing with this applied.
@SuibianP SuibianP requested a review from JDevlieghere as a code owner May 21, 2025 14:36
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
Copy link
Member

llvmbot commented May 21, 2025

@llvm/pr-subscribers-lldb

Author: Hu Jialun (SuibianP)

Changes
  • CreateRunInTerminalReverseRequest is passed a StringMap by value, whose keys are owned and deallocated after return.
  • Target args are wrongly specified as reverse request (launcher) args.
  • Test case error message did not catch up with a0aa5f8.

All runInTerminal tests are passing with this applied.


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

3 Files Affected:

  • (modified) lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py (+2-2)
  • (modified) lldb/tools/lldb-dap/JSONUtils.cpp (+2-2)
  • (modified) lldb/tools/lldb-dap/JSONUtils.h (+1-1)
diff --git a/lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py b/lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py
index 9aab7ca3293db..65c931210d400 100644
--- a/lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py
+++ b/lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py
@@ -128,8 +128,8 @@ def test_runInTerminalInvalidTarget(self):
         )
         self.assertFalse(response["success"])
         self.assertIn(
-            "Could not create a target for a program 'INVALIDPROGRAM': 'INVALIDPROGRAM' does not exist",
-            response["message"],
+            "'INVALIDPROGRAM' does not exist",
+            response["body"]["error"]["format"],
         )
 
     @skipIfWindows
diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp b/lldb/tools/lldb-dap/JSONUtils.cpp
index 714947a4d3b9c..e26fa9d2b3251 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -1303,7 +1303,7 @@ llvm::json::Value CreateCompileUnit(lldb::SBCompileUnit &unit) {
 /// https://microsoft.github.io/debug-adapter-protocol/specification#Reverse_Requests_RunInTerminal
 llvm::json::Object CreateRunInTerminalReverseRequest(
     llvm::StringRef program, const std::vector<std::string> &args,
-    const llvm::StringMap<std::string> env, llvm::StringRef cwd,
+    const llvm::StringMap<std::string> &env, llvm::StringRef cwd,
     llvm::StringRef comm_file, lldb::pid_t debugger_pid) {
   llvm::json::Object run_in_terminal_args;
   // This indicates the IDE to open an embedded terminal, instead of opening
@@ -1320,7 +1320,7 @@ llvm::json::Object CreateRunInTerminalReverseRequest(
   req_args.push_back("--launch-target");
   req_args.push_back(program.str());
   req_args.insert(req_args.end(), args.begin(), args.end());
-  run_in_terminal_args.try_emplace("args", args);
+  run_in_terminal_args.try_emplace("args", req_args);
 
   if (!cwd.empty())
     run_in_terminal_args.try_emplace("cwd", cwd);
diff --git a/lldb/tools/lldb-dap/JSONUtils.h b/lldb/tools/lldb-dap/JSONUtils.h
index 783f291338d8c..6ac9fe75387fd 100644
--- a/lldb/tools/lldb-dap/JSONUtils.h
+++ b/lldb/tools/lldb-dap/JSONUtils.h
@@ -530,7 +530,7 @@ llvm::json::Value CreateCompileUnit(lldb::SBCompileUnit &unit);
 ///     Microsoft.
 llvm::json::Object CreateRunInTerminalReverseRequest(
     llvm::StringRef program, const std::vector<std::string> &args,
-    const llvm::StringMap<std::string> env, llvm::StringRef cwd,
+    const llvm::StringMap<std::string> &env, llvm::StringRef cwd,
     llvm::StringRef comm_file, lldb::pid_t debugger_pid);
 
 /// Create a "Terminated" JSON object that contains statistics

@SuibianP
Copy link
Contributor Author

The fixes are unrelated to each other. I chose not to break this up into separate changesets since this is so tiny...

@JDevlieghere JDevlieghere requested review from ashgti and da-viper May 21, 2025 23:01
Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

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

LGTM

@SuibianP
Copy link
Contributor Author

I still wonder why CI checks (such as this) were PASS without catching the errors. I could only guess it is in isTestSupported.

def isTestSupported(self):
# For some strange reason, this test fails on python3.6
if not (sys.version_info.major == 3 and sys.version_info.minor >= 7):
return False
try:
# We skip this test for debug builds because it takes too long parsing lldb's own
# debug info. Release builds are fine.
# Checking the size of the lldb-dap binary seems to be a decent proxy for a quick
# detection. It should be far less than 1 MB in Release builds.
if os.path.getsize(os.environ["LLDBDAP_EXEC"]) < 1000000:
return True
except:
return False

Target is of course x86_64 on Linux, and as per buildkite logs Python is 3.10.12.

@ashgti
Copy link
Contributor

ashgti commented May 22, 2025

I have a change to remove the size check on the binary and yea, these tests are broken on macOS for sure.

If this is submitted, then I'll rebase my changes on this, otherwise I also have a patch that could fix this.

@SuibianP
Copy link
Contributor Author

I don't have commit access and please kindly help commit on my behalf when you see fit.

@JDevlieghere JDevlieghere merged commit 695d725 into llvm:main May 23, 2025
13 checks passed
Copy link

@SuibianP 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!

sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
- `CreateRunInTerminalReverseRequest` is passed a `StringMap` by value,
whose keys are owned and deallocated after return.
- Target args are wrongly specified as reverse request (launcher) args.
- Test case error message did not catch up with a0aa5f8.

All runInTerminal tests are passing with this applied.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants