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