Skip to content

Commit 24dea05

Browse files
committed
Simplify attach json args
1 parent b6cb9b6 commit 24dea05

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

lldb/tools/lldb-dap/EventHelper.cpp

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -472,31 +472,6 @@ void EventThread(lldb::SBDebugger debugger, lldb::SBBroadcaster broadcaster,
472472

473473
// Find the DAP instance that owns this target
474474
DAP *dap_instance = DAPSessionManager::FindDAP(target);
475-
476-
// Get the target and debugger IDs for the new session to use.
477-
lldb::user_id_t target_id = target.GetGloballyUniqueID();
478-
lldb::SBDebugger target_debugger = target.GetDebugger();
479-
int debugger_id = target_debugger.GetID();
480-
481-
// We create an attach config that contains the debugger ID and target
482-
// ID. The new DAP instance will use these IDs to find the existing
483-
// debugger and target via FindDebuggerWithID and
484-
// FindTargetByGloballyUniqueID.
485-
llvm::json::Object attach_config;
486-
487-
attach_config.try_emplace("type", "lldb");
488-
attach_config.try_emplace("debuggerId", debugger_id);
489-
attach_config.try_emplace("targetId", target_id);
490-
const char *session_name = target.GetTargetSessionName();
491-
attach_config.try_emplace("name", session_name);
492-
493-
// 2. Construct the main 'startDebugging' request arguments.
494-
llvm::json::Object start_debugging_args{
495-
{"request", "attach"},
496-
{"configuration", std::move(attach_config)}};
497-
498-
// Send the request. Note that this is a reverse request, so you don't
499-
// expect a direct response in the same way as a client request.
500475
// If we don't have a dap_instance (target wasn't found), get any
501476
// active instance
502477
if (!dap_instance) {
@@ -507,8 +482,20 @@ void EventThread(lldb::SBDebugger debugger, lldb::SBBroadcaster broadcaster,
507482
}
508483

509484
if (dap_instance) {
485+
// Send a startDebugging reverse request with the debugger and target
486+
// IDs. The new DAP instance will use these IDs to find the existing
487+
// debugger and target via FindDebuggerWithID and
488+
// FindTargetByGloballyUniqueID.
489+
llvm::json::Object configuration{
490+
{"type", "lldb"},
491+
{"debuggerId", target.GetDebugger().GetID()},
492+
{"targetId", target.GetGloballyUniqueID()},
493+
{"name", target.GetTargetSessionName()}};
494+
510495
dap_instance->SendReverseRequest<LogFailureResponseHandler>(
511-
"startDebugging", std::move(start_debugging_args));
496+
"startDebugging", llvm::json::Object{{"request", "attach"},
497+
{"configuration",
498+
std::move(configuration)}});
512499
}
513500
}
514501
} else if (lldb::SBBreakpoint::EventIsBreakpointEvent(event)) {

0 commit comments

Comments
 (0)