]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdCmdGdbSet.cpp
Update LLDB snapshot to upstream r225923 (git 2b588ecd)
[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     // { "target-async", &CMICmdCmdGdbSet::OptionFnTargetAsync },       // Example code if need to implement GDB set other options
34     // { "auto-solib-add", &CMICmdCmdGdbSet::OptionFnAutoSolibAdd },    // Example code if need to implement GDB set other options
35     {"solib-search-path", &CMICmdCmdGdbSet::OptionFnSolibSearchPath},
36     {"fallback", &CMICmdCmdGdbSet::OptionFnFallback}};
37
38 //++ ------------------------------------------------------------------------------------
39 // Details: CMICmdCmdGdbSet constructor.
40 // Type:    Method.
41 // Args:    None.
42 // Return:  None.
43 // Throws:  None.
44 //--
45 CMICmdCmdGdbSet::CMICmdCmdGdbSet(void)
46     : m_constStrArgNamedThreadGrp("thread-group")
47     , m_constStrArgNamedGdbOption("option")
48     , m_bGdbOptionRecognised(true)
49     , m_bGdbOptionFnSuccessful(false)
50     , m_bGbbOptionFnHasError(false)
51     , m_strGdbOptionFnError(MIRSRC(IDS_WORD_ERR_MSG_NOT_IMPLEMENTED_BRKTS))
52 {
53     // Command factory matches this name with that received from the stdin stream
54     m_strMiCmd = "gdb-set";
55
56     // Required by the CMICmdFactory when registering *this command
57     m_pSelfCreatorFn = &CMICmdCmdGdbSet::CreateSelf;
58 }
59
60 //++ ------------------------------------------------------------------------------------
61 // Details: CMICmdCmdGdbSet destructor.
62 // Type:    Overrideable.
63 // Args:    None.
64 // Return:  None.
65 // Throws:  None.
66 //--
67 CMICmdCmdGdbSet::~CMICmdCmdGdbSet(void)
68 {
69 }
70
71 //++ ------------------------------------------------------------------------------------
72 // Details: The invoker requires this function. The parses the command line options
73 //          arguments to extract values for each of those arguments.
74 // Type:    Overridden.
75 // Args:    None.
76 // Return:  MIstatus::success - Functional succeeded.
77 //          MIstatus::failure - Functional failed.
78 // Throws:  None.
79 //--
80 bool
81 CMICmdCmdGdbSet::ParseArgs(void)
82 {
83     bool bOk = m_setCmdArgs.Add(
84         *(new CMICmdArgValOptionLong(m_constStrArgNamedThreadGrp, false, false, CMICmdArgValListBase::eArgValType_ThreadGrp, 1)));
85     bOk = bOk &&
86           m_setCmdArgs.Add(
87               *(new CMICmdArgValListOfN(m_constStrArgNamedGdbOption, true, true, CMICmdArgValListBase::eArgValType_StringAnything)));
88     return (bOk && ParseValidateCmdOptions());
89 }
90
91 //++ ------------------------------------------------------------------------------------
92 // Details: The invoker requires this function. The command does work in this function.
93 //          The command is likely to communicate with the LLDB SBDebugger in here.
94 // Type:    Overridden.
95 // Args:    None.
96 // Return:  MIstatus::success - Functional succeeded.
97 //          MIstatus::failure - Functional failed.
98 // Throws:  None.
99 //--
100 bool
101 CMICmdCmdGdbSet::Execute(void)
102 {
103     CMICMDBASE_GETOPTION(pArgGdbOption, ListOfN, m_constStrArgNamedGdbOption);
104     const CMICmdArgValListBase::VecArgObjPtr_t &rVecWords(pArgGdbOption->GetExpectedOptions());
105
106     // Get the gdb-set option to carry out
107     CMICmdArgValListBase::VecArgObjPtr_t::const_iterator it = rVecWords.begin();
108     const CMICmdArgValString *pOption = static_cast<const CMICmdArgValString *>(*it);
109     const CMIUtilString strOption(pOption->GetValue());
110     ++it;
111
112     // Retrieve the parameter(s) for the option
113     CMIUtilString::VecString_t vecWords;
114     while (it != rVecWords.end())
115     {
116         const CMICmdArgValString *pWord = static_cast<const CMICmdArgValString *>(*it);
117         vecWords.push_back(pWord->GetValue());
118
119         // Next
120         ++it;
121     }
122
123     FnGdbOptionPtr pPrintRequestFn = nullptr;
124     if (!GetOptionFn(strOption, pPrintRequestFn))
125     {
126         // For unimplemented option handlers, fallback on a generic handler
127         // ToDo: Remove this when ALL options have been implemented
128         if (!GetOptionFn("fallback", pPrintRequestFn))
129         {
130             m_bGdbOptionRecognised = false;
131             m_strGdbOptionName = "fallback"; // This would be the strOption name
132             return MIstatus::success;
133         }
134     }
135
136     m_bGdbOptionFnSuccessful = (this->*(pPrintRequestFn))(vecWords);
137     if (!m_bGdbOptionFnSuccessful && !m_bGbbOptionFnHasError)
138         return MIstatus::failure;
139
140     return MIstatus::success;
141 }
142
143 //++ ------------------------------------------------------------------------------------
144 // Details: The invoker requires this function. The command prepares a MI Record Result
145 //          for the work carried out in the Execute().
146 // Type:    Overridden.
147 // Args:    None.
148 // Return:  MIstatus::success - Functional succeeded.
149 //          MIstatus::failure - Functional failed.
150 // Throws:  None.
151 //--
152 bool
153 CMICmdCmdGdbSet::Acknowledge(void)
154 {
155     if (!m_bGdbOptionRecognised)
156     {
157         const CMICmnMIValueConst miValueConst(
158             CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INFO_PRINTFN_NOT_FOUND), m_strGdbOptionName.c_str()));
159         const CMICmnMIValueResult miValueResult("msg", miValueConst);
160         const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
161         m_miResultRecord = miRecordResult;
162         return MIstatus::success;
163     }
164
165     if (m_bGdbOptionFnSuccessful)
166     {
167         const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done);
168         m_miResultRecord = miRecordResult;
169         return MIstatus::success;
170     }
171
172     const CMICmnMIValueConst miValueConst(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INFO_PRINTFN_FAILED), m_strGdbOptionFnError.c_str()));
173     const CMICmnMIValueResult miValueResult("msg", miValueConst);
174     const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
175     m_miResultRecord = miRecordResult;
176
177     return MIstatus::success;
178 }
179
180 //++ ------------------------------------------------------------------------------------
181 // Details: Required by the CMICmdFactory when registering *this command. The factory
182 //          calls this function to create an instance of *this command.
183 // Type:    Static method.
184 // Args:    None.
185 // Return:  CMICmdBase * - Pointer to a new command.
186 // Throws:  None.
187 //--
188 CMICmdBase *
189 CMICmdCmdGdbSet::CreateSelf(void)
190 {
191     return new CMICmdCmdGdbSet();
192 }
193
194 //++ ------------------------------------------------------------------------------------
195 // Details: Retrieve the print function's pointer for the matching print request.
196 // Type:    Method.
197 // Args:    vrPrintFnName   - (R) The info requested.
198 //          vrwpFn          - (W) The print function's pointer of the function to carry out
199 // Return:  bool    - True = Print request is implemented, false = not found.
200 // Throws:  None.
201 //--
202 bool
203 CMICmdCmdGdbSet::GetOptionFn(const CMIUtilString &vrPrintFnName, FnGdbOptionPtr &vrwpFn) const
204 {
205     vrwpFn = nullptr;
206
207     const MapGdbOptionNameToFnGdbOptionPtr_t::const_iterator it = ms_mapGdbOptionNameToFnGdbOptionPtr.find(vrPrintFnName);
208     if (it != ms_mapGdbOptionNameToFnGdbOptionPtr.end())
209     {
210         vrwpFn = (*it).second;
211         return true;
212     }
213
214     return false;
215 }
216
217 //++ ------------------------------------------------------------------------------------
218 // Details: Carry out work to complete the GDB set option 'solib-search-path' to prepare
219 //          and send back information asked for.
220 // Type:    Method.
221 // Args:    vrWords - (R) List of additional parameters used by this option.
222 // Return:  MIstatus::success - Functional succeeded.
223 //          MIstatus::failure - Functional failed.
224 // Throws:  None.
225 //--
226 bool
227 CMICmdCmdGdbSet::OptionFnSolibSearchPath(const CMIUtilString::VecString_t &vrWords)
228 {
229     // Check we have at least one argument
230     if (vrWords.size() < 1)
231     {
232         m_bGbbOptionFnHasError = true;
233         m_strGdbOptionFnError = MIRSRC(IDS_CMD_ERR_GDBSET_OPT_SOLIBSEARCHPATH);
234         return MIstatus::failure;
235     }
236     const CMIUtilString &rStrValSolibPath(vrWords[0]);
237
238     // Add 'solib-search-path' to the shared data list
239     const CMIUtilString &rStrKeySolibPath(m_rLLDBDebugSessionInfo.m_constStrSharedDataSolibPath);
240     if (!m_rLLDBDebugSessionInfo.SharedDataAdd<CMIUtilString>(rStrKeySolibPath, rStrValSolibPath))
241     {
242         m_bGbbOptionFnHasError = false;
243         SetError(CMIUtilString::Format(MIRSRC(IDS_DBGSESSION_ERR_SHARED_DATA_ADD), m_cmdData.strMiCmd.c_str(), rStrKeySolibPath.c_str()));
244         return MIstatus::failure;
245     }
246
247     return MIstatus::success;
248 }
249
250 //++ ------------------------------------------------------------------------------------
251 // Details: Carry out work to complete the GDB set option to prepare and send back information
252 //          asked for.
253 // Type:    Method.
254 // Args:    None.
255 // Return:  MIstatus::success - Functional succeeded.
256 //          MIstatus::failure - Functional failed.
257 // Throws:  None.
258 //--
259 bool
260 CMICmdCmdGdbSet::OptionFnFallback(const CMIUtilString::VecString_t &vrWords)
261 {
262     MIunused(vrWords);
263
264     // Do nothing - intentional. This is a fallback temporary action function to do nothing.
265     // This allows the search for gdb-set options to always suceed when the option is not
266     // found (implemented).
267
268     return MIstatus::success;
269 }