blob: 2e592f1f43c6dc1d61d9578f2d4da943c483759a [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
10//++
Zachary Turner1d6af022014-11-17 18:06:21 +000011// File: MICmnLLDBDebugSessionInfo.h
Deepak Panickal6f9c4682014-05-16 10:51:01 +000012//
Zachary Turner1d6af022014-11-17 18:06:21 +000013// Overview: CMICmnLLDBDebugSessionInfo interface.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000014//
Zachary Turner1d6af022014-11-17 18:06:21 +000015// Environment: Compilers: Visual C++ 12.
16// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17// Libraries: See MIReadmetxt.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000018//
Zachary Turner1d6af022014-11-17 18:06:21 +000019// Copyright: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000020//--
21
22#pragma once
23
24// Third party headers:
25#include <map>
26#include <vector>
Greg Claytonee3626e2015-01-20 00:04:26 +000027#include "lldb/API/SBDebugger.h"
28#include "lldb/API/SBListener.h"
29#include "lldb/API/SBProcess.h"
30#include "lldb/API/SBTarget.h"
Deepak Panickal6f9c4682014-05-16 10:51:01 +000031
32// In-house headers:
33#include "MICmnBase.h"
34#include "MIUtilSingletonBase.h"
35#include "MICmnLLDBDebugSessionInfoVarObj.h"
36#include "MICmnMIValueTuple.h"
Deepak Panickal877569c2014-06-24 16:35:50 +000037#include "MIUtilMapIdToVariant.h"
Hafiz Abid Qadeerd1f606f2015-02-04 09:59:23 +000038#include "MIUtilThreadBaseStd.h"
Deepak Panickal6f9c4682014-05-16 10:51:01 +000039
40// Declarations:
41class CMICmnLLDBDebugger;
42struct SMICmdData;
43class CMICmnMIValueTuple;
44class CMICmnMIValueList;
45
46//++ ============================================================================
Zachary Turner1d6af022014-11-17 18:06:21 +000047// 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 Panickal6f9c4682014-05-16 10:51:01 +000056//--
Zachary Turner1d6af022014-11-17 18:06:21 +000057class CMICmnLLDBDebugSessionInfo : public CMICmnBase, public MI::ISingleton<CMICmnLLDBDebugSessionInfo>
Deepak Panickal6f9c4682014-05-16 10:51:01 +000058{
Zachary Turner1d6af022014-11-17 18:06:21 +000059 friend class MI::ISingleton<CMICmnLLDBDebugSessionInfo>;
Deepak Panickal6f9c4682014-05-16 10:51:01 +000060
Zachary Turner1d6af022014-11-17 18:06:21 +000061 // 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 Panickal877569c2014-06-24 16:35:50 +000085
Zachary Turner1d6af022014-11-17 18:06:21 +000086 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 Panickal877569c2014-06-24 16:35:50 +0000106
Hafiz Abid Qadeer290ece82014-12-08 18:07:40 +0000107 // 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 K1a0ec0f2015-02-06 18:08:24 +0000120 //++ ===================================================================
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 Turner1d6af022014-11-17 18:06:21 +0000131 // Typedefs:
132 public:
133 typedef std::vector<uint32_t> VecActiveThreadId_t;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000134
Zachary Turner1d6af022014-11-17 18:06:21 +0000135 // Methods:
136 public:
137 bool Initialize(void);
138 bool Shutdown(void);
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000139
Zachary Turner1d6af022014-11-17 18:06:21 +0000140 // 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 Panickal6f9c4682014-05-16 10:51:01 +0000144
Zachary Turner1d6af022014-11-17 18:06:21 +0000145 // 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 K1a0ec0f2015-02-06 18:08:24 +0000162 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 Turner1d6af022014-11-17 18:06:21 +0000168 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 Qadeerd1f606f2015-02-04 09:59:23 +0000174 CMIUtilThreadMutex& GetSessionMutex() { return m_sessionMutex;}
Hafiz Abid Qadeer0d51c152015-02-03 10:05:54 +0000175 lldb::SBDebugger &GetDebugger() const;
176 lldb::SBListener &GetListener() const;
177 lldb::SBTarget GetTarget() const;
178 lldb::SBProcess GetProcess() const;
Deepak Panickal877569c2014-06-24 16:35:50 +0000179
Zachary Turner1d6af022014-11-17 18:06:21 +0000180 // Attributes:
181 public:
182 // The following are available to all command instances
Zachary Turner1d6af022014-11-17 18:06:21 +0000183 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 Panickal877569c2014-06-24 16:35:50 +0000190 const CMIUtilString m_constStrSharedDataSolibPath;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000191
Zachary Turner1d6af022014-11-17 18:06:21 +0000192 // 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 Panickal6f9c4682014-05-16 10:51:01 +0000197
Zachary Turner1d6af022014-11-17 18:06:21 +0000198 // 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 K1a0ec0f2015-02-06 18:08:24 +0000205 const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList, MIuint &vrwnDepth);
Zachary Turner1d6af022014-11-17 18:06:21 +0000206 bool GetVariableInfo2(const MIuint vnMaxDepth, const lldb::SBValue &vrValue, const bool vbIsChildValue,
Ilia K1a0ec0f2015-02-06 18:08:24 +0000207 const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList, MIuint &vrwnDepth);
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000208
Zachary Turner1d6af022014-11-17 18:06:21 +0000209 // 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 Qadeerd1f606f2015-02-04 09:59:23 +0000219 CMIUtilThreadMutex m_sessionMutex;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000220};
Deepak Panickal877569c2014-06-24 16:35:50 +0000221
222//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +0000223// 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 Panickal877569c2014-06-24 16:35:50 +0000233//--
Zachary Turner1d6af022014-11-17 18:06:21 +0000234template <typename T>
235bool
236CMICmnLLDBDebugSessionInfo::SharedDataAdd(const CMIUtilString &vKey, const T &vData)
Deepak Panickal877569c2014-06-24 16:35:50 +0000237{
Zachary Turner1d6af022014-11-17 18:06:21 +0000238 if (!m_mapIdToSessionData.Add<T>(vKey, vData))
239 {
240 SetErrorDescription(m_mapIdToSessionData.GetErrorDescription());
241 return MIstatus::failure;
242 }
Deepak Panickal877569c2014-06-24 16:35:50 +0000243
Zachary Turner1d6af022014-11-17 18:06:21 +0000244 return MIstatus::success;
Deepak Panickal877569c2014-06-24 16:35:50 +0000245}
246
247//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +0000248// 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 Panickal877569c2014-06-24 16:35:50 +0000256//--
Zachary Turner1d6af022014-11-17 18:06:21 +0000257template <typename T>
258bool
259CMICmnLLDBDebugSessionInfo::SharedDataRetrieve(const CMIUtilString &vKey, T &vwData)
Deepak Panickal877569c2014-06-24 16:35:50 +0000260{
Zachary Turner1d6af022014-11-17 18:06:21 +0000261 bool bDataFound = false;
Deepak Panickal877569c2014-06-24 16:35:50 +0000262
Zachary Turner1d6af022014-11-17 18:06:21 +0000263 if (!m_mapIdToSessionData.Get<T>(vKey, vwData, bDataFound))
264 {
265 SetErrorDescription(m_mapIdToSessionData.GetErrorDescription());
266 return MIstatus::failure;
267 }
Deepak Panickal877569c2014-06-24 16:35:50 +0000268
Zachary Turner1d6af022014-11-17 18:06:21 +0000269 return bDataFound;
270}