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