| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 1 | //===-- MICmnLLDBDebugSessionInfo.h -----------------------------*- C++ -*-===// | 
|  | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
|  | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
|  | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 |  | 
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 10 | #pragma once | 
|  | 11 |  | 
|  | 12 | // Third party headers: | 
|  | 13 | #include <map> | 
|  | 14 | #include <vector> | 
| Greg Clayton | ee3626e | 2015-01-20 00:04:26 +0000 | [diff] [blame] | 15 | #include "lldb/API/SBDebugger.h" | 
|  | 16 | #include "lldb/API/SBListener.h" | 
|  | 17 | #include "lldb/API/SBProcess.h" | 
|  | 18 | #include "lldb/API/SBTarget.h" | 
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 19 |  | 
|  | 20 | // In-house headers: | 
|  | 21 | #include "MICmnBase.h" | 
|  | 22 | #include "MIUtilSingletonBase.h" | 
|  | 23 | #include "MICmnLLDBDebugSessionInfoVarObj.h" | 
|  | 24 | #include "MICmnMIValueTuple.h" | 
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 25 | #include "MIUtilMapIdToVariant.h" | 
| Hafiz Abid Qadeer | d1f606f | 2015-02-04 09:59:23 +0000 | [diff] [blame] | 26 | #include "MIUtilThreadBaseStd.h" | 
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 27 |  | 
|  | 28 | // Declarations: | 
|  | 29 | class CMICmnLLDBDebugger; | 
|  | 30 | struct SMICmdData; | 
|  | 31 | class CMICmnMIValueTuple; | 
|  | 32 | class CMICmnMIValueList; | 
|  | 33 |  | 
|  | 34 | //++ ============================================================================ | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 35 | // Details: MI debug session object that holds debugging information between | 
|  | 36 | //          instances of MI commands executing their work and producing MI | 
|  | 37 | //          result records. Information/data is set by one or many commands then | 
|  | 38 | //          retrieved by the same or other sebsequent commands. | 
|  | 39 | //          It primarily to hold LLDB type objects. | 
|  | 40 | //          A singleton class. | 
|  | 41 | // Gotchas: None. | 
|  | 42 | // Authors: Illya Rudkin 04/03/2014. | 
|  | 43 | // Changes: None. | 
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 44 | //-- | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 45 | class CMICmnLLDBDebugSessionInfo : public CMICmnBase, public MI::ISingleton<CMICmnLLDBDebugSessionInfo> | 
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 46 | { | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 47 | friend class MI::ISingleton<CMICmnLLDBDebugSessionInfo>; | 
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 48 |  | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 49 | // Structs: | 
|  | 50 | public: | 
|  | 51 | //++ ============================================================================ | 
|  | 52 | // Details: Break point information object. Used to easily pass information about | 
|  | 53 | //          a break around and record break point information to be recalled by | 
|  | 54 | //          other commands or LLDB event handling functions. | 
|  | 55 | //-- | 
|  | 56 | struct SBrkPtInfo | 
|  | 57 | { | 
|  | 58 | SBrkPtInfo(void) | 
|  | 59 | : m_id(0) | 
|  | 60 | , m_bDisp(false) | 
|  | 61 | , m_bEnabled(false) | 
|  | 62 | , m_pc(0) | 
|  | 63 | , m_nLine(0) | 
|  | 64 | , m_bHaveArgOptionThreadGrp(false) | 
|  | 65 | , m_nTimes(0) | 
|  | 66 | , m_bPending(false) | 
|  | 67 | , m_nIgnore(0) | 
|  | 68 | , m_bCondition(false) | 
|  | 69 | , m_bBrkPtThreadId(false) | 
|  | 70 | , m_nBrkPtThreadId(0) | 
|  | 71 | { | 
|  | 72 | } | 
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 73 |  | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 74 | MIuint m_id;                    // LLDB break point ID. | 
|  | 75 | CMIUtilString m_strType;        // Break point type. | 
|  | 76 | bool m_bDisp;                   // True = "del", false = "keep". | 
|  | 77 | bool m_bEnabled;                // True = enabled, false = disabled break point. | 
| Ilia K | 7690fc5 | 2015-03-19 17:27:23 +0000 | [diff] [blame] | 78 | lldb::addr_t m_pc;              // Address number. | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 79 | CMIUtilString m_fnName;         // Function name. | 
|  | 80 | CMIUtilString m_fileName;       // File name text. | 
|  | 81 | CMIUtilString m_path;           // Full file name and path text. | 
|  | 82 | MIuint m_nLine;                 // File line number. | 
|  | 83 | bool m_bHaveArgOptionThreadGrp; // True = include MI field, false = do not include "thread-groups". | 
|  | 84 | CMIUtilString m_strOptThrdGrp;  // Thread group number. | 
|  | 85 | MIuint m_nTimes;                // The count of the breakpoint existence. | 
|  | 86 | CMIUtilString m_strOrigLoc;     // The name of the break point. | 
|  | 87 | bool m_bPending;                // True = the breakpoint has not been established yet, false = location found | 
|  | 88 | MIuint m_nIgnore;               // The number of time the breakpoint is run over before it is stopped on a hit | 
|  | 89 | bool m_bCondition;              // True = break point is conditional, use condition expression, false = no condition | 
|  | 90 | CMIUtilString m_strCondition;   // Break point condition expression | 
|  | 91 | bool m_bBrkPtThreadId;          // True = break point is specified to work with a specific thread, false = no specified thread given | 
|  | 92 | MIuint m_nBrkPtThreadId;        // Restrict the breakpoint to the specified thread-id | 
|  | 93 | }; | 
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 94 |  | 
| Hafiz Abid Qadeer | 290ece8 | 2014-12-08 18:07:40 +0000 | [diff] [blame] | 95 | // Enumerations: | 
|  | 96 | public: | 
|  | 97 | //++ =================================================================== | 
|  | 98 | // Details: The type of variable used by MIResponseFormVariableInfo family functions. | 
|  | 99 | //-- | 
|  | 100 | enum VariableType_e | 
|  | 101 | { | 
|  | 102 | eVariableType_InScope   = (1u << 0), // In scope only. | 
|  | 103 | eVariableType_Statics   = (1u << 1), // Statics. | 
|  | 104 | eVariableType_Locals    = (1u << 2), // Locals. | 
|  | 105 | eVariableType_Arguments = (1u << 3)  // Arguments. | 
|  | 106 | }; | 
|  | 107 |  | 
| Ilia K | 1a0ec0f | 2015-02-06 18:08:24 +0000 | [diff] [blame] | 108 | //++ =================================================================== | 
|  | 109 | // Details: Determine the information that should be shown by using MIResponseFormVariableInfo family functions. | 
|  | 110 | //-- | 
|  | 111 | enum VariableInfoFormat_e | 
|  | 112 | { | 
|  | 113 | eVariableInfoFormat_NoValues, | 
|  | 114 | eVariableInfoFormat_AllValues, | 
|  | 115 | eVariableInfoFormat_SimpleValues, | 
|  | 116 | kNumVariableInfoFormats | 
|  | 117 | }; | 
|  | 118 |  | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 119 | // Typedefs: | 
|  | 120 | public: | 
|  | 121 | typedef std::vector<uint32_t> VecActiveThreadId_t; | 
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 122 |  | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 123 | // Methods: | 
|  | 124 | public: | 
|  | 125 | bool Initialize(void); | 
|  | 126 | bool Shutdown(void); | 
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 127 |  | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 128 | // Variant type data which can be assigned and retrieved across all command instances | 
|  | 129 | template <typename T> bool SharedDataAdd(const CMIUtilString &vKey, const T &vData); | 
|  | 130 | template <typename T> bool SharedDataRetrieve(const CMIUtilString &vKey, T &vwData); | 
|  | 131 | bool SharedDataDestroy(void); | 
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 132 |  | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 133 | //  Common command required functionality | 
|  | 134 | bool AccessPath(const CMIUtilString &vPath, bool &vwbYesAccessible); | 
|  | 135 | bool GetFrameInfo(const lldb::SBFrame &vrFrame, lldb::addr_t &vwPc, CMIUtilString &vwFnName, CMIUtilString &vwFileName, | 
|  | 136 | CMIUtilString &vwPath, MIuint &vwnLine); | 
|  | 137 | bool GetThreadFrames(const SMICmdData &vCmdData, const MIuint vThreadIdx, CMIUtilString &vwrThreadFrames); | 
|  | 138 | bool GetThreadFrames2(const SMICmdData &vCmdData, const MIuint vThreadIdx, CMIUtilString &vwrThreadFrames); | 
|  | 139 | bool ResolvePath(const SMICmdData &vCmdData, const CMIUtilString &vPath, CMIUtilString &vwrResolvedPath); | 
|  | 140 | bool ResolvePath(const CMIUtilString &vstrUnknown, CMIUtilString &vwrResolvedPath); | 
|  | 141 | bool MIResponseFormFrameInfo(const lldb::SBThread &vrThread, const MIuint vnLevel, CMICmnMIValueTuple &vwrMiValueTuple); | 
|  | 142 | bool MIResponseFormFrameInfo(const lldb::addr_t vPc, const CMIUtilString &vFnName, const CMIUtilString &vFileName, | 
|  | 143 | const CMIUtilString &vPath, const MIuint vnLine, CMICmnMIValueTuple &vwrMiValueTuple); | 
|  | 144 | bool MIResponseFormFrameInfo2(const lldb::addr_t vPc, const CMIUtilString &vArgInfo, const CMIUtilString &vFnName, | 
|  | 145 | const CMIUtilString &vFileName, const CMIUtilString &vPath, const MIuint vnLine, | 
|  | 146 | CMICmnMIValueTuple &vwrMiValueTuple); | 
|  | 147 | bool MIResponseFormThreadInfo(const SMICmdData &vCmdData, const lldb::SBThread &vrThread, CMICmnMIValueTuple &vwrMIValueTuple); | 
|  | 148 | bool MIResponseFormThreadInfo2(const SMICmdData &vCmdData, const lldb::SBThread &vrThread, CMICmnMIValueTuple &vwrMIValueTuple); | 
|  | 149 | bool MIResponseFormThreadInfo3(const SMICmdData &vCmdData, const lldb::SBThread &vrThread, CMICmnMIValueTuple &vwrMIValueTuple); | 
| Ilia K | 1a0ec0f | 2015-02-06 18:08:24 +0000 | [diff] [blame] | 150 | bool MIResponseFormVariableInfo(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, | 
|  | 151 | const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList); | 
|  | 152 | bool MIResponseFormVariableInfo2(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, | 
|  | 153 | const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList); | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 154 | bool MIResponseFormBrkPtFrameInfo(const SBrkPtInfo &vrBrkPtInfo, CMICmnMIValueTuple &vwrMiValueTuple); | 
|  | 155 | bool MIResponseFormBrkPtInfo(const SBrkPtInfo &vrBrkPtInfo, CMICmnMIValueTuple &vwrMiValueTuple); | 
|  | 156 | bool GetBrkPtInfo(const lldb::SBBreakpoint &vBrkPt, SBrkPtInfo &vrwBrkPtInfo) const; | 
|  | 157 | bool RecordBrkPtInfo(const MIuint vnBrkPtId, const SBrkPtInfo &vrBrkPtInfo); | 
|  | 158 | bool RecordBrkPtInfoGet(const MIuint vnBrkPtId, SBrkPtInfo &vrwBrkPtInfo) const; | 
|  | 159 | bool RecordBrkPtInfoDelete(const MIuint vnBrkPtId); | 
| Hafiz Abid Qadeer | d1f606f | 2015-02-04 09:59:23 +0000 | [diff] [blame] | 160 | CMIUtilThreadMutex& GetSessionMutex() { return m_sessionMutex;} | 
| Hafiz Abid Qadeer | 0d51c15 | 2015-02-03 10:05:54 +0000 | [diff] [blame] | 161 | lldb::SBDebugger &GetDebugger() const; | 
|  | 162 | lldb::SBListener &GetListener() const; | 
|  | 163 | lldb::SBTarget GetTarget() const; | 
|  | 164 | lldb::SBProcess GetProcess() const; | 
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 165 |  | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 166 | // Attributes: | 
|  | 167 | public: | 
|  | 168 | // The following are available to all command instances | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 169 | const MIuint m_nBrkPointCntMax; | 
|  | 170 | VecActiveThreadId_t m_vecActiveThreadId; | 
|  | 171 | lldb::tid_t m_currentSelectedThread; | 
|  | 172 |  | 
|  | 173 | // These are keys that can be used to access the shared data map | 
|  | 174 | // Note: This list is expected to grow and will be moved and abstracted in the future. | 
|  | 175 | const CMIUtilString m_constStrSharedDataKeyWkDir; | 
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 176 | const CMIUtilString m_constStrSharedDataSolibPath; | 
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 177 |  | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 178 | // Typedefs: | 
|  | 179 | private: | 
|  | 180 | typedef std::vector<CMICmnLLDBDebugSessionInfoVarObj> VecVarObj_t; | 
|  | 181 | typedef std::map<MIuint, SBrkPtInfo> MapBrkPtIdToBrkPtInfo_t; | 
|  | 182 | typedef std::pair<MIuint, SBrkPtInfo> MapPairBrkPtIdToBrkPtInfo_t; | 
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 183 |  | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 184 | // Methods: | 
|  | 185 | private: | 
|  | 186 | /* ctor */ CMICmnLLDBDebugSessionInfo(void); | 
|  | 187 | /* ctor */ CMICmnLLDBDebugSessionInfo(const CMICmnLLDBDebugSessionInfo &); | 
|  | 188 | void operator=(const CMICmnLLDBDebugSessionInfo &); | 
|  | 189 | // | 
|  | 190 | bool GetVariableInfo(const MIuint vnMaxDepth, const lldb::SBValue &vrValue, const bool vbIsChildValue, | 
| Hafiz Abid Qadeer | 095b128 | 2015-02-13 11:53:50 +0000 | [diff] [blame] | 191 | const MIuint vnDepth, CMICmnMIValueList &vwrMiValueList); | 
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 192 |  | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 193 | // Overridden: | 
|  | 194 | private: | 
|  | 195 | // From CMICmnBase | 
|  | 196 | /* dtor */ virtual ~CMICmnLLDBDebugSessionInfo(void); | 
|  | 197 |  | 
|  | 198 | // Attributes: | 
|  | 199 | private: | 
|  | 200 | CMIUtilMapIdToVariant m_mapIdToSessionData; // Hold and retrieve key to value data available across all commands | 
|  | 201 | VecVarObj_t m_vecVarObj;                    // Vector of session variable objects | 
|  | 202 | MapBrkPtIdToBrkPtInfo_t m_mapBrkPtIdToBrkPtInfo; | 
| Hafiz Abid Qadeer | d1f606f | 2015-02-04 09:59:23 +0000 | [diff] [blame] | 203 | CMIUtilThreadMutex m_sessionMutex; | 
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 204 | }; | 
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 205 |  | 
|  | 206 | //++ ------------------------------------------------------------------------------------ | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 207 | // Details: Command instances can create and share data between other instances of commands. | 
|  | 208 | //          This function adds new data to the shared data. Using the same ID more than | 
|  | 209 | //          once replaces any previous matching data keys. | 
|  | 210 | // Type:    Template method. | 
|  | 211 | // Args:    T       - The type of the object to be stored. | 
|  | 212 | //          vKey    - (R) A non empty unique data key to retrieve the data by. | 
|  | 213 | //          vData   - (R) Data to be added to the share. | 
|  | 214 | // Return:  MIstatus::success - Functional succeeded. | 
|  | 215 | //          MIstatus::failure - Functional failed. | 
|  | 216 | // Throws:  None. | 
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 217 | //-- | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 218 | template <typename T> | 
|  | 219 | bool | 
|  | 220 | CMICmnLLDBDebugSessionInfo::SharedDataAdd(const CMIUtilString &vKey, const T &vData) | 
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 221 | { | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 222 | if (!m_mapIdToSessionData.Add<T>(vKey, vData)) | 
|  | 223 | { | 
|  | 224 | SetErrorDescription(m_mapIdToSessionData.GetErrorDescription()); | 
|  | 225 | return MIstatus::failure; | 
|  | 226 | } | 
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 227 |  | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 228 | return MIstatus::success; | 
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 229 | } | 
|  | 230 |  | 
|  | 231 | //++ ------------------------------------------------------------------------------------ | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 232 | // Details: Command instances can create and share data between other instances of commands. | 
|  | 233 | //          This function retrieves data from the shared data container. | 
|  | 234 | // Type:    Method. | 
|  | 235 | // Args:    T     - The type of the object being retrieved. | 
|  | 236 | //          vKey  - (R) A non empty unique data key to retrieve the data by. | 
|  | 237 | //          vData - (W) The data. | 
|  | 238 | // Return:  bool  - True = data found, false = data not found or an error occurred trying to fetch. | 
|  | 239 | // Throws:  None. | 
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 240 | //-- | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 241 | template <typename T> | 
|  | 242 | bool | 
|  | 243 | CMICmnLLDBDebugSessionInfo::SharedDataRetrieve(const CMIUtilString &vKey, T &vwData) | 
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 244 | { | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 245 | bool bDataFound = false; | 
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 246 |  | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 247 | if (!m_mapIdToSessionData.Get<T>(vKey, vwData, bDataFound)) | 
|  | 248 | { | 
|  | 249 | SetErrorDescription(m_mapIdToSessionData.GetErrorDescription()); | 
|  | 250 | return MIstatus::failure; | 
|  | 251 | } | 
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 252 |  | 
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 253 | return bDataFound; | 
|  | 254 | } |