Skip to content

Commit 93be970

Browse files
committed
Two InitializeDebugger functions
1 parent 30034a5 commit 93be970

File tree

3 files changed

+42
-32
lines changed

3 files changed

+42
-32
lines changed

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,38 +1321,30 @@ void DAP::StartEventThreads() {
13211321
StartEventThread();
13221322
}
13231323

1324-
llvm::Error DAP::InitializeDebugger(std::optional<int> debugger_id,
1325-
std::optional<lldb::user_id_t> target_id) {
1326-
// Validate that both debugger_id and target_id are provided together.
1327-
if (debugger_id.has_value() != target_id.has_value()) {
1324+
llvm::Error DAP::InitializeDebugger(int debugger_id,
1325+
lldb::user_id_t target_id) {
1326+
// Find the existing debugger by ID
1327+
debugger = lldb::SBDebugger::FindDebuggerWithID(debugger_id);
1328+
if (!debugger.IsValid()) {
13281329
return llvm::createStringError(
1329-
"Both debuggerId and targetId must be specified together for debugger "
1330-
"reuse, or both must be omitted to create a new debugger");
1330+
"Unable to find existing debugger for debugger ID");
13311331
}
13321332

1333-
// Initialize debugger instance (shared or individual).
1334-
if (debugger_id && target_id) {
1335-
// Find the existing debugger by ID
1336-
debugger = lldb::SBDebugger::FindDebuggerWithID(*debugger_id);
1337-
if (!debugger.IsValid()) {
1338-
return llvm::createStringError(
1339-
"Unable to find existing debugger for debugger ID");
1340-
}
1341-
1342-
// Find the target within the debugger by its globally unique ID
1343-
lldb::SBTarget shared_target =
1344-
debugger.FindTargetByGloballyUniqueID(*target_id);
1345-
if (!shared_target.IsValid()) {
1346-
return llvm::createStringError(
1347-
"Unable to find existing target for target ID");
1348-
}
1349-
1350-
// Set the target for this DAP session.
1351-
SetTarget(shared_target);
1352-
StartEventThreads();
1353-
return llvm::Error::success();
1333+
// Find the target within the debugger by its globally unique ID
1334+
lldb::SBTarget shared_target =
1335+
debugger.FindTargetByGloballyUniqueID(target_id);
1336+
if (!shared_target.IsValid()) {
1337+
return llvm::createStringError(
1338+
"Unable to find existing target for target ID");
13541339
}
13551340

1341+
// Set the target for this DAP session.
1342+
SetTarget(shared_target);
1343+
StartEventThreads();
1344+
return llvm::Error::success();
1345+
}
1346+
1347+
llvm::Error DAP::InitializeDebugger() {
13561348
debugger = lldb::SBDebugger::Create(/*argument_name=*/false);
13571349

13581350
// Configure input/output/error file descriptors.

lldb/tools/lldb-dap/DAP.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,18 @@ struct DAP final : public DAPTransport::MessageHandler {
426426
/// DAP debugger initialization functions.
427427
/// @{
428428

429-
/// Perform complete DAP initialization in one call.
430-
llvm::Error
431-
InitializeDebugger(std::optional<int> debugger_id = std::nullopt,
432-
std::optional<lldb::user_id_t> target_id = std::nullopt);
429+
/// Perform complete DAP initialization for a new debugger.
430+
llvm::Error InitializeDebugger();
431+
432+
/// Perform complete DAP initialization by reusing an existing debugger and
433+
/// target.
434+
///
435+
/// \param[in] debugger_id
436+
/// The ID of the existing debugger to reuse.
437+
///
438+
/// \param[in] target_id
439+
/// The globally unique ID of the existing target to reuse.
440+
llvm::Error InitializeDebugger(int debugger_id, lldb::user_id_t target_id);
433441

434442
/// Start event handling threads based on client capabilities.
435443
void StartEventThreads();

lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ Error AttachRequestHandler::Run(const AttachRequestArguments &args) const {
3434
// launched debugger.
3535
std::optional<int> debugger_id = args.debuggerId;
3636
std::optional<lldb::user_id_t> target_id = args.targetId;
37-
if (Error err = dap.InitializeDebugger(debugger_id, target_id))
37+
38+
// Validate that both debugger_id and target_id are provided together.
39+
if (debugger_id.has_value() != target_id.has_value()) {
40+
return llvm::createStringError(
41+
"Both debuggerId and targetId must be specified together for debugger "
42+
"reuse, or both must be omitted to create a new debugger");
43+
}
44+
45+
if (Error err = debugger_id && target_id
46+
? dap.InitializeDebugger(*debugger_id, *target_id)
47+
: dap.InitializeDebugger())
3848
return err;
3949

4050
// Validate that we have a well formed attach request.

0 commit comments

Comments
 (0)