@@ -72,10 +72,29 @@ class DAPSessionManager {
7272 llvm::Error WaitForAllSessionsToDisconnect ();
7373
7474 // / Store a target for later retrieval by another session.
75- void StoreTargetById (uint32_t target_id, lldb::SBTarget target);
75+ // /
76+ // / When a new target is dynamically created (e.g., via scripting hooks or
77+ // / child process debugging), it needs to be handed off to a new DAP session.
78+ // / This method stores the target in a temporary map using its globally unique
79+ // / ID so that the new session can retrieve it via TakeTargetById().
80+ // /
81+ // / \param target_id The globally unique ID of the target (from
82+ // / SBTarget::GetGloballyUniqueID()).
83+ // / \param target The target to store.
84+ void StoreTargetById (lldb::user_id_t target_id, lldb::SBTarget target);
7685
7786 // / Retrieve and remove a stored target by its globally unique target ID.
78- std::optional<lldb::SBTarget> TakeTargetById (uint32_t target_id);
87+ // /
88+ // / This method is called during the attach request when a new DAP session
89+ // / wants to attach to a dynamically created target. The target is removed
90+ // / from the map after retrieval because:
91+ // / 1. Each target should only be attached to by one DAP session
92+ // / 2. Once attached, the DAP session takes ownership of the target
93+ // / 3. Keeping the target in the map would prevent proper cleanup
94+ // /
95+ // / \param target_id The globally unique ID of the target to retrieve.
96+ // / \return The target if found, std::nullopt otherwise.
97+ std::optional<lldb::SBTarget> TakeTargetById (lldb::user_id_t target_id);
7998
8099 // / Get or create event thread for a specific debugger.
81100 std::shared_ptr<ManagedEventThread>
@@ -112,7 +131,7 @@ class DAPSessionManager {
112131
113132 // / Map from target ID to target for handing off newly created targets
114133 // / between sessions.
115- std::map<uint32_t , lldb::SBTarget> m_target_map;
134+ std::map<lldb:: user_id_t , lldb::SBTarget> m_target_map;
116135
117136 // / Map from debugger ID to its event thread, used when multiple DAP sessions
118137 // / share the same debugger instance.
0 commit comments