CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
120 lines
4.0 KiB
C++
120 lines
4.0 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// This file contains the declarations of the DAPSessionManager and
|
|
/// ManagedEventThread classes, which are used to multiple concurrent DAP
|
|
/// sessions in a single lldb-dap process.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLDB_TOOLS_LLDB_DAP_DAPSESSIONMANAGER_H
|
|
#define LLDB_TOOLS_LLDB_DAP_DAPSESSIONMANAGER_H
|
|
|
|
#include "lldb/API/SBBroadcaster.h"
|
|
#include "lldb/API/SBDebugger.h"
|
|
#include "lldb/API/SBTarget.h"
|
|
#include "lldb/Host/MainLoop.h"
|
|
#include "lldb/lldb-types.h"
|
|
#include "llvm/Support/Error.h"
|
|
#include <condition_variable>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <optional>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
namespace lldb_dap {
|
|
|
|
// Forward declarations
|
|
struct DAP;
|
|
|
|
class ManagedEventThread {
|
|
public:
|
|
// Constructor declaration
|
|
ManagedEventThread(lldb::SBBroadcaster broadcaster, std::thread t);
|
|
|
|
~ManagedEventThread();
|
|
|
|
ManagedEventThread(const ManagedEventThread &) = delete;
|
|
ManagedEventThread &operator=(const ManagedEventThread &) = delete;
|
|
|
|
private:
|
|
lldb::SBBroadcaster m_broadcaster;
|
|
std::thread m_event_thread;
|
|
};
|
|
|
|
/// Global DAP session manager that manages multiple concurrent DAP sessions in
|
|
/// a single lldb-dap process. Handles session lifecycle tracking, coordinates
|
|
/// shared debugger event threads, and facilitates target handoff between
|
|
/// sessions for dynamically created targets.
|
|
class DAPSessionManager {
|
|
public:
|
|
/// Get the singleton instance of the DAP session manager.
|
|
static DAPSessionManager &GetInstance();
|
|
|
|
/// Register a DAP session.
|
|
void RegisterSession(lldb_private::MainLoop *loop, DAP *dap);
|
|
|
|
/// Unregister a DAP session. Called by sessions when they complete their
|
|
/// disconnection, which unblocks WaitForAllSessionsToDisconnect().
|
|
void UnregisterSession(lldb_private::MainLoop *loop);
|
|
|
|
/// Get all active DAP sessions.
|
|
std::vector<DAP *> GetActiveSessions();
|
|
|
|
/// Disconnect all registered sessions by calling Disconnect() on
|
|
/// each and requesting their event loops to terminate. Used during
|
|
/// shutdown to force all sessions to begin disconnecting.
|
|
void DisconnectAllSessions();
|
|
|
|
/// Block until all sessions disconnect and unregister. Returns an error if
|
|
/// DisconnectAllSessions() was called and any disconnection failed.
|
|
llvm::Error WaitForAllSessionsToDisconnect();
|
|
|
|
/// Get or create event thread for a specific debugger.
|
|
std::shared_ptr<ManagedEventThread>
|
|
GetEventThreadForDebugger(lldb::SBDebugger debugger, DAP *requesting_dap);
|
|
|
|
/// Find the DAP instance that owns the given target.
|
|
DAP *FindDAPForTarget(lldb::SBTarget target);
|
|
|
|
/// Static convenience method for FindDAPForTarget.
|
|
static DAP *FindDAP(lldb::SBTarget target) {
|
|
return GetInstance().FindDAPForTarget(target);
|
|
}
|
|
|
|
/// Clean up expired event threads from the collection.
|
|
void ReleaseExpiredEventThreads();
|
|
|
|
private:
|
|
DAPSessionManager() = default;
|
|
~DAPSessionManager() = default;
|
|
|
|
// Non-copyable and non-movable.
|
|
DAPSessionManager(const DAPSessionManager &) = delete;
|
|
DAPSessionManager &operator=(const DAPSessionManager &) = delete;
|
|
DAPSessionManager(DAPSessionManager &&) = delete;
|
|
DAPSessionManager &operator=(DAPSessionManager &&) = delete;
|
|
|
|
bool m_client_failed = false;
|
|
std::mutex m_sessions_mutex;
|
|
std::condition_variable m_sessions_condition;
|
|
std::map<lldb_private::MainLoop *, DAP *> m_active_sessions;
|
|
|
|
/// Map from debugger ID to its event thread, used when multiple DAP sessions
|
|
/// share the same debugger instance.
|
|
std::map<lldb::user_id_t, std::weak_ptr<ManagedEventThread>>
|
|
m_debugger_event_threads;
|
|
};
|
|
|
|
} // namespace lldb_dap
|
|
|
|
#endif // LLDB_TOOLS_LLDB_DAP_DAPSESSIONMANAGER_H
|