blob: ca7ea27f561164bb61090946f92e6e720f2aceea [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//++
11// File: MICmnLLDBDebugSessionInfo.h
12//
13// Overview: CMICmnLLDBDebugSessionInfo interface.
14//
15// Environment: Compilers: Visual C++ 12.
16// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17// Libraries: See MIReadmetxt.
18//
19// Copyright: None.
20//--
21
22#pragma once
23
24// Third party headers:
25#include <map>
26#include <vector>
27#include <lldb/API/SBDebugger.h>
28#include <lldb/API/SBListener.h>
29#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//++ ============================================================================
46// 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.
55//--
56class CMICmnLLDBDebugSessionInfo
57: public CMICmnBase
58, public MI::ISingleton< CMICmnLLDBDebugSessionInfo >
59{
60 friend class MI::ISingleton< CMICmnLLDBDebugSessionInfo >;
61
Deepak Panickal877569c2014-06-24 16:35:50 +000062// Structs:
63public:
64 //++ ============================================================================
65 // Details: Break point information object. Used to easily pass information about
66 // a break around and record break point information to be recalled by
67 // other commands or LLDB event handling functions.
68 //--
69 struct SBrkPtInfo
70 {
71 SBrkPtInfo( void )
72 : m_id( 0 )
73 , m_bDisp( false )
74 , m_bEnabled( false )
75 , m_pc( 0 )
76 , m_nLine( 0 )
77 , m_bHaveArgOptionThreadGrp( false )
78 , m_nTimes( 0 )
79 , m_bPending( false )
80 , m_nIgnore( 0 )
81 , m_bCondition( false )
82 , m_bBrkPtThreadId( false )
83 , m_nBrkPtThreadId( 0 )
84 {
85 }
86
87 MIuint m_id; // LLDB break point ID.
88 CMIUtilString m_strType; // Break point type.
89 bool m_bDisp ; // True = "del", false = "keep".
90 bool m_bEnabled; // True = enabled, false = disabled break point.
91 MIuint m_pc; // Address number.
92 CMIUtilString m_fnName; // Function name.
93 CMIUtilString m_fileName; // File name text.
94 CMIUtilString m_path; // Full file name and path text.
95 MIuint m_nLine; // File line number.
96 bool m_bHaveArgOptionThreadGrp; // True = include MI field, false = do not include "thread-groups".
97 CMIUtilString m_strOptThrdGrp; // Thread group number.
98 MIuint m_nTimes; // The count of the breakpoint existence.
99 CMIUtilString m_strOrigLoc; // The name of the break point.
100 bool m_bPending; // True = the breakpoint has not been established yet, false = location found
101 MIuint m_nIgnore; // The number of time the breakpoint is run over before it is stopped on a hit
102 bool m_bCondition; // True = break point is conditional, use condition expression, false = no condition
103 CMIUtilString m_strCondition; // Break point condition expression
104 bool m_bBrkPtThreadId; // True = break point is specified to work with a specific thread, false = no specified thread given
105 MIuint m_nBrkPtThreadId; // Restrict the breakpoint to the specified thread-id
106 };
107
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000108// Typedefs:
109public:
110 typedef std::vector< uint32_t > VecActiveThreadId_t;
111
112// Methods:
113public:
114 bool Initialize( void );
115 bool Shutdown( void );
116
117 // Variant type data which can be assigned and retrieved across all command instances
Deepak Panickal877569c2014-06-24 16:35:50 +0000118 template< typename T >
119 bool SharedDataAdd( const CMIUtilString & vKey, const T & vData );
120 template< typename T >
121 bool SharedDataRetrieve( const CMIUtilString & vKey, T & vwData );
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000122 bool SharedDataDestroy( void );
123
124 // Common command required functionality
125 bool AccessPath( const CMIUtilString & vPath, bool & vwbYesAccessible );
126 bool GetFrameInfo( const lldb::SBFrame & vrFrame, lldb::addr_t & vwPc, CMIUtilString & vwFnName, CMIUtilString & vwFileName, CMIUtilString & vwPath, MIuint & vwnLine );
Deepak Panickald2499282014-08-08 16:47:42 +0000127 bool GetThreadFrames( const SMICmdData & vCmdData, const MIuint vThreadIdx, CMIUtilString & vwrThreadFrames );
128 bool GetThreadFrames2( const SMICmdData & vCmdData, const MIuint vThreadIdx, CMIUtilString & vwrThreadFrames );
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000129 bool ResolvePath( const SMICmdData & vCmdData, const CMIUtilString & vPath, CMIUtilString & vwrResolvedPath );
130 bool ResolvePath( const CMIUtilString & vstrUnknown, CMIUtilString & vwrResolvedPath );
131 bool MIResponseFormFrameInfo( const lldb::SBThread & vrThread, const MIuint vnLevel, CMICmnMIValueTuple & vwrMiValueTuple );
Deepak Panickald2499282014-08-08 16:47:42 +0000132 bool MIResponseFormFrameInfo( const lldb::addr_t vPc, const CMIUtilString & vFnName, const CMIUtilString & vFileName, const CMIUtilString & vPath, const MIuint vnLine, CMICmnMIValueTuple & vwrMiValueTuple );
133 bool MIResponseFormFrameInfo2( const lldb::addr_t vPc, const CMIUtilString & vArgInfo, const CMIUtilString & vFnName, const CMIUtilString & vFileName, const CMIUtilString & vPath, const MIuint vnLine, CMICmnMIValueTuple & vwrMiValueTuple );
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000134 bool MIResponseFormThreadInfo( const SMICmdData & vCmdData, const lldb::SBThread & vrThread, CMICmnMIValueTuple & vwrMIValueTuple );
Deepak Panickald2499282014-08-08 16:47:42 +0000135 bool MIResponseFormThreadInfo2( const SMICmdData & vCmdData, const lldb::SBThread & vrThread, CMICmnMIValueTuple & vwrMIValueTuple );
136 bool MIResponseFormThreadInfo3( const SMICmdData & vCmdData, const lldb::SBThread & vrThread, CMICmnMIValueTuple & vwrMIValueTuple );
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000137 bool MIResponseFormVariableInfo( const lldb::SBFrame & vrFrame, const MIuint vMaskVarTypes, CMICmnMIValueList & vwrMiValueList );
Deepak Panickald2499282014-08-08 16:47:42 +0000138 bool MIResponseFormVariableInfo2( const lldb::SBFrame & vrFrame, const MIuint vMaskVarTypes, CMICmnMIValueList & vwrMiValueList );
139 bool MIResponseFormVariableInfo3( const lldb::SBFrame & vrFrame, const MIuint vMaskVarTypes, CMICmnMIValueList & vwrMiValueList );
Deepak Panickal877569c2014-06-24 16:35:50 +0000140 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 Panickal6f9c4682014-05-16 10:51:01 +0000146
Deepak Panickal877569c2014-06-24 16:35:50 +0000147// Attributes:
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000148public:
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;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000154 const MIuint m_nBrkPointCntMax;
155 VecActiveThreadId_t m_vecActiveThreadId;
156 lldb::tid_t m_currentSelectedThread;
Deepak Panickal877569c2014-06-24 16:35:50 +0000157
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.
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000160 const CMIUtilString m_constStrSharedDataKeyWkDir;
Deepak Panickal877569c2014-06-24 16:35:50 +0000161 const CMIUtilString m_constStrSharedDataSolibPath;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000162
163// Typedefs:
164private:
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000165 typedef std::vector< CMICmnLLDBDebugSessionInfoVarObj > VecVarObj_t;
Deepak Panickal877569c2014-06-24 16:35:50 +0000166 typedef std::map< MIuint, SBrkPtInfo > MapBrkPtIdToBrkPtInfo_t;
167 typedef std::pair< MIuint, SBrkPtInfo > MapPairBrkPtIdToBrkPtInfo_t;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000168
169// Methods:
170private:
171 /* ctor */ CMICmnLLDBDebugSessionInfo( void );
172 /* ctor */ CMICmnLLDBDebugSessionInfo( const CMICmnLLDBDebugSessionInfo & );
173 void operator=( const CMICmnLLDBDebugSessionInfo & );
Deepak Panickald2499282014-08-08 16:47:42 +0000174 //
175 bool GetVariableInfo( const MIuint vnMaxDepth, const lldb::SBValue & vrValue, const bool vbIsChildValue, CMICmnMIValueList & vwrMiValueList, MIuint & vrwnDepth );
176 bool GetVariableInfo2( const MIuint vnMaxDepth, const lldb::SBValue & vrValue, const bool vbIsChildValue, CMICmnMIValueList & vwrMiValueList, MIuint & vrwnDepth );
177
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000178// Overridden:
179private:
180 // From CMICmnBase
181 /* dtor */ virtual ~CMICmnLLDBDebugSessionInfo( void );
182
183// Attributes:
184private:
Deepak Panickal877569c2014-06-24 16:35:50 +0000185 CMIUtilMapIdToVariant m_mapIdToSessionData; // Hold and retrieve key to value data available across all commands
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000186 VecVarObj_t m_vecVarObj; // Vector of session variable objects
Deepak Panickal877569c2014-06-24 16:35:50 +0000187 MapBrkPtIdToBrkPtInfo_t m_mapBrkPtIdToBrkPtInfo;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000188};
Deepak Panickal877569c2014-06-24 16:35:50 +0000189
190//++ ------------------------------------------------------------------------------------
191// Details: Command instances can create and share data between other instances of commands.
192// This function adds new data to the shared data. Using the same ID more than
193// once replaces any previous matching data keys.
194// Type: Template method.
195// Args: T - The type of the object to be stored.
196// vKey - (R) A non empty unique data key to retrieve the data by.
197// vData - (R) Data to be added to the share.
198// Return: MIstatus::success - Functional succeeded.
199// MIstatus::failure - Functional failed.
200// Throws: None.
201//--
202template< typename T >
203bool CMICmnLLDBDebugSessionInfo::SharedDataAdd( const CMIUtilString & vKey, const T & vData )
204{
205 if( !m_mapIdToSessionData.Add< T >( vKey, vData ) )
206 {
207 SetErrorDescription( m_mapIdToSessionData.GetErrorDescription() );
208 return MIstatus::failure;
209 }
210
211 return MIstatus::success;
212}
213
214//++ ------------------------------------------------------------------------------------
215// Details: Command instances can create and share data between other instances of commands.
216// This function retrieves data from the shared data container.
217// Type: Method.
218// Args: T - The type of the object being retrieved.
219// vKey - (R) A non empty unique data key to retrieve the data by.
220// vData - (W) The data.
221// Return: bool - True = data found, false = data not found or an error occurred trying to fetch.
222// Throws: None.
223//--
224template< typename T >
225bool CMICmnLLDBDebugSessionInfo::SharedDataRetrieve( const CMIUtilString & vKey, T & vwData )
226{
227 bool bDataFound = false;
228
229 if( !m_mapIdToSessionData.Get< T >( vKey, vwData, bDataFound ) )
230 {
231 SetErrorDescription( m_mapIdToSessionData.GetErrorDescription() );
232 return MIstatus::failure;
233 }
234
235 return bDataFound;
236}