Skip to content

Commit e5ba117

Browse files
authored
[lldb-dap] Remove g_dap references from lldb-dap/LLDBUtils. (llvm#115933)
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.
1 parent 5b67372 commit e5ba117

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ bool DAP::RunLLDBCommands(llvm::StringRef prefix,
548548
llvm::ArrayRef<std::string> commands) {
549549
bool required_command_failed = false;
550550
std::string output =
551-
::RunLLDBCommands(prefix, commands, required_command_failed);
551+
::RunLLDBCommands(debugger, prefix, commands, required_command_failed);
552552
SendOutput(OutputType::Console, output);
553553
return !required_command_failed;
554554
}

lldb/tools/lldb-dap/LLDBUtils.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
namespace lldb_dap {
1717

18-
bool RunLLDBCommands(llvm::StringRef prefix,
18+
bool RunLLDBCommands(lldb::SBDebugger &debugger, llvm::StringRef prefix,
1919
const llvm::ArrayRef<std::string> &commands,
2020
llvm::raw_ostream &strm, bool parse_command_directives) {
2121
if (commands.empty())
2222
return true;
2323

2424
bool did_print_prefix = false;
2525

26-
lldb::SBCommandInterpreter interp = g_dap.debugger.GetCommandInterpreter();
26+
lldb::SBCommandInterpreter interp = debugger.GetCommandInterpreter();
2727
for (llvm::StringRef command : commands) {
2828
lldb::SBCommandReturnObject result;
2929
bool quiet_on_success = false;
@@ -78,23 +78,23 @@ bool RunLLDBCommands(llvm::StringRef prefix,
7878
return true;
7979
}
8080

81-
std::string RunLLDBCommands(llvm::StringRef prefix,
81+
std::string RunLLDBCommands(lldb::SBDebugger &debugger, llvm::StringRef prefix,
8282
const llvm::ArrayRef<std::string> &commands,
8383
bool &required_command_failed,
8484
bool parse_command_directives) {
8585
required_command_failed = false;
8686
std::string s;
8787
llvm::raw_string_ostream strm(s);
88-
required_command_failed =
89-
!RunLLDBCommands(prefix, commands, strm, parse_command_directives);
88+
required_command_failed = !RunLLDBCommands(debugger, prefix, commands, strm,
89+
parse_command_directives);
9090
return s;
9191
}
9292

9393
std::string
94-
RunLLDBCommandsVerbatim(llvm::StringRef prefix,
94+
RunLLDBCommandsVerbatim(lldb::SBDebugger &debugger, llvm::StringRef prefix,
9595
const llvm::ArrayRef<std::string> &commands) {
9696
bool required_command_failed = false;
97-
return RunLLDBCommands(prefix, commands, required_command_failed,
97+
return RunLLDBCommands(debugger, prefix, commands, required_command_failed,
9898
/*parse_command_directives=*/false);
9999
}
100100

lldb/tools/lldb-dap/LLDBUtils.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLDB_TOOLS_LLDB_DAP_LLDBUTILS_H
1111

1212
#include "DAPForward.h"
13+
#include "lldb/API/SBDebugger.h"
1314
#include "lldb/API/SBEnvironment.h"
1415
#include "llvm/ADT/ArrayRef.h"
1516
#include "llvm/ADT/StringRef.h"
@@ -30,6 +31,9 @@ namespace lldb_dap {
3031
/// emitted regardless, and \b false is returned without executing the
3132
/// remaining commands.
3233
///
34+
/// \param[in] debugger
35+
/// The debugger that will execute the lldb commands.
36+
///
3337
/// \param[in] prefix
3438
/// A string that will be printed into \a strm prior to emitting
3539
/// the prompt + command and command output. Can be NULL.
@@ -48,7 +52,7 @@ namespace lldb_dap {
4852
/// \return
4953
/// \b true, unless a command prefixed with \b ! fails and parsing of
5054
/// command directives is enabled.
51-
bool RunLLDBCommands(llvm::StringRef prefix,
55+
bool RunLLDBCommands(lldb::SBDebugger &debugger, llvm::StringRef prefix,
5256
const llvm::ArrayRef<std::string> &commands,
5357
llvm::raw_ostream &strm, bool parse_command_directives);
5458

@@ -57,6 +61,9 @@ bool RunLLDBCommands(llvm::StringRef prefix,
5761
/// All output from every command, including the prompt + the command
5862
/// is returned in the std::string return value.
5963
///
64+
/// \param[in] debugger
65+
/// The debugger that will execute the lldb commands.
66+
///
6067
/// \param[in] prefix
6168
/// A string that will be printed into \a strm prior to emitting
6269
/// the prompt + command and command output. Can be NULL.
@@ -75,14 +82,14 @@ bool RunLLDBCommands(llvm::StringRef prefix,
7582
/// \return
7683
/// A std::string that contains the prefix and all commands and
7784
/// command output.
78-
std::string RunLLDBCommands(llvm::StringRef prefix,
85+
std::string RunLLDBCommands(lldb::SBDebugger &debugger, llvm::StringRef prefix,
7986
const llvm::ArrayRef<std::string> &commands,
8087
bool &required_command_failed,
8188
bool parse_command_directives = true);
8289

8390
/// Similar to the method above, but without parsing command directives.
8491
std::string
85-
RunLLDBCommandsVerbatim(llvm::StringRef prefix,
92+
RunLLDBCommandsVerbatim(lldb::SBDebugger &debugger, llvm::StringRef prefix,
8693
const llvm::ArrayRef<std::string> &commands);
8794

8895
/// Check if a thread has a stop reason.

lldb/tools/lldb-dap/lldb-dap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,8 +1615,8 @@ void request_evaluate(const llvm::json::Object &request) {
16151615
if (frame.IsValid()) {
16161616
g_dap.focus_tid = frame.GetThread().GetThreadID();
16171617
}
1618-
auto result =
1619-
RunLLDBCommandsVerbatim(llvm::StringRef(), {std::string(expression)});
1618+
auto result = RunLLDBCommandsVerbatim(g_dap.debugger, llvm::StringRef(),
1619+
{std::string(expression)});
16201620
EmplaceSafeString(body, "result", result);
16211621
body.try_emplace("variablesReference", (int64_t)0);
16221622
} else {

0 commit comments

Comments
 (0)