#pragma once
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBEvent.h"
#include "lldb/API/SBListener.h"
#include <condition_variable>
#include <map>
#include <mutex>
#include "MICmnBase.h"
#include "MIUtilSingletonBase.h"
#include "MIUtilThreadBaseStd.h"
class CMIDriverBase;
class CMICmnLLDBDebuggerHandleEvents;
class CMICmnLLDBDebugger : public CMICmnBase,
public CMIUtilThreadActiveObjBase,
public MI::ISingleton<CMICmnLLDBDebugger> {
friend class MI::ISingleton<CMICmnLLDBDebugger>;
public:
bool Initialize() override;
bool Shutdown() override;
bool SetDriver(const CMIDriverBase &vClientDriver);
CMIDriverBase &GetDriver() const;
lldb::SBDebugger &GetTheDebugger();
lldb::SBListener &GetTheListener();
void WaitForHandleEvent();
bool CheckIfNeedToRebroadcastStopEvent();
void RebroadcastStopEvent();
bool RegisterForEvent(const CMIUtilString &vClientName,
const CMIUtilString &vBroadcasterClass,
const MIuint vEventMask);
bool UnregisterForEvent(const CMIUtilString &vClientName,
const CMIUtilString &vBroadcasterClass);
bool RegisterForEvent(const CMIUtilString &vClientName,
const lldb::SBBroadcaster &vBroadcaster,
const MIuint vEventMask);
bool UnregisterForEvent(const CMIUtilString &vClientName,
const lldb::SBBroadcaster &vBroadcaster);
public:
const CMIUtilString &ThreadGetName() const override;
protected:
bool ThreadRun(bool &vrIsAlive) override;
bool ThreadFinish() override;
private:
typedef std::map<CMIUtilString, MIuint> MapBroadcastClassNameToEventMask_t;
typedef std::pair<CMIUtilString, MIuint>
MapPairBroadcastClassNameToEventMask_t;
typedef std::map<CMIUtilString, MIuint> MapIdToEventMask_t;
typedef std::pair<CMIUtilString, MIuint> MapPairIdToEventMask_t;
private:
CMICmnLLDBDebugger();
CMICmnLLDBDebugger(const CMICmnLLDBDebugger &);
void operator=(const CMICmnLLDBDebugger &);
bool InitSBDebugger();
bool InitSBListener();
bool InitStdStreams();
bool MonitorSBListenerEvents(bool &vrbYesExit);
bool BroadcasterGetMask(const CMIUtilString &vBroadcasterClass,
MIuint &vEventMask) const;
bool BroadcasterRemoveMask(const CMIUtilString &vBroadcasterClass);
bool BroadcasterSaveMask(const CMIUtilString &vBroadcasterClass,
const MIuint vEventMask);
MIuint
ClientGetMaskForAllClients(const CMIUtilString &vBroadcasterClass) const;
bool ClientSaveMask(const CMIUtilString &vClientName,
const CMIUtilString &vBroadcasterClass,
const MIuint vEventMask);
bool ClientRemoveTheirMask(const CMIUtilString &vClientName,
const CMIUtilString &vBroadcasterClass);
bool ClientGetTheirMask(const CMIUtilString &vClientName,
const CMIUtilString &vBroadcasterClass,
MIuint &vwEventMask);
bool LoadMIFormatters(lldb::SBTypeCategory miCategory);
bool RegisterMISummaryProviders();
private:
~CMICmnLLDBDebugger() override;
private:
CMIDriverBase
*m_pClientDriver;
lldb::SBDebugger m_lldbDebugger;
lldb::SBListener m_lldbListener;
const CMIUtilString m_constStrThisThreadId;
MapBroadcastClassNameToEventMask_t m_mapBroadcastClassNameToEventMask;
MapIdToEventMask_t m_mapIdToEventMask;
std::mutex m_mutexEventQueue;
std::condition_variable m_conditionEventQueueEmpty;
uint32_t m_nLastStopId;
};