1 //===-- MICmdCmdGdbSet.cpp ------- -------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 // File: MICmdCmdGdbSet.cpp
13 // Overview: CMICmdCmdGdbSet implementation.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
23 #include "MICmdCmdGdbSet.h"
24 #include "MICmnMIResultRecord.h"
25 #include "MICmnMIValueConst.h"
26 #include "MICmdArgValString.h"
27 #include "MICmdArgValListOfN.h"
28 #include "MICmdArgValOptionLong.h"
29 #include "MICmnLLDBDebugSessionInfo.h"
32 const CMICmdCmdGdbSet::MapGdbOptionNameToFnGdbOptionPtr_t CMICmdCmdGdbSet::ms_mapGdbOptionNameToFnGdbOptionPtr =
34 // { "target-async", &CMICmdCmdGdbSet::OptionFnTargetAsync }, // Example code if need to implement GDB set other options
35 // { "auto-solib-add", &CMICmdCmdGdbSet::OptionFnAutoSolibAdd }, // Example code if need to implement GDB set other options
36 { "solib-search-path", &CMICmdCmdGdbSet::OptionFnSolibSearchPath },
37 { "fallback", &CMICmdCmdGdbSet::OptionFnFallback }
40 //++ ------------------------------------------------------------------------------------
41 // Details: CMICmdCmdGdbSet constructor.
47 CMICmdCmdGdbSet::CMICmdCmdGdbSet( void )
48 : m_constStrArgNamedThreadGrp( "thread-group" )
49 , m_constStrArgNamedGdbOption( "option" )
50 , m_bGdbOptionRecognised( true )
51 , m_bGdbOptionFnSuccessful( false )
52 , m_bGbbOptionFnHasError( false )
53 , m_strGdbOptionFnError( MIRSRC( IDS_WORD_ERR_MSG_NOT_IMPLEMENTED_BRKTS ) )
55 // Command factory matches this name with that received from the stdin stream
56 m_strMiCmd = "gdb-set";
58 // Required by the CMICmdFactory when registering *this command
59 m_pSelfCreatorFn = &CMICmdCmdGdbSet::CreateSelf;
62 //++ ------------------------------------------------------------------------------------
63 // Details: CMICmdCmdGdbSet destructor.
64 // Type: Overrideable.
69 CMICmdCmdGdbSet::~CMICmdCmdGdbSet( void )
73 //++ ------------------------------------------------------------------------------------
74 // Details: The invoker requires this function. The parses the command line options
75 // arguments to extract values for each of those arguments.
78 // Return: MIstatus::success - Functional succeeded.
79 // MIstatus::failure - Functional failed.
82 bool CMICmdCmdGdbSet::ParseArgs( void )
84 bool bOk = m_setCmdArgs.Add( *(new CMICmdArgValOptionLong( m_constStrArgNamedThreadGrp, false, false, CMICmdArgValListBase::eArgValType_ThreadGrp, 1 ) ) );
85 bOk = bOk && m_setCmdArgs.Add( *(new CMICmdArgValListOfN( m_constStrArgNamedGdbOption, true, true, CMICmdArgValListBase::eArgValType_StringAnything ) ) );
86 return (bOk && ParseValidateCmdOptions() );
89 //++ ------------------------------------------------------------------------------------
90 // Details: The invoker requires this function. The command does work in this function.
91 // The command is likely to communicate with the LLDB SBDebugger in here.
94 // Return: MIstatus::success - Functional succeeded.
95 // MIstatus::failure - Functional failed.
98 bool CMICmdCmdGdbSet::Execute( void )
100 CMICMDBASE_GETOPTION( pArgGdbOption, ListOfN, m_constStrArgNamedGdbOption );
101 const CMICmdArgValListBase::VecArgObjPtr_t & rVecWords( pArgGdbOption->GetExpectedOptions() );
103 // Get the gdb-set option to carry out
104 CMICmdArgValListBase::VecArgObjPtr_t::const_iterator it = rVecWords.begin();
105 const CMICmdArgValString * pOption = static_cast< const CMICmdArgValString * >( *it );
106 const CMIUtilString strOption( pOption->GetValue() );
109 // Retrieve the parameter(s) for the option
110 CMIUtilString::VecString_t vecWords;
111 while( it != rVecWords.end() )
113 const CMICmdArgValString * pWord = static_cast< const CMICmdArgValString * >( *it );
114 vecWords.push_back( pWord->GetValue() );
120 FnGdbOptionPtr pPrintRequestFn = nullptr;
121 if( !GetOptionFn( strOption, pPrintRequestFn ) )
123 // For unimplemented option handlers, fallback on a generic handler
124 // ToDo: Remove this when ALL options have been implemented
125 if( !GetOptionFn( "fallback", pPrintRequestFn ) )
127 m_bGdbOptionRecognised = false;
128 m_strGdbOptionName = "fallback"; // This would be the strOption name
129 return MIstatus::success;
133 m_bGdbOptionFnSuccessful = (this->*(pPrintRequestFn))( vecWords );
134 if( !m_bGdbOptionFnSuccessful && !m_bGbbOptionFnHasError )
135 return MIstatus::failure;
137 return MIstatus::success;
140 //++ ------------------------------------------------------------------------------------
141 // Details: The invoker requires this function. The command prepares a MI Record Result
142 // for the work carried out in the Execute().
145 // Return: MIstatus::success - Functional succeeded.
146 // MIstatus::failure - Functional failed.
149 bool CMICmdCmdGdbSet::Acknowledge( void )
151 if( !m_bGdbOptionRecognised )
153 const CMICmnMIValueConst miValueConst( CMIUtilString::Format( MIRSRC( IDS_CMD_ERR_INFO_PRINTFN_NOT_FOUND ), m_strGdbOptionName.c_str() ) );
154 const CMICmnMIValueResult miValueResult( "msg", miValueConst );
155 const CMICmnMIResultRecord miRecordResult( m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult );
156 m_miResultRecord = miRecordResult;
157 return MIstatus::success;
160 if( m_bGdbOptionFnSuccessful )
162 const CMICmnMIResultRecord miRecordResult( m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done );
163 m_miResultRecord = miRecordResult;
164 return MIstatus::success;
167 const CMICmnMIValueConst miValueConst( CMIUtilString::Format( MIRSRC( IDS_CMD_ERR_INFO_PRINTFN_FAILED ), m_strGdbOptionFnError.c_str() ) );
168 const CMICmnMIValueResult miValueResult( "msg", miValueConst );
169 const CMICmnMIResultRecord miRecordResult( m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult );
170 m_miResultRecord = miRecordResult;
172 return MIstatus::success;
175 //++ ------------------------------------------------------------------------------------
176 // Details: Required by the CMICmdFactory when registering *this command. The factory
177 // calls this function to create an instance of *this command.
178 // Type: Static method.
180 // Return: CMICmdBase * - Pointer to a new command.
183 CMICmdBase * CMICmdCmdGdbSet::CreateSelf( void )
185 return new CMICmdCmdGdbSet();
188 //++ ------------------------------------------------------------------------------------
189 // Details: Retrieve the print function's pointer for the matching print request.
191 // Args: vrPrintFnName - (R) The info requested.
192 // vrwpFn - (W) The print function's pointer of the function to carry out
193 // Return: bool - True = Print request is implemented, false = not found.
196 bool CMICmdCmdGdbSet::GetOptionFn( const CMIUtilString & vrPrintFnName, FnGdbOptionPtr & vrwpFn ) const
200 const MapGdbOptionNameToFnGdbOptionPtr_t::const_iterator it = ms_mapGdbOptionNameToFnGdbOptionPtr.find( vrPrintFnName );
201 if( it != ms_mapGdbOptionNameToFnGdbOptionPtr.end() )
203 vrwpFn = (*it).second;
210 //++ ------------------------------------------------------------------------------------
211 // Details: Carry out work to complete the GDB set option 'solib-search-path' to prepare
212 // and send back information asked for.
214 // Args: vrWords - (R) List of additional parameters used by this option.
215 // Return: MIstatus::success - Functional succeeded.
216 // MIstatus::failure - Functional failed.
219 bool CMICmdCmdGdbSet::OptionFnSolibSearchPath( const CMIUtilString::VecString_t & vrWords )
221 // Check we have at least one argument
222 if( vrWords.size() < 1 )
224 m_bGbbOptionFnHasError = true;
225 m_strGdbOptionFnError = MIRSRC( IDS_CMD_ERR_GDBSET_OPT_SOLIBSEARCHPATH );
226 return MIstatus::failure;
228 const CMIUtilString & rStrValSolibPath( vrWords[ 0 ] );
230 // Add 'solib-search-path' to the shared data list
231 const CMIUtilString & rStrKeySolibPath( m_rLLDBDebugSessionInfo.m_constStrSharedDataSolibPath );
232 if( !m_rLLDBDebugSessionInfo.SharedDataAdd< CMIUtilString >( rStrKeySolibPath, rStrValSolibPath ) )
234 m_bGbbOptionFnHasError = false;
235 SetError( CMIUtilString::Format( MIRSRC( IDS_DBGSESSION_ERR_SHARED_DATA_ADD ), m_cmdData.strMiCmd.c_str(), rStrKeySolibPath.c_str() ) );
236 return MIstatus::failure;
239 return MIstatus::success;
242 //++ ------------------------------------------------------------------------------------
243 // Details: Carry out work to complete the GDB set option to prepare and send back information
247 // Return: MIstatus::success - Functional succeeded.
248 // MIstatus::failure - Functional failed.
251 bool CMICmdCmdGdbSet::OptionFnFallback( const CMIUtilString::VecString_t & vrWords )
255 // Do nothing - intentional. This is a fallback temporary action function to do nothing.
256 // This allows the search for gdb-set options to always suceed when the option is not
257 // found (implemented).
259 return MIstatus::success;