1 //===-- MICmnLLDBDebugger.h -------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // Third party headers
13 #include "lldb/API/SBDebugger.h"
14 #include "lldb/API/SBEvent.h"
15 #include "lldb/API/SBListener.h"
16 #include <condition_variable>
21 #include "MICmnBase.h"
22 #include "MIUtilSingletonBase.h"
23 #include "MIUtilThreadBaseStd.h"
27 class CMICmnLLDBDebuggerHandleEvents;
30 //============================================================================
31 // Details: MI proxy/adapter for the LLDB public SBDebugger API. The CMIDriver
32 // requires *this object. Command classes make calls on *this object
33 // to facilitate their work effort. The instance runs in its own worker
37 class CMICmnLLDBDebugger : public CMICmnBase,
38 public CMIUtilThreadActiveObjBase,
39 public MI::ISingleton<CMICmnLLDBDebugger> {
40 friend class MI::ISingleton<CMICmnLLDBDebugger>;
44 bool Initialize() override;
45 bool Shutdown() override;
47 bool SetDriver(const CMIDriverBase &vClientDriver);
48 CMIDriverBase &GetDriver() const;
49 lldb::SBDebugger &GetTheDebugger();
50 lldb::SBListener &GetTheListener();
51 void WaitForHandleEvent();
52 bool CheckIfNeedToRebroadcastStopEvent();
53 void RebroadcastStopEvent();
55 // MI Commands can use these functions to listen for events they require
56 bool RegisterForEvent(const CMIUtilString &vClientName,
57 const CMIUtilString &vBroadcasterClass,
58 const MIuint vEventMask);
59 bool UnregisterForEvent(const CMIUtilString &vClientName,
60 const CMIUtilString &vBroadcasterClass);
61 bool RegisterForEvent(const CMIUtilString &vClientName,
62 const lldb::SBBroadcaster &vBroadcaster,
63 const MIuint vEventMask);
64 bool UnregisterForEvent(const CMIUtilString &vClientName,
65 const lldb::SBBroadcaster &vBroadcaster);
69 // From CMIUtilThreadActiveObjBase
70 const CMIUtilString &ThreadGetName() const override;
74 // From CMIUtilThreadActiveObjBase
75 bool ThreadRun(bool &vrIsAlive) override;
76 bool ThreadFinish() override;
80 typedef std::map<CMIUtilString, MIuint> MapBroadcastClassNameToEventMask_t;
81 typedef std::pair<CMIUtilString, MIuint>
82 MapPairBroadcastClassNameToEventMask_t;
83 typedef std::map<CMIUtilString, MIuint> MapIdToEventMask_t;
84 typedef std::pair<CMIUtilString, MIuint> MapPairIdToEventMask_t;
88 /* ctor */ CMICmnLLDBDebugger();
89 /* ctor */ CMICmnLLDBDebugger(const CMICmnLLDBDebugger &);
90 void operator=(const CMICmnLLDBDebugger &);
92 bool InitSBDebugger();
93 bool InitSBListener();
94 bool InitStdStreams();
95 bool MonitorSBListenerEvents(bool &vrbYesExit);
97 bool BroadcasterGetMask(const CMIUtilString &vBroadcasterClass,
98 MIuint &vEventMask) const;
99 bool BroadcasterRemoveMask(const CMIUtilString &vBroadcasterClass);
100 bool BroadcasterSaveMask(const CMIUtilString &vBroadcasterClass,
101 const MIuint vEventMask);
104 ClientGetMaskForAllClients(const CMIUtilString &vBroadcasterClass) const;
105 bool ClientSaveMask(const CMIUtilString &vClientName,
106 const CMIUtilString &vBroadcasterClass,
107 const MIuint vEventMask);
108 bool ClientRemoveTheirMask(const CMIUtilString &vClientName,
109 const CMIUtilString &vBroadcasterClass);
110 bool ClientGetTheirMask(const CMIUtilString &vClientName,
111 const CMIUtilString &vBroadcasterClass,
112 MIuint &vwEventMask);
113 bool LoadMIFormatters(lldb::SBTypeCategory miCategory);
114 bool RegisterMISummaryProviders();
118 /* dtor */ ~CMICmnLLDBDebugger() override;
123 *m_pClientDriver; // The driver that wants to use *this LLDB debugger
124 lldb::SBDebugger m_lldbDebugger; // SBDebugger is the primordial object that
125 // creates SBTargets and provides access to
127 lldb::SBListener m_lldbListener; // API clients can register its own listener
128 // to debugger events
129 const CMIUtilString m_constStrThisThreadId;
130 MapBroadcastClassNameToEventMask_t m_mapBroadcastClassNameToEventMask;
131 MapIdToEventMask_t m_mapIdToEventMask;
132 std::mutex m_mutexEventQueue;
133 std::condition_variable m_conditionEventQueueEmpty;
134 uint32_t m_nLastStopId;