blob: 94205956ff40d3b23fce6a702e4807f636e23e7c [file] [log] [blame]
Deepak Panickal6f9c4682014-05-16 10:51:01 +00001//===-- 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 Panickal6f9c4682014-05-16 10:51:01 +000010#pragma once
11
12// Third party headers:
13#include <map>
14#include <vector>
Greg Claytonee3626e2015-01-20 00:04:26 +000015#include "lldb/API/SBDebugger.h"
16#include "lldb/API/SBListener.h"
17#include "lldb/API/SBProcess.h"
18#include "lldb/API/SBTarget.h"
Deepak Panickal6f9c4682014-05-16 10:51:01 +000019
20// In-house headers:
21#include "MICmnBase.h"
22#include "MIUtilSingletonBase.h"
23#include "MICmnLLDBDebugSessionInfoVarObj.h"
24#include "MICmnMIValueTuple.h"
Deepak Panickal877569c2014-06-24 16:35:50 +000025#include "MIUtilMapIdToVariant.h"
Hafiz Abid Qadeerd1f606f2015-02-04 09:59:23 +000026#include "MIUtilThreadBaseStd.h"
Deepak Panickal6f9c4682014-05-16 10:51:01 +000027
28// Declarations:
29class CMICmnLLDBDebugger;
30struct SMICmdData;
31class CMICmnMIValueTuple;
32class CMICmnMIValueList;
33
34//++ ============================================================================
Zachary Turner1d6af022014-11-17 18:06:21 +000035// 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 Panickal6f9c4682014-05-16 10:51:01 +000044//--
Zachary Turner1d6af022014-11-17 18:06:21 +000045class CMICmnLLDBDebugSessionInfo : public CMICmnBase, public MI::ISingleton<CMICmnLLDBDebugSessionInfo>
Deepak Panickal6f9c4682014-05-16 10:51:01 +000046{
Zachary Turner1d6af022014-11-17 18:06:21 +000047 friend class MI::ISingleton<CMICmnLLDBDebugSessionInfo>;
Deepak Panickal6f9c4682014-05-16 10:51:01 +000048
Zachary Turner1d6af022014-11-17 18:06:21 +000049 // 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 Panickal877569c2014-06-24 16:35:50 +000073
Zachary Turner1d6af022014-11-17 18:06:21 +000074 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 K7690fc52015-03-19 17:27:23 +000078 lldb::addr_t m_pc; // Address number.
Zachary Turner1d6af022014-11-17 18:06:21 +000079 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 Panickal877569c2014-06-24 16:35:50 +000094
Hafiz Abid Qadeer290ece82014-12-08 18:07:40 +000095 // 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 K1a0ec0f2015-02-06 18:08:24 +0000108 //++ ===================================================================
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
Ilia K58627322015-04-09 11:17:54 +0000119 //++ ===================================================================
120 // Details: Determine the information that should be shown by using MIResponseFormThreadInfo family functions.
121 //--
122 enum ThreadInfoFormat_e
123 {
124 eThreadInfoFormat_NoFrames,
125 eThreadInfoFormat_AllFrames
126 };
127
128 //++ ===================================================================
129 // Details: Determine the information that should be shown by using MIResponseFormFrameInfo family functions.
130 //--
131 enum FrameInfoFormat_e
132 {
133 eFrameInfoFormat_NoArguments,
134 eFrameInfoFormat_AllArguments,
135 eFrameInfoFormat_AllArgumentsInSimpleForm
136 };
137
Zachary Turner1d6af022014-11-17 18:06:21 +0000138 // Typedefs:
139 public:
140 typedef std::vector<uint32_t> VecActiveThreadId_t;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000141
Zachary Turner1d6af022014-11-17 18:06:21 +0000142 // Methods:
143 public:
144 bool Initialize(void);
145 bool Shutdown(void);
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000146
Zachary Turner1d6af022014-11-17 18:06:21 +0000147 // Variant type data which can be assigned and retrieved across all command instances
148 template <typename T> bool SharedDataAdd(const CMIUtilString &vKey, const T &vData);
149 template <typename T> bool SharedDataRetrieve(const CMIUtilString &vKey, T &vwData);
150 bool SharedDataDestroy(void);
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000151
Zachary Turner1d6af022014-11-17 18:06:21 +0000152 // Common command required functionality
153 bool AccessPath(const CMIUtilString &vPath, bool &vwbYesAccessible);
Zachary Turner1d6af022014-11-17 18:06:21 +0000154 bool ResolvePath(const SMICmdData &vCmdData, const CMIUtilString &vPath, CMIUtilString &vwrResolvedPath);
155 bool ResolvePath(const CMIUtilString &vstrUnknown, CMIUtilString &vwrResolvedPath);
Ilia K58627322015-04-09 11:17:54 +0000156 bool MIResponseFormFrameInfo(const lldb::SBThread &vrThread, const MIuint vnLevel,
157 const FrameInfoFormat_e veFrameInfoFormat, CMICmnMIValueTuple &vwrMiValueTuple);
158 bool MIResponseFormThreadInfo(const SMICmdData &vCmdData, const lldb::SBThread &vrThread,
159 const ThreadInfoFormat_e veThreadInfoFormat, CMICmnMIValueTuple &vwrMIValueTuple);
Ilia K1a0ec0f2015-02-06 18:08:24 +0000160 bool MIResponseFormVariableInfo(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes,
Ilia K58627322015-04-09 11:17:54 +0000161 const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList,
Hafiz Abid Qadeerfda237d2015-04-29 08:18:41 +0000162 const MIuint vnMaxDepth = 10, const bool vbMarkArgs = false);
Zachary Turner1d6af022014-11-17 18:06:21 +0000163 bool MIResponseFormBrkPtFrameInfo(const SBrkPtInfo &vrBrkPtInfo, CMICmnMIValueTuple &vwrMiValueTuple);
164 bool MIResponseFormBrkPtInfo(const SBrkPtInfo &vrBrkPtInfo, CMICmnMIValueTuple &vwrMiValueTuple);
165 bool GetBrkPtInfo(const lldb::SBBreakpoint &vBrkPt, SBrkPtInfo &vrwBrkPtInfo) const;
166 bool RecordBrkPtInfo(const MIuint vnBrkPtId, const SBrkPtInfo &vrBrkPtInfo);
167 bool RecordBrkPtInfoGet(const MIuint vnBrkPtId, SBrkPtInfo &vrwBrkPtInfo) const;
168 bool RecordBrkPtInfoDelete(const MIuint vnBrkPtId);
Hafiz Abid Qadeerd1f606f2015-02-04 09:59:23 +0000169 CMIUtilThreadMutex& GetSessionMutex() { return m_sessionMutex;}
Hafiz Abid Qadeer0d51c152015-02-03 10:05:54 +0000170 lldb::SBDebugger &GetDebugger() const;
171 lldb::SBListener &GetListener() const;
172 lldb::SBTarget GetTarget() const;
173 lldb::SBProcess GetProcess() const;
Deepak Panickal877569c2014-06-24 16:35:50 +0000174
Zachary Turner1d6af022014-11-17 18:06:21 +0000175 // Attributes:
176 public:
177 // The following are available to all command instances
Zachary Turner1d6af022014-11-17 18:06:21 +0000178 const MIuint m_nBrkPointCntMax;
179 VecActiveThreadId_t m_vecActiveThreadId;
180 lldb::tid_t m_currentSelectedThread;
181
182 // These are keys that can be used to access the shared data map
183 // Note: This list is expected to grow and will be moved and abstracted in the future.
184 const CMIUtilString m_constStrSharedDataKeyWkDir;
Deepak Panickal877569c2014-06-24 16:35:50 +0000185 const CMIUtilString m_constStrSharedDataSolibPath;
Ilia Kaa82b4a2015-04-25 19:44:56 +0000186 const CMIUtilString m_constStrPrintCharArrayAsString;
Ilia K81bd06d2015-04-25 20:10:02 +0000187 const CMIUtilString m_constStrPrintExpandAggregates;
Ilia K94b8ebc2015-04-25 20:33:02 +0000188 const CMIUtilString m_constStrPrintAggregateFieldNames;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000189
Zachary Turner1d6af022014-11-17 18:06:21 +0000190 // Typedefs:
191 private:
192 typedef std::vector<CMICmnLLDBDebugSessionInfoVarObj> VecVarObj_t;
193 typedef std::map<MIuint, SBrkPtInfo> MapBrkPtIdToBrkPtInfo_t;
194 typedef std::pair<MIuint, SBrkPtInfo> MapPairBrkPtIdToBrkPtInfo_t;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000195
Zachary Turner1d6af022014-11-17 18:06:21 +0000196 // Methods:
197 private:
198 /* ctor */ CMICmnLLDBDebugSessionInfo(void);
199 /* ctor */ CMICmnLLDBDebugSessionInfo(const CMICmnLLDBDebugSessionInfo &);
200 void operator=(const CMICmnLLDBDebugSessionInfo &);
201 //
Ilia K58627322015-04-09 11:17:54 +0000202 bool GetVariableInfo(const lldb::SBValue &vrValue, const bool vbInSimpleForm, CMIUtilString &vwrStrValue);
203 bool GetFrameInfo(const lldb::SBFrame &vrFrame, lldb::addr_t &vwPc, CMIUtilString &vwFnName, CMIUtilString &vwFileName,
204 CMIUtilString &vwPath, MIuint &vwnLine);
205 bool GetThreadFrames(const SMICmdData &vCmdData, const MIuint vThreadIdx, const FrameInfoFormat_e veFrameInfoFormat,
206 CMIUtilString &vwrThreadFrames);
Hafiz Abid Qadeerfda237d2015-04-29 08:18:41 +0000207 bool MIResponseForVariableInfoInternal(const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList,
208 const lldb::SBValueList &vwrSBValueList, const MIuint vnMaxDepth, const bool vbIsArgs, const bool vbMarkArgs);
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000209
Zachary Turner1d6af022014-11-17 18:06:21 +0000210 // Overridden:
211 private:
212 // From CMICmnBase
213 /* dtor */ virtual ~CMICmnLLDBDebugSessionInfo(void);
214
215 // Attributes:
216 private:
217 CMIUtilMapIdToVariant m_mapIdToSessionData; // Hold and retrieve key to value data available across all commands
218 VecVarObj_t m_vecVarObj; // Vector of session variable objects
219 MapBrkPtIdToBrkPtInfo_t m_mapBrkPtIdToBrkPtInfo;
Hafiz Abid Qadeerd1f606f2015-02-04 09:59:23 +0000220 CMIUtilThreadMutex m_sessionMutex;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000221};
Deepak Panickal877569c2014-06-24 16:35:50 +0000222
223//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +0000224// Details: Command instances can create and share data between other instances of commands.
225// This function adds new data to the shared data. Using the same ID more than
226// once replaces any previous matching data keys.
227// Type: Template method.
228// Args: T - The type of the object to be stored.
229// vKey - (R) A non empty unique data key to retrieve the data by.
230// vData - (R) Data to be added to the share.
231// Return: MIstatus::success - Functional succeeded.
232// MIstatus::failure - Functional failed.
233// Throws: None.
Deepak Panickal877569c2014-06-24 16:35:50 +0000234//--
Zachary Turner1d6af022014-11-17 18:06:21 +0000235template <typename T>
236bool
237CMICmnLLDBDebugSessionInfo::SharedDataAdd(const CMIUtilString &vKey, const T &vData)
Deepak Panickal877569c2014-06-24 16:35:50 +0000238{
Zachary Turner1d6af022014-11-17 18:06:21 +0000239 if (!m_mapIdToSessionData.Add<T>(vKey, vData))
240 {
241 SetErrorDescription(m_mapIdToSessionData.GetErrorDescription());
242 return MIstatus::failure;
243 }
Deepak Panickal877569c2014-06-24 16:35:50 +0000244
Zachary Turner1d6af022014-11-17 18:06:21 +0000245 return MIstatus::success;
Deepak Panickal877569c2014-06-24 16:35:50 +0000246}
247
248//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +0000249// Details: Command instances can create and share data between other instances of commands.
250// This function retrieves data from the shared data container.
251// Type: Method.
252// Args: T - The type of the object being retrieved.
253// vKey - (R) A non empty unique data key to retrieve the data by.
254// vData - (W) The data.
255// Return: bool - True = data found, false = data not found or an error occurred trying to fetch.
256// Throws: None.
Deepak Panickal877569c2014-06-24 16:35:50 +0000257//--
Zachary Turner1d6af022014-11-17 18:06:21 +0000258template <typename T>
259bool
260CMICmnLLDBDebugSessionInfo::SharedDataRetrieve(const CMIUtilString &vKey, T &vwData)
Deepak Panickal877569c2014-06-24 16:35:50 +0000261{
Zachary Turner1d6af022014-11-17 18:06:21 +0000262 bool bDataFound = false;
Deepak Panickal877569c2014-06-24 16:35:50 +0000263
Zachary Turner1d6af022014-11-17 18:06:21 +0000264 if (!m_mapIdToSessionData.Get<T>(vKey, vwData, bDataFound))
265 {
266 SetErrorDescription(m_mapIdToSessionData.GetErrorDescription());
267 return MIstatus::failure;
268 }
Deepak Panickal877569c2014-06-24 16:35:50 +0000269
Zachary Turner1d6af022014-11-17 18:06:21 +0000270 return bDataFound;
271}