]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdCmdGdbSet.cpp
Install the liblzma pkg-config file
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdCmdGdbSet.cpp
1 //===-- MICmdCmdGdbSet.cpp -------      -------------------------*- 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:                MICmdCmdGdbSet.cpp
12 //
13 // Overview:    CMICmdCmdGdbSet implementation.
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 // In-house headers:
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"
30
31 // Instantiations:
32 const CMICmdCmdGdbSet::MapGdbOptionNameToFnGdbOptionPtr_t CMICmdCmdGdbSet::ms_mapGdbOptionNameToFnGdbOptionPtr =
33 {
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 }
38 };
39
40 //++ ------------------------------------------------------------------------------------
41 // Details:     CMICmdCmdGdbSet constructor.
42 // Type:        Method.
43 // Args:        None.
44 // Return:      None.
45 // Throws:      None.
46 //--
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 ) )
54 {
55         // Command factory matches this name with that received from the stdin stream
56         m_strMiCmd = "gdb-set";
57         
58         // Required by the CMICmdFactory when registering *this command
59         m_pSelfCreatorFn = &CMICmdCmdGdbSet::CreateSelf;
60 }
61
62 //++ ------------------------------------------------------------------------------------
63 // Details:     CMICmdCmdGdbSet destructor.
64 // Type:        Overrideable.
65 // Args:        None.
66 // Return:      None.
67 // Throws:      None.
68 //--
69 CMICmdCmdGdbSet::~CMICmdCmdGdbSet( void )
70 {
71 }
72
73 //++ ------------------------------------------------------------------------------------
74 // Details:     The invoker requires this function. The parses the command line options 
75 //                      arguments to extract values for each of those arguments.
76 // Type:        Overridden.
77 // Args:        None.
78 // Return:      MIstatus::success - Functional succeeded.
79 //                      MIstatus::failure - Functional failed.
80 // Throws:      None.
81 //--
82 bool CMICmdCmdGdbSet::ParseArgs( void )
83 {
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() );
87 }
88
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.
92 // Type:        Overridden.
93 // Args:        None.
94 // Return:      MIstatus::success - Functional succeeded.
95 //                      MIstatus::failure - Functional failed.
96 // Throws:      None.
97 //--
98 bool CMICmdCmdGdbSet::Execute( void )
99 {
100         CMICMDBASE_GETOPTION( pArgGdbOption, ListOfN, m_constStrArgNamedGdbOption );
101         const CMICmdArgValListBase::VecArgObjPtr_t & rVecWords( pArgGdbOption->GetExpectedOptions() );
102         
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() );
107         ++it;
108
109         // Retrieve the parameter(s) for the option
110         CMIUtilString::VecString_t vecWords;
111         while( it != rVecWords.end() )
112         {
113                 const CMICmdArgValString * pWord = static_cast< const CMICmdArgValString * >( *it );
114                 vecWords.push_back( pWord->GetValue() );
115
116                 // Next
117                 ++it;
118         }
119
120         FnGdbOptionPtr pPrintRequestFn = nullptr;
121         if( !GetOptionFn( strOption, pPrintRequestFn ) )
122         {
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 ) )
126                 {
127                         m_bGdbOptionRecognised = false;
128                         m_strGdbOptionName = "fallback"; // This would be the strOption name
129                         return MIstatus::success;
130                 }
131         }
132
133         m_bGdbOptionFnSuccessful = (this->*(pPrintRequestFn))( vecWords );
134         if( !m_bGdbOptionFnSuccessful && !m_bGbbOptionFnHasError )
135                 return MIstatus::failure;
136
137         return MIstatus::success;
138
139
140 //++ ------------------------------------------------------------------------------------
141 // Details:     The invoker requires this function. The command prepares a MI Record Result
142 //                      for the work carried out in the Execute().
143 // Type:        Overridden.
144 // Args:        None.
145 // Return:      MIstatus::success - Functional succeeded.
146 //                      MIstatus::failure - Functional failed.
147 // Throws:      None.
148 //--
149 bool CMICmdCmdGdbSet::Acknowledge( void )
150 {
151         if( !m_bGdbOptionRecognised )
152         {
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;
158         }
159         
160         if( m_bGdbOptionFnSuccessful )
161         {
162                 const CMICmnMIResultRecord miRecordResult( m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done );
163                 m_miResultRecord = miRecordResult;
164                 return MIstatus::success;
165         }
166
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;
171
172         return MIstatus::success;
173 }
174
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.
179 // Args:        None.
180 // Return:      CMICmdBase * - Pointer to a new command.
181 // Throws:      None.
182 //--
183 CMICmdBase * CMICmdCmdGdbSet::CreateSelf( void )
184 {
185         return new CMICmdCmdGdbSet();
186 }
187
188 //++ ------------------------------------------------------------------------------------
189 // Details:     Retrieve the print function's pointer for the matching print request.
190 // Type:        Method.
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.
194 // Throws:      None.
195 //--
196 bool CMICmdCmdGdbSet::GetOptionFn( const CMIUtilString & vrPrintFnName, FnGdbOptionPtr & vrwpFn ) const
197 {
198         vrwpFn = nullptr;
199
200         const MapGdbOptionNameToFnGdbOptionPtr_t::const_iterator it = ms_mapGdbOptionNameToFnGdbOptionPtr.find( vrPrintFnName );
201         if( it != ms_mapGdbOptionNameToFnGdbOptionPtr.end() )
202         {
203                 vrwpFn = (*it).second;
204                 return true;
205         }
206
207         return false;
208 }
209
210 //++ ------------------------------------------------------------------------------------
211 // Details:     Carry out work to complete the GDB set option 'solib-search-path' to prepare 
212 //                      and send back information asked for.
213 // Type:        Method.
214 // Args:        vrWords - (R) List of additional parameters used by this option.
215 // Return:      MIstatus::success - Functional succeeded.
216 //                      MIstatus::failure - Functional failed.
217 // Throws:      None.
218 //--
219 bool CMICmdCmdGdbSet::OptionFnSolibSearchPath( const CMIUtilString::VecString_t & vrWords )
220 {
221         // Check we have at least one argument
222         if( vrWords.size() < 1 )
223         {
224                 m_bGbbOptionFnHasError = true;
225                 m_strGdbOptionFnError = MIRSRC( IDS_CMD_ERR_GDBSET_OPT_SOLIBSEARCHPATH );
226                 return MIstatus::failure;
227         }
228         const CMIUtilString & rStrValSolibPath( vrWords[ 0 ] );
229
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 ) )
233         {
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;
237         }       
238
239         return MIstatus::success;
240 }
241
242 //++ ------------------------------------------------------------------------------------
243 // Details:     Carry out work to complete the GDB set option to prepare and send back information
244 //                      asked for.
245 // Type:        Method.
246 // Args:        None.
247 // Return:      MIstatus::success - Functional succeeded.
248 //                      MIstatus::failure - Functional failed.
249 // Throws:      None.
250 //--
251 bool CMICmdCmdGdbSet::OptionFnFallback( const CMIUtilString::VecString_t & vrWords )
252 {
253         MIunused( vrWords );
254
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).
258
259         return MIstatus::success;
260 }