Skip to content

[lldb-dap] Remove g_dap references from lldb-dap/LLDBUtils. #115933

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 3 commits into from
Nov 12, 2024

Conversation

ashgti
Copy link
Contributor

@ashgti ashgti commented Nov 12, 2024

This refactor removes g_dap references from lldb-dap/LLDBUtils.{h,cpp} to allow us to create more than one g_dap instance in the future.

This refactor removes g_dap references from lldb-dap/LLDBUtils.{h,cpp} to allow us to create more than one g_dap instance in the future.
@ashgti ashgti marked this pull request as ready for review November 12, 2024 20:11
@ashgti ashgti requested a review from JDevlieghere as a code owner November 12, 2024 20:11
@llvmbot llvmbot added the lldb label Nov 12, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 12, 2024

@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)

Changes

This refactor removes g_dap references from lldb-dap/LLDBUtils.{h,cpp} to allow us to create more than one g_dap instance in the future.


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

4 Files Affected:

  • (modified) lldb/tools/lldb-dap/DAP.cpp (+1-1)
  • (modified) lldb/tools/lldb-dap/LLDBUtils.cpp (+7-7)
  • (modified) lldb/tools/lldb-dap/LLDBUtils.h (+7-3)
  • (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+2-2)
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index e45f9bf359e5bf..10d2d5d79a74bf 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -548,7 +548,7 @@ bool DAP::RunLLDBCommands(llvm::StringRef prefix,
                           llvm::ArrayRef<std::string> commands) {
   bool required_command_failed = false;
   std::string output =
-      ::RunLLDBCommands(prefix, commands, required_command_failed);
+      ::RunLLDBCommands(debugger, prefix, commands, required_command_failed);
   SendOutput(OutputType::Console, output);
   return !required_command_failed;
 }
diff --git a/lldb/tools/lldb-dap/LLDBUtils.cpp b/lldb/tools/lldb-dap/LLDBUtils.cpp
index 2ffcba7dff4f24..48b63b59e0e3fe 100644
--- a/lldb/tools/lldb-dap/LLDBUtils.cpp
+++ b/lldb/tools/lldb-dap/LLDBUtils.cpp
@@ -15,7 +15,7 @@
 
 namespace lldb_dap {
 
-bool RunLLDBCommands(llvm::StringRef prefix,
+bool RunLLDBCommands(lldb::SBDebugger &debugger, llvm::StringRef prefix,
                      const llvm::ArrayRef<std::string> &commands,
                      llvm::raw_ostream &strm, bool parse_command_directives) {
   if (commands.empty())
@@ -23,7 +23,7 @@ bool RunLLDBCommands(llvm::StringRef prefix,
 
   bool did_print_prefix = false;
 
-  lldb::SBCommandInterpreter interp = g_dap.debugger.GetCommandInterpreter();
+  lldb::SBCommandInterpreter interp = debugger.GetCommandInterpreter();
   for (llvm::StringRef command : commands) {
     lldb::SBCommandReturnObject result;
     bool quiet_on_success = false;
@@ -78,23 +78,23 @@ bool RunLLDBCommands(llvm::StringRef prefix,
   return true;
 }
 
-std::string RunLLDBCommands(llvm::StringRef prefix,
+std::string RunLLDBCommands(lldb::SBDebugger &debugger, llvm::StringRef prefix,
                             const llvm::ArrayRef<std::string> &commands,
                             bool &required_command_failed,
                             bool parse_command_directives) {
   required_command_failed = false;
   std::string s;
   llvm::raw_string_ostream strm(s);
-  required_command_failed =
-      !RunLLDBCommands(prefix, commands, strm, parse_command_directives);
+  required_command_failed = !RunLLDBCommands(debugger, prefix, commands, strm,
+                                             parse_command_directives);
   return s;
 }
 
 std::string
-RunLLDBCommandsVerbatim(llvm::StringRef prefix,
+RunLLDBCommandsVerbatim(lldb::SBDebugger &debugger, llvm::StringRef prefix,
                         const llvm::ArrayRef<std::string> &commands) {
   bool required_command_failed = false;
-  return RunLLDBCommands(prefix, commands, required_command_failed,
+  return RunLLDBCommands(debugger, prefix, commands, required_command_failed,
                          /*parse_command_directives=*/false);
 }
 
diff --git a/lldb/tools/lldb-dap/LLDBUtils.h b/lldb/tools/lldb-dap/LLDBUtils.h
index d5072d19029a1e..683d48a4a46321 100644
--- a/lldb/tools/lldb-dap/LLDBUtils.h
+++ b/lldb/tools/lldb-dap/LLDBUtils.h
@@ -10,6 +10,7 @@
 #define LLDB_TOOLS_LLDB_DAP_LLDBUTILS_H
 
 #include "DAPForward.h"
+#include "lldb/API/SBDebugger.h"
 #include "lldb/API/SBEnvironment.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
@@ -30,6 +31,9 @@ namespace lldb_dap {
 /// emitted regardless, and \b false is returned without executing the
 /// remaining commands.
 ///
+/// \param[in] debugger
+///     The debugger that will execute the lldb commands.
+///
 /// \param[in] prefix
 ///     A string that will be printed into \a strm prior to emitting
 ///     the prompt + command and command output. Can be NULL.
@@ -48,7 +52,7 @@ namespace lldb_dap {
 /// \return
 ///     \b true, unless a command prefixed with \b ! fails and parsing of
 ///     command directives is enabled.
-bool RunLLDBCommands(llvm::StringRef prefix,
+bool RunLLDBCommands(lldb::SBDebugger &debugger, llvm::StringRef prefix,
                      const llvm::ArrayRef<std::string> &commands,
                      llvm::raw_ostream &strm, bool parse_command_directives);
 
@@ -75,14 +79,14 @@ bool RunLLDBCommands(llvm::StringRef prefix,
 /// \return
 ///     A std::string that contains the prefix and all commands and
 ///     command output.
-std::string RunLLDBCommands(llvm::StringRef prefix,
+std::string RunLLDBCommands(lldb::SBDebugger &debugger, llvm::StringRef prefix,
                             const llvm::ArrayRef<std::string> &commands,
                             bool &required_command_failed,
                             bool parse_command_directives = true);
 
 /// Similar to the method above, but without parsing command directives.
 std::string
-RunLLDBCommandsVerbatim(llvm::StringRef prefix,
+RunLLDBCommandsVerbatim(lldb::SBDebugger &debugger, llvm::StringRef prefix,
                         const llvm::ArrayRef<std::string> &commands);
 
 /// Check if a thread has a stop reason.
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index c50e7abb32b47b..180923f1f145a2 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -1615,8 +1615,8 @@ void request_evaluate(const llvm::json::Object &request) {
     if (frame.IsValid()) {
       g_dap.focus_tid = frame.GetThread().GetThreadID();
     }
-    auto result =
-        RunLLDBCommandsVerbatim(llvm::StringRef(), {std::string(expression)});
+    auto result = RunLLDBCommandsVerbatim(g_dap.debugger, llvm::StringRef(),
+                                          {std::string(expression)});
     EmplaceSafeString(body, "result", result);
     body.try_emplace("variablesReference", (int64_t)0);
   } else {

@ashgti ashgti merged commit e5ba117 into llvm:main Nov 12, 2024
6 of 7 checks passed
JDevlieghere pushed a commit to swiftlang/llvm-project that referenced this pull request Feb 25, 2025
…15933)

This refactor removes g_dap references from lldb-dap/LLDBUtils.{h,cpp}
to allow us to create more than one g_dap instance in the future.

(cherry picked from commit e5ba117)
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.

4 participants