1 //===-- MICmdCmdSupportInfo.cpp ---------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Overview: CMICmdCmdSupportInfoMiCmdQuery implementation.
12 #include "MICmdCmdSupportInfo.h"
13 #include "MICmdArgValString.h"
14 #include "MICmdFactory.h"
15 #include "MICmnMIResultRecord.h"
16 #include "MICmnMIValueConst.h"
17 #include "MICmnMIValueTuple.h"
20 // Details: CMICmdCmdSupportInfoMiCmdQuery constructor.
26 CMICmdCmdSupportInfoMiCmdQuery::CMICmdCmdSupportInfoMiCmdQuery()
27 : m_bCmdFound(false), m_constStrArgCmdName("cmd_name") {
28 // Command factory matches this name with that received from the stdin stream
29 m_strMiCmd = "info-gdb-mi-command";
31 // Required by the CMICmdFactory when registering *this command
32 m_pSelfCreatorFn = &CMICmdCmdSupportInfoMiCmdQuery::CreateSelf;
36 // Details: CMICmdCmdSupportInfoMiCmdQuery destructor.
37 // Type: Overrideable.
42 CMICmdCmdSupportInfoMiCmdQuery::~CMICmdCmdSupportInfoMiCmdQuery() {}
45 // Details: The invoker requires this function. The parses the command line
47 // arguments to extract values for each of those arguments.
50 // Return: MIstatus::success - Functional succeeded.
51 // MIstatus::failure - Functional failed.
54 bool CMICmdCmdSupportInfoMiCmdQuery::ParseArgs() {
55 m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgCmdName, true, true));
56 return ParseValidateCmdOptions();
60 // Details: The invoker requires this function. The command does work in this
62 // The command is likely to communicate with the LLDB SBDebugger in
66 // Return: MIstatus::success - Functional succeeded.
67 // MIstatus::failure - Functional failed.
70 bool CMICmdCmdSupportInfoMiCmdQuery::Execute() {
71 CMICMDBASE_GETOPTION(pArgNamedCmdName, String, m_constStrArgCmdName);
72 const CMIUtilString &rCmdToQuery(pArgNamedCmdName->GetValue());
73 const MIuint nLen = rCmdToQuery.length();
74 const CMICmdFactory &rCmdFactory = CMICmdFactory::Instance();
75 if ((nLen > 1) && (rCmdToQuery[0] == '-'))
76 m_bCmdFound = rCmdFactory.CmdExist(rCmdToQuery.substr(1, nLen - 1).c_str());
78 m_bCmdFound = rCmdFactory.CmdExist(rCmdToQuery);
80 return MIstatus::success;
84 // Details: The invoker requires this function. The command prepares a MI Record
86 // for the work carried out in the Execute().
89 // Return: MIstatus::success - Functional succeeded.
90 // MIstatus::failure - Functional failed.
93 bool CMICmdCmdSupportInfoMiCmdQuery::Acknowledge() {
94 const CMICmnMIValueConst miValueConst(m_bCmdFound ? "true" : "false");
95 const CMICmnMIValueResult miValueResult("exists", miValueConst);
96 const CMICmnMIValueTuple miValueTuple(miValueResult);
97 const CMICmnMIValueResult miValueResult2("command", miValueTuple);
98 const CMICmnMIResultRecord miRecordResult(
99 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done,
101 m_miResultRecord = miRecordResult;
103 return MIstatus::success;
107 // Details: Required by the CMICmdFactory when registering *this command. The
109 // calls this function to create an instance of *this command.
110 // Type: Static method.
112 // Return: CMICmdBase * - Pointer to a new command.
115 CMICmdBase *CMICmdCmdSupportInfoMiCmdQuery::CreateSelf() {
116 return new CMICmdCmdSupportInfoMiCmdQuery();