| 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" |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 38 | |
| 39 | // Declarations: |
| 40 | class CMICmnLLDBDebugger; |
| 41 | struct SMICmdData; |
| 42 | class CMICmnMIValueTuple; |
| 43 | class CMICmnMIValueList; |
| 44 | |
| 45 | //++ ============================================================================ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 46 | // Details: MI debug session object that holds debugging information between |
| 47 | // instances of MI commands executing their work and producing MI |
| 48 | // result records. Information/data is set by one or many commands then |
| 49 | // retrieved by the same or other sebsequent commands. |
| 50 | // It primarily to hold LLDB type objects. |
| 51 | // A singleton class. |
| 52 | // Gotchas: None. |
| 53 | // Authors: Illya Rudkin 04/03/2014. |
| 54 | // Changes: None. |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 55 | //-- |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 56 | class CMICmnLLDBDebugSessionInfo : public CMICmnBase, public MI::ISingleton<CMICmnLLDBDebugSessionInfo> |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 57 | { |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 58 | friend class MI::ISingleton<CMICmnLLDBDebugSessionInfo>; |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 59 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 60 | // Structs: |
| 61 | public: |
| 62 | //++ ============================================================================ |
| 63 | // Details: Break point information object. Used to easily pass information about |
| 64 | // a break around and record break point information to be recalled by |
| 65 | // other commands or LLDB event handling functions. |
| 66 | //-- |
| 67 | struct SBrkPtInfo |
| 68 | { |
| 69 | SBrkPtInfo(void) |
| 70 | : m_id(0) |
| 71 | , m_bDisp(false) |
| 72 | , m_bEnabled(false) |
| 73 | , m_pc(0) |
| 74 | , m_nLine(0) |
| 75 | , m_bHaveArgOptionThreadGrp(false) |
| 76 | , m_nTimes(0) |
| 77 | , m_bPending(false) |
| 78 | , m_nIgnore(0) |
| 79 | , m_bCondition(false) |
| 80 | , m_bBrkPtThreadId(false) |
| 81 | , m_nBrkPtThreadId(0) |
| 82 | { |
| 83 | } |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 84 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 85 | MIuint m_id; // LLDB break point ID. |
| 86 | CMIUtilString m_strType; // Break point type. |
| 87 | bool m_bDisp; // True = "del", false = "keep". |
| 88 | bool m_bEnabled; // True = enabled, false = disabled break point. |
| 89 | MIuint m_pc; // Address number. |
| 90 | CMIUtilString m_fnName; // Function name. |
| 91 | CMIUtilString m_fileName; // File name text. |
| 92 | CMIUtilString m_path; // Full file name and path text. |
| 93 | MIuint m_nLine; // File line number. |
| 94 | bool m_bHaveArgOptionThreadGrp; // True = include MI field, false = do not include "thread-groups". |
| 95 | CMIUtilString m_strOptThrdGrp; // Thread group number. |
| 96 | MIuint m_nTimes; // The count of the breakpoint existence. |
| 97 | CMIUtilString m_strOrigLoc; // The name of the break point. |
| 98 | bool m_bPending; // True = the breakpoint has not been established yet, false = location found |
| 99 | MIuint m_nIgnore; // The number of time the breakpoint is run over before it is stopped on a hit |
| 100 | bool m_bCondition; // True = break point is conditional, use condition expression, false = no condition |
| 101 | CMIUtilString m_strCondition; // Break point condition expression |
| 102 | bool m_bBrkPtThreadId; // True = break point is specified to work with a specific thread, false = no specified thread given |
| 103 | MIuint m_nBrkPtThreadId; // Restrict the breakpoint to the specified thread-id |
| 104 | }; |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 105 | |
| Hafiz Abid Qadeer | 290ece8 | 2014-12-08 18:07:40 +0000 | [diff] [blame] | 106 | // Enumerations: |
| 107 | public: |
| 108 | //++ =================================================================== |
| 109 | // Details: The type of variable used by MIResponseFormVariableInfo family functions. |
| 110 | //-- |
| 111 | enum VariableType_e |
| 112 | { |
| 113 | eVariableType_InScope = (1u << 0), // In scope only. |
| 114 | eVariableType_Statics = (1u << 1), // Statics. |
| 115 | eVariableType_Locals = (1u << 2), // Locals. |
| 116 | eVariableType_Arguments = (1u << 3) // Arguments. |
| 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); |
| 150 | bool MIResponseFormVariableInfo(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, CMICmnMIValueList &vwrMiValueList); |
| 151 | bool MIResponseFormVariableInfo2(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, CMICmnMIValueList &vwrMiValueList); |
| 152 | bool MIResponseFormVariableInfo3(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, CMICmnMIValueList &vwrMiValueList); |
| 153 | bool MIResponseFormBrkPtFrameInfo(const SBrkPtInfo &vrBrkPtInfo, CMICmnMIValueTuple &vwrMiValueTuple); |
| 154 | bool MIResponseFormBrkPtInfo(const SBrkPtInfo &vrBrkPtInfo, CMICmnMIValueTuple &vwrMiValueTuple); |
| 155 | bool GetBrkPtInfo(const lldb::SBBreakpoint &vBrkPt, SBrkPtInfo &vrwBrkPtInfo) const; |
| 156 | bool RecordBrkPtInfo(const MIuint vnBrkPtId, const SBrkPtInfo &vrBrkPtInfo); |
| 157 | bool RecordBrkPtInfoGet(const MIuint vnBrkPtId, SBrkPtInfo &vrwBrkPtInfo) const; |
| 158 | bool RecordBrkPtInfoDelete(const MIuint vnBrkPtId); |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 159 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 160 | // Attributes: |
| 161 | public: |
| 162 | // The following are available to all command instances |
| 163 | lldb::SBDebugger &m_rLldbDebugger; |
| 164 | lldb::SBListener &m_rLlldbListener; |
| 165 | lldb::SBTarget m_lldbTarget; |
| 166 | lldb::SBProcess m_lldbProcess; |
| 167 | const MIuint m_nBrkPointCntMax; |
| 168 | VecActiveThreadId_t m_vecActiveThreadId; |
| 169 | lldb::tid_t m_currentSelectedThread; |
| 170 | |
| 171 | // These are keys that can be used to access the shared data map |
| 172 | // Note: This list is expected to grow and will be moved and abstracted in the future. |
| 173 | const CMIUtilString m_constStrSharedDataKeyWkDir; |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 174 | const CMIUtilString m_constStrSharedDataSolibPath; |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 175 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 176 | // Typedefs: |
| 177 | private: |
| 178 | typedef std::vector<CMICmnLLDBDebugSessionInfoVarObj> VecVarObj_t; |
| 179 | typedef std::map<MIuint, SBrkPtInfo> MapBrkPtIdToBrkPtInfo_t; |
| 180 | typedef std::pair<MIuint, SBrkPtInfo> MapPairBrkPtIdToBrkPtInfo_t; |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 181 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 182 | // Methods: |
| 183 | private: |
| 184 | /* ctor */ CMICmnLLDBDebugSessionInfo(void); |
| 185 | /* ctor */ CMICmnLLDBDebugSessionInfo(const CMICmnLLDBDebugSessionInfo &); |
| 186 | void operator=(const CMICmnLLDBDebugSessionInfo &); |
| 187 | // |
| 188 | bool GetVariableInfo(const MIuint vnMaxDepth, const lldb::SBValue &vrValue, const bool vbIsChildValue, |
| 189 | CMICmnMIValueList &vwrMiValueList, MIuint &vrwnDepth); |
| 190 | bool GetVariableInfo2(const MIuint vnMaxDepth, const lldb::SBValue &vrValue, const bool vbIsChildValue, |
| 191 | CMICmnMIValueList &vwrMiValueList, MIuint &vrwnDepth); |
| 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; |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 203 | }; |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 204 | |
| 205 | //++ ------------------------------------------------------------------------------------ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 206 | // Details: Command instances can create and share data between other instances of commands. |
| 207 | // This function adds new data to the shared data. Using the same ID more than |
| 208 | // once replaces any previous matching data keys. |
| 209 | // Type: Template method. |
| 210 | // Args: T - The type of the object to be stored. |
| 211 | // vKey - (R) A non empty unique data key to retrieve the data by. |
| 212 | // vData - (R) Data to be added to the share. |
| 213 | // Return: MIstatus::success - Functional succeeded. |
| 214 | // MIstatus::failure - Functional failed. |
| 215 | // Throws: None. |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 216 | //-- |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 217 | template <typename T> |
| 218 | bool |
| 219 | CMICmnLLDBDebugSessionInfo::SharedDataAdd(const CMIUtilString &vKey, const T &vData) |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 220 | { |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 221 | if (!m_mapIdToSessionData.Add<T>(vKey, vData)) |
| 222 | { |
| 223 | SetErrorDescription(m_mapIdToSessionData.GetErrorDescription()); |
| 224 | return MIstatus::failure; |
| 225 | } |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 226 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 227 | return MIstatus::success; |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | //++ ------------------------------------------------------------------------------------ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 231 | // Details: Command instances can create and share data between other instances of commands. |
| 232 | // This function retrieves data from the shared data container. |
| 233 | // Type: Method. |
| 234 | // Args: T - The type of the object being retrieved. |
| 235 | // vKey - (R) A non empty unique data key to retrieve the data by. |
| 236 | // vData - (W) The data. |
| 237 | // Return: bool - True = data found, false = data not found or an error occurred trying to fetch. |
| 238 | // Throws: None. |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 239 | //-- |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 240 | template <typename T> |
| 241 | bool |
| 242 | CMICmnLLDBDebugSessionInfo::SharedDataRetrieve(const CMIUtilString &vKey, T &vwData) |
| 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 | bool bDataFound = false; |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 245 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 246 | if (!m_mapIdToSessionData.Get<T>(vKey, vwData, bDataFound)) |
| 247 | { |
| 248 | SetErrorDescription(m_mapIdToSessionData.GetErrorDescription()); |
| 249 | return MIstatus::failure; |
| 250 | } |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 251 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 252 | return bDataFound; |
| 253 | } |