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