blob: 53cb8a0877a626fc872d66c3ccf2b2b32ee1c8c6 [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>
27#include <lldb/API/SBDebugger.h>
Zachary Turner1d6af022014-11-17 18:06:21 +000028#include <lldb/API/SBListener.h>
Deepak Panickal6f9c4682014-05-16 10:51:01 +000029#include <lldb/API/SBProcess.h>
30#include <lldb/API/SBTarget.h>
31
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"
Deepak Panickal6f9c4682014-05-16 10:51:01 +000038
39// Declarations:
40class CMICmnLLDBDebugger;
41struct SMICmdData;
42class CMICmnMIValueTuple;
43class CMICmnMIValueList;
44
45//++ ============================================================================
Zachary Turner1d6af022014-11-17 18:06:21 +000046// Details: MI debug session object that holds debugging information between
47// instances of MI commands executing their work and producing MI
48// result records. Information/data is set by one or many commands then
49// retrieved by the same or other sebsequent commands.
50// It primarily to hold LLDB type objects.
51// A singleton class.
52// Gotchas: None.
53// Authors: Illya Rudkin 04/03/2014.
54// Changes: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000055//--
Zachary Turner1d6af022014-11-17 18:06:21 +000056class CMICmnLLDBDebugSessionInfo : public CMICmnBase, public MI::ISingleton<CMICmnLLDBDebugSessionInfo>
Deepak Panickal6f9c4682014-05-16 10:51:01 +000057{
Zachary Turner1d6af022014-11-17 18:06:21 +000058 friend class MI::ISingleton<CMICmnLLDBDebugSessionInfo>;
Deepak Panickal6f9c4682014-05-16 10:51:01 +000059
Zachary Turner1d6af022014-11-17 18:06:21 +000060 // Structs:
61 public:
62 //++ ============================================================================
63 // Details: Break point information object. Used to easily pass information about
64 // a break around and record break point information to be recalled by
65 // other commands or LLDB event handling functions.
66 //--
67 struct SBrkPtInfo
68 {
69 SBrkPtInfo(void)
70 : m_id(0)
71 , m_bDisp(false)
72 , m_bEnabled(false)
73 , m_pc(0)
74 , m_nLine(0)
75 , m_bHaveArgOptionThreadGrp(false)
76 , m_nTimes(0)
77 , m_bPending(false)
78 , m_nIgnore(0)
79 , m_bCondition(false)
80 , m_bBrkPtThreadId(false)
81 , m_nBrkPtThreadId(0)
82 {
83 }
Deepak Panickal877569c2014-06-24 16:35:50 +000084
Zachary Turner1d6af022014-11-17 18:06:21 +000085 MIuint m_id; // LLDB break point ID.
86 CMIUtilString m_strType; // Break point type.
87 bool m_bDisp; // True = "del", false = "keep".
88 bool m_bEnabled; // True = enabled, false = disabled break point.
89 MIuint m_pc; // Address number.
90 CMIUtilString m_fnName; // Function name.
91 CMIUtilString m_fileName; // File name text.
92 CMIUtilString m_path; // Full file name and path text.
93 MIuint m_nLine; // File line number.
94 bool m_bHaveArgOptionThreadGrp; // True = include MI field, false = do not include "thread-groups".
95 CMIUtilString m_strOptThrdGrp; // Thread group number.
96 MIuint m_nTimes; // The count of the breakpoint existence.
97 CMIUtilString m_strOrigLoc; // The name of the break point.
98 bool m_bPending; // True = the breakpoint has not been established yet, false = location found
99 MIuint m_nIgnore; // The number of time the breakpoint is run over before it is stopped on a hit
100 bool m_bCondition; // True = break point is conditional, use condition expression, false = no condition
101 CMIUtilString m_strCondition; // Break point condition expression
102 bool m_bBrkPtThreadId; // True = break point is specified to work with a specific thread, false = no specified thread given
103 MIuint m_nBrkPtThreadId; // Restrict the breakpoint to the specified thread-id
104 };
Deepak Panickal877569c2014-06-24 16:35:50 +0000105
Zachary Turner1d6af022014-11-17 18:06:21 +0000106 // Typedefs:
107 public:
108 typedef std::vector<uint32_t> VecActiveThreadId_t;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000109
Zachary Turner1d6af022014-11-17 18:06:21 +0000110 // Methods:
111 public:
112 bool Initialize(void);
113 bool Shutdown(void);
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000114
Zachary Turner1d6af022014-11-17 18:06:21 +0000115 // Variant type data which can be assigned and retrieved across all command instances
116 template <typename T> bool SharedDataAdd(const CMIUtilString &vKey, const T &vData);
117 template <typename T> bool SharedDataRetrieve(const CMIUtilString &vKey, T &vwData);
118 bool SharedDataDestroy(void);
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000119
Zachary Turner1d6af022014-11-17 18:06:21 +0000120 // Common command required functionality
121 bool AccessPath(const CMIUtilString &vPath, bool &vwbYesAccessible);
122 bool GetFrameInfo(const lldb::SBFrame &vrFrame, lldb::addr_t &vwPc, CMIUtilString &vwFnName, CMIUtilString &vwFileName,
123 CMIUtilString &vwPath, MIuint &vwnLine);
124 bool GetThreadFrames(const SMICmdData &vCmdData, const MIuint vThreadIdx, CMIUtilString &vwrThreadFrames);
125 bool GetThreadFrames2(const SMICmdData &vCmdData, const MIuint vThreadIdx, CMIUtilString &vwrThreadFrames);
126 bool ResolvePath(const SMICmdData &vCmdData, const CMIUtilString &vPath, CMIUtilString &vwrResolvedPath);
127 bool ResolvePath(const CMIUtilString &vstrUnknown, CMIUtilString &vwrResolvedPath);
128 bool MIResponseFormFrameInfo(const lldb::SBThread &vrThread, const MIuint vnLevel, CMICmnMIValueTuple &vwrMiValueTuple);
129 bool MIResponseFormFrameInfo(const lldb::addr_t vPc, const CMIUtilString &vFnName, const CMIUtilString &vFileName,
130 const CMIUtilString &vPath, const MIuint vnLine, CMICmnMIValueTuple &vwrMiValueTuple);
131 bool MIResponseFormFrameInfo2(const lldb::addr_t vPc, const CMIUtilString &vArgInfo, const CMIUtilString &vFnName,
132 const CMIUtilString &vFileName, const CMIUtilString &vPath, const MIuint vnLine,
133 CMICmnMIValueTuple &vwrMiValueTuple);
134 bool MIResponseFormThreadInfo(const SMICmdData &vCmdData, const lldb::SBThread &vrThread, CMICmnMIValueTuple &vwrMIValueTuple);
135 bool MIResponseFormThreadInfo2(const SMICmdData &vCmdData, const lldb::SBThread &vrThread, CMICmnMIValueTuple &vwrMIValueTuple);
136 bool MIResponseFormThreadInfo3(const SMICmdData &vCmdData, const lldb::SBThread &vrThread, CMICmnMIValueTuple &vwrMIValueTuple);
137 bool MIResponseFormVariableInfo(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, CMICmnMIValueList &vwrMiValueList);
138 bool MIResponseFormVariableInfo2(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, CMICmnMIValueList &vwrMiValueList);
139 bool MIResponseFormVariableInfo3(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, CMICmnMIValueList &vwrMiValueList);
140 bool MIResponseFormBrkPtFrameInfo(const SBrkPtInfo &vrBrkPtInfo, CMICmnMIValueTuple &vwrMiValueTuple);
141 bool MIResponseFormBrkPtInfo(const SBrkPtInfo &vrBrkPtInfo, CMICmnMIValueTuple &vwrMiValueTuple);
142 bool GetBrkPtInfo(const lldb::SBBreakpoint &vBrkPt, SBrkPtInfo &vrwBrkPtInfo) const;
143 bool RecordBrkPtInfo(const MIuint vnBrkPtId, const SBrkPtInfo &vrBrkPtInfo);
144 bool RecordBrkPtInfoGet(const MIuint vnBrkPtId, SBrkPtInfo &vrwBrkPtInfo) const;
145 bool RecordBrkPtInfoDelete(const MIuint vnBrkPtId);
Deepak Panickal877569c2014-06-24 16:35:50 +0000146
Zachary Turner1d6af022014-11-17 18:06:21 +0000147 // Attributes:
148 public:
149 // The following are available to all command instances
150 lldb::SBDebugger &m_rLldbDebugger;
151 lldb::SBListener &m_rLlldbListener;
152 lldb::SBTarget m_lldbTarget;
153 lldb::SBProcess m_lldbProcess;
154 const MIuint m_nBrkPointCntMax;
155 VecActiveThreadId_t m_vecActiveThreadId;
156 lldb::tid_t m_currentSelectedThread;
157
158 // These are keys that can be used to access the shared data map
159 // Note: This list is expected to grow and will be moved and abstracted in the future.
160 const CMIUtilString m_constStrSharedDataKeyWkDir;
Deepak Panickal877569c2014-06-24 16:35:50 +0000161 const CMIUtilString m_constStrSharedDataSolibPath;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000162
Zachary Turner1d6af022014-11-17 18:06:21 +0000163 // Typedefs:
164 private:
165 typedef std::vector<CMICmnLLDBDebugSessionInfoVarObj> VecVarObj_t;
166 typedef std::map<MIuint, SBrkPtInfo> MapBrkPtIdToBrkPtInfo_t;
167 typedef std::pair<MIuint, SBrkPtInfo> MapPairBrkPtIdToBrkPtInfo_t;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000168
Zachary Turner1d6af022014-11-17 18:06:21 +0000169 // Methods:
170 private:
171 /* ctor */ CMICmnLLDBDebugSessionInfo(void);
172 /* ctor */ CMICmnLLDBDebugSessionInfo(const CMICmnLLDBDebugSessionInfo &);
173 void operator=(const CMICmnLLDBDebugSessionInfo &);
174 //
175 bool GetVariableInfo(const MIuint vnMaxDepth, const lldb::SBValue &vrValue, const bool vbIsChildValue,
176 CMICmnMIValueList &vwrMiValueList, MIuint &vrwnDepth);
177 bool GetVariableInfo2(const MIuint vnMaxDepth, const lldb::SBValue &vrValue, const bool vbIsChildValue,
178 CMICmnMIValueList &vwrMiValueList, MIuint &vrwnDepth);
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000179
Zachary Turner1d6af022014-11-17 18:06:21 +0000180 // Overridden:
181 private:
182 // From CMICmnBase
183 /* dtor */ virtual ~CMICmnLLDBDebugSessionInfo(void);
184
185 // Attributes:
186 private:
187 CMIUtilMapIdToVariant m_mapIdToSessionData; // Hold and retrieve key to value data available across all commands
188 VecVarObj_t m_vecVarObj; // Vector of session variable objects
189 MapBrkPtIdToBrkPtInfo_t m_mapBrkPtIdToBrkPtInfo;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000190};
Deepak Panickal877569c2014-06-24 16:35:50 +0000191
192//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +0000193// Details: Command instances can create and share data between other instances of commands.
194// This function adds new data to the shared data. Using the same ID more than
195// once replaces any previous matching data keys.
196// Type: Template method.
197// Args: T - The type of the object to be stored.
198// vKey - (R) A non empty unique data key to retrieve the data by.
199// vData - (R) Data to be added to the share.
200// Return: MIstatus::success - Functional succeeded.
201// MIstatus::failure - Functional failed.
202// Throws: None.
Deepak Panickal877569c2014-06-24 16:35:50 +0000203//--
Zachary Turner1d6af022014-11-17 18:06:21 +0000204template <typename T>
205bool
206CMICmnLLDBDebugSessionInfo::SharedDataAdd(const CMIUtilString &vKey, const T &vData)
Deepak Panickal877569c2014-06-24 16:35:50 +0000207{
Zachary Turner1d6af022014-11-17 18:06:21 +0000208 if (!m_mapIdToSessionData.Add<T>(vKey, vData))
209 {
210 SetErrorDescription(m_mapIdToSessionData.GetErrorDescription());
211 return MIstatus::failure;
212 }
Deepak Panickal877569c2014-06-24 16:35:50 +0000213
Zachary Turner1d6af022014-11-17 18:06:21 +0000214 return MIstatus::success;
Deepak Panickal877569c2014-06-24 16:35:50 +0000215}
216
217//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +0000218// Details: Command instances can create and share data between other instances of commands.
219// This function retrieves data from the shared data container.
220// Type: Method.
221// Args: T - The type of the object being retrieved.
222// vKey - (R) A non empty unique data key to retrieve the data by.
223// vData - (W) The data.
224// Return: bool - True = data found, false = data not found or an error occurred trying to fetch.
225// Throws: None.
Deepak Panickal877569c2014-06-24 16:35:50 +0000226//--
Zachary Turner1d6af022014-11-17 18:06:21 +0000227template <typename T>
228bool
229CMICmnLLDBDebugSessionInfo::SharedDataRetrieve(const CMIUtilString &vKey, T &vwData)
Deepak Panickal877569c2014-06-24 16:35:50 +0000230{
Zachary Turner1d6af022014-11-17 18:06:21 +0000231 bool bDataFound = false;
Deepak Panickal877569c2014-06-24 16:35:50 +0000232
Zachary Turner1d6af022014-11-17 18:06:21 +0000233 if (!m_mapIdToSessionData.Get<T>(vKey, vwData, bDataFound))
234 {
235 SetErrorDescription(m_mapIdToSessionData.GetErrorDescription());
236 return MIstatus::failure;
237 }
Deepak Panickal877569c2014-06-24 16:35:50 +0000238
Zachary Turner1d6af022014-11-17 18:06:21 +0000239 return bDataFound;
240}