Skip to content

Commit dd3e809

Browse files
committed
Simplify attach json args
1 parent 058acc1 commit dd3e809

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

lldb/tools/lldb-dap/EventHelper.cpp

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -449,34 +449,10 @@ void HandleTargetEvent(const lldb::SBEvent &event, Log *log) {
449449
}
450450
}
451451
} else if (event_mask & lldb::SBTarget::eBroadcastBitNewTargetCreated) {
452-
// Find the DAP instance that owns this target to check if we should
453-
// ignore this event.
454-
DAP *dap_instance = DAPSessionManager::FindDAP(target);
452+
auto target = lldb::SBTarget::GetTargetFromEvent(event);
455453

456-
// Get the target and debugger IDs for the new session to use.
457-
lldb::user_id_t target_id = target.GetGloballyUniqueID();
458-
lldb::SBDebugger target_debugger = target.GetDebugger();
459-
int debugger_id = target_debugger.GetID();
460-
461-
// We create an attach config that contains the debugger ID and target
462-
// ID. The new DAP instance will use these IDs to find the existing
463-
// debugger and target via FindDebuggerWithID and
464-
// FindTargetByGloballyUniqueID.
465-
llvm::json::Object attach_config;
466-
467-
attach_config.try_emplace("type", "lldb");
468-
attach_config.try_emplace("debuggerId", debugger_id);
469-
attach_config.try_emplace("targetId", target_id);
470-
const char *session_name = target.GetTargetSessionName();
471-
attach_config.try_emplace("name", session_name);
472-
473-
// 2. Construct the main 'startDebugging' request arguments.
474-
llvm::json::Object start_debugging_args{
475-
{"request", "attach"},
476-
{"configuration", std::move(attach_config)}};
477-
478-
// Send the request. Note that this is a reverse request, so you don't
479-
// expect a direct response in the same way as a client request.
454+
// Find the DAP instance that owns this target
455+
DAP *dap_instance = DAPSessionManager::FindDAP(target);
480456
// If we don't have a dap_instance (target wasn't found), get any
481457
// active instance
482458
if (!dap_instance) {
@@ -487,9 +463,22 @@ void HandleTargetEvent(const lldb::SBEvent &event, Log *log) {
487463
}
488464

489465
if (dap_instance) {
466+
// Send a startDebugging reverse request with the debugger and target
467+
// IDs. The new DAP instance will use these IDs to find the existing
468+
// debugger and target via FindDebuggerWithID and
469+
// FindTargetByGloballyUniqueID.
470+
llvm::json::Object configuration{
471+
{"type", "lldb"},
472+
{"debuggerId", target.GetDebugger().GetID()},
473+
{"targetId", target.GetGloballyUniqueID()},
474+
{"name", target.GetTargetSessionName()}};
475+
490476
dap_instance->SendReverseRequest<LogFailureResponseHandler>(
491-
"startDebugging", std::move(start_debugging_args));
477+
"startDebugging", llvm::json::Object{{"request", "attach"},
478+
{"configuration",
479+
std::move(configuration)}});
492480
}
481+
}
493482
}
494483

495484
void HandleBreakpointEvent(const lldb::SBEvent &event, Log *log) {

0 commit comments

Comments
 (0)