2014-05-16 18:51:01 +08:00
|
|
|
//===-- MICmnLLDBDebugger.h -------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// Third party headers
|
2015-05-07 14:45:42 +08:00
|
|
|
#include <condition_variable>
|
2014-05-16 18:51:01 +08:00
|
|
|
#include <map>
|
2015-05-07 14:45:42 +08:00
|
|
|
#include <mutex>
|
2015-01-20 08:04:26 +08:00
|
|
|
#include "lldb/API/SBDebugger.h"
|
|
|
|
#include "lldb/API/SBListener.h"
|
|
|
|
#include "lldb/API/SBEvent.h"
|
2014-05-16 18:51:01 +08:00
|
|
|
|
|
|
|
// In-house headers:
|
|
|
|
#include "MICmnBase.h"
|
|
|
|
#include "MIUtilThreadBaseStd.h"
|
|
|
|
#include "MIUtilSingletonBase.h"
|
|
|
|
|
|
|
|
// Declarations:
|
|
|
|
class CMIDriverBase;
|
|
|
|
class CMICmnLLDBDebuggerHandleEvents;
|
|
|
|
|
|
|
|
//++ ============================================================================
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: MI proxy/adapter for the LLDB public SBDebugger API. The CMIDriver
|
|
|
|
// requires *this object. Command classes make calls on *this object
|
|
|
|
// to facilitate their work effort. The instance runs in its own worker
|
|
|
|
// thread.
|
|
|
|
// A singleton class.
|
|
|
|
// Gotchas: None.
|
|
|
|
// Authors: Illya Rudkin 26/02/2014.
|
|
|
|
// Changes: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2014-11-18 02:06:21 +08:00
|
|
|
class CMICmnLLDBDebugger : public CMICmnBase, public CMIUtilThreadActiveObjBase, public MI::ISingleton<CMICmnLLDBDebugger>
|
2014-05-16 18:51:01 +08:00
|
|
|
{
|
2014-11-18 02:06:21 +08:00
|
|
|
friend class MI::ISingleton<CMICmnLLDBDebugger>;
|
|
|
|
|
|
|
|
// Methods:
|
|
|
|
public:
|
2015-07-06 23:48:55 +08:00
|
|
|
bool Initialize(void) override;
|
|
|
|
bool Shutdown(void) override;
|
2014-11-18 02:06:21 +08:00
|
|
|
|
|
|
|
bool SetDriver(const CMIDriverBase &vClientDriver);
|
|
|
|
CMIDriverBase &GetDriver(void) const;
|
|
|
|
lldb::SBDebugger &GetTheDebugger(void);
|
|
|
|
lldb::SBListener &GetTheListener(void);
|
2015-05-07 14:45:42 +08:00
|
|
|
void WaitForHandleEvent(void);
|
2015-05-20 18:15:47 +08:00
|
|
|
bool CheckIfNeedToRebroadcastStopEvent(void);
|
|
|
|
void RebroadcastStopEvent(void);
|
2014-11-18 02:06:21 +08:00
|
|
|
|
|
|
|
// MI Commands can use these functions to listen for events they require
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Overridden:
|
|
|
|
public:
|
|
|
|
// From CMIUtilThreadActiveObjBase
|
2015-07-06 23:48:55 +08:00
|
|
|
const CMIUtilString &ThreadGetName(void) const override;
|
2014-11-18 02:06:21 +08:00
|
|
|
|
|
|
|
// Overridden:
|
|
|
|
protected:
|
|
|
|
// From CMIUtilThreadActiveObjBase
|
2015-07-06 23:48:55 +08:00
|
|
|
bool ThreadRun(bool &vrIsAlive) override;
|
|
|
|
bool ThreadFinish(void) override;
|
2014-11-18 02:06:21 +08:00
|
|
|
|
|
|
|
// Typedefs:
|
|
|
|
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;
|
2014-05-16 18:51:01 +08:00
|
|
|
|
2014-11-18 02:06:21 +08:00
|
|
|
// Methods:
|
|
|
|
private:
|
|
|
|
/* ctor */ CMICmnLLDBDebugger(void);
|
|
|
|
/* ctor */ CMICmnLLDBDebugger(const CMICmnLLDBDebugger &);
|
|
|
|
void operator=(const CMICmnLLDBDebugger &);
|
|
|
|
|
|
|
|
bool InitSBDebugger(void);
|
|
|
|
bool InitSBListener(void);
|
|
|
|
bool InitStdStreams(void);
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Overridden:
|
|
|
|
private:
|
|
|
|
// From CMICmnBase
|
2015-07-06 23:48:55 +08:00
|
|
|
/* dtor */ ~CMICmnLLDBDebugger(void) override;
|
2014-11-18 02:06:21 +08:00
|
|
|
|
|
|
|
// Attributes:
|
|
|
|
private:
|
|
|
|
CMIDriverBase *m_pClientDriver; // The driver that wants to use *this LLDB debugger
|
|
|
|
lldb::SBDebugger m_lldbDebugger; // SBDebugger is the primordial object that creates SBTargets and provides access to them
|
|
|
|
lldb::SBListener m_lldbListener; // API clients can register its own listener to debugger events
|
|
|
|
const CMIUtilString m_constStrThisThreadId;
|
|
|
|
MapBroadcastClassNameToEventMask_t m_mapBroadcastClassNameToEventMask;
|
|
|
|
MapIdToEventMask_t m_mapIdToEventMask;
|
2015-05-07 14:45:42 +08:00
|
|
|
std::mutex m_mutexEventQueue;
|
|
|
|
std::condition_variable m_conditionEventQueueEmpty;
|
2015-05-20 18:15:47 +08:00
|
|
|
uint32_t m_nLastStopId;
|
2014-11-18 02:06:21 +08:00
|
|
|
};
|