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 = {
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}};
38 //++ ------------------------------------------------------------------------------------
39 // Details: CMICmdCmdGdbSet constructor.
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))
53 // Command factory matches this name with that received from the stdin stream
54 m_strMiCmd = "gdb-set";
56 // Required by the CMICmdFactory when registering *this command
57 m_pSelfCreatorFn = &CMICmdCmdGdbSet::CreateSelf;
60 //++ ------------------------------------------------------------------------------------
61 // Details: CMICmdCmdGdbSet destructor.
62 // Type: Overrideable.
67 CMICmdCmdGdbSet::~CMICmdCmdGdbSet(void)
71 //++ ------------------------------------------------------------------------------------
72 // Details: The invoker requires this function. The parses the command line options
73 // arguments to extract values for each of those arguments.
76 // Return: MIstatus::success - Functional succeeded.
77 // MIstatus::failure - Functional failed.
81 CMICmdCmdGdbSet::ParseArgs(void)
83 bool bOk = m_setCmdArgs.Add(
84 *(new CMICmdArgValOptionLong(m_constStrArgNamedThreadGrp, false, false, CMICmdArgValListBase::eArgValType_ThreadGrp, 1)));
87 *(new CMICmdArgValListOfN(m_constStrArgNamedGdbOption, true, true, CMICmdArgValListBase::eArgValType_StringAnything)));
88 return (bOk && ParseValidateCmdOptions());
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.
96 // Return: MIstatus::success - Functional succeeded.
97 // MIstatus::failure - Functional failed.
101 CMICmdCmdGdbSet::Execute(void)
103 CMICMDBASE_GETOPTION(pArgGdbOption, ListOfN, m_constStrArgNamedGdbOption);
104 const CMICmdArgValListBase::VecArgObjPtr_t &rVecWords(pArgGdbOption->GetExpectedOptions());
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());
112 // Retrieve the parameter(s) for the option
113 CMIUtilString::VecString_t vecWords;
114 while (it != rVecWords.end())
116 const CMICmdArgValString *pWord = static_cast<const CMICmdArgValString *>(*it);
117 vecWords.push_back(pWord->GetValue());
123 FnGdbOptionPtr pPrintRequestFn = nullptr;
124 if (!GetOptionFn(strOption, pPrintRequestFn))
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))
130 m_bGdbOptionRecognised = false;
131 m_strGdbOptionName = "fallback"; // This would be the strOption name
132 return MIstatus::success;
136 m_bGdbOptionFnSuccessful = (this->*(pPrintRequestFn))(vecWords);
137 if (!m_bGdbOptionFnSuccessful && !m_bGbbOptionFnHasError)
138 return MIstatus::failure;
140 return MIstatus::success;
143 //++ ------------------------------------------------------------------------------------
144 // Details: The invoker requires this function. The command prepares a MI Record Result
145 // for the work carried out in the Execute().
148 // Return: MIstatus::success - Functional succeeded.
149 // MIstatus::failure - Functional failed.
153 CMICmdCmdGdbSet::Acknowledge(void)
155 if (!m_bGdbOptionRecognised)
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;
165 if (m_bGdbOptionFnSuccessful)
167 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done);
168 m_miResultRecord = miRecordResult;
169 return MIstatus::success;
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;
177 return MIstatus::success;
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.
185 // Return: CMICmdBase * - Pointer to a new command.
189 CMICmdCmdGdbSet::CreateSelf(void)
191 return new CMICmdCmdGdbSet();
194 //++ ------------------------------------------------------------------------------------
195 // Details: Retrieve the print function's pointer for the matching print request.
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.
203 CMICmdCmdGdbSet::GetOptionFn(const CMIUtilString &vrPrintFnName, FnGdbOptionPtr &vrwpFn) const
207 const MapGdbOptionNameToFnGdbOptionPtr_t::const_iterator it = ms_mapGdbOptionNameToFnGdbOptionPtr.find(vrPrintFnName);
208 if (it != ms_mapGdbOptionNameToFnGdbOptionPtr.end())
210 vrwpFn = (*it).second;
217 //++ ------------------------------------------------------------------------------------
218 // Details: Carry out work to complete the GDB set option 'solib-search-path' to prepare
219 // and send back information asked for.
221 // Args: vrWords - (R) List of additional parameters used by this option.
222 // Return: MIstatus::success - Functional succeeded.
223 // MIstatus::failure - Functional failed.
227 CMICmdCmdGdbSet::OptionFnSolibSearchPath(const CMIUtilString::VecString_t &vrWords)
229 // Check we have at least one argument
230 if (vrWords.size() < 1)
232 m_bGbbOptionFnHasError = true;
233 m_strGdbOptionFnError = MIRSRC(IDS_CMD_ERR_GDBSET_OPT_SOLIBSEARCHPATH);
234 return MIstatus::failure;
236 const CMIUtilString &rStrValSolibPath(vrWords[0]);
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))
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;
247 return MIstatus::success;
250 //++ ------------------------------------------------------------------------------------
251 // Details: Carry out work to complete the GDB set option to prepare and send back information
255 // Return: MIstatus::success - Functional succeeded.
256 // MIstatus::failure - Functional failed.
260 CMICmdCmdGdbSet::OptionFnFallback(const CMIUtilString::VecString_t &vrWords)
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).
268 return MIstatus::success;