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