1 //===-- MICmdCmdSupportListInfo.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 // Overview:    CMICmdCmdSupportInfoMiCmdQuery          implementation.
11 
12 // In-house headers:
13 #include "MICmdCmdSupportInfo.h"
14 #include "MICmdArgValString.h"
15 #include "MICmdFactory.h"
16 #include "MICmnMIResultRecord.h"
17 #include "MICmnMIValueConst.h"
18 #include "MICmnMIValueTuple.h"
19 
20 //++
21 //------------------------------------------------------------------------------------
22 // Details: CMICmdCmdSupportInfoMiCmdQuery constructor.
23 // Type:    Method.
24 // Args:    None.
25 // Return:  None.
26 // Throws:  None.
27 //--
CMICmdCmdSupportInfoMiCmdQuery()28 CMICmdCmdSupportInfoMiCmdQuery::CMICmdCmdSupportInfoMiCmdQuery()
29     : m_bCmdFound(false), m_constStrArgCmdName("cmd_name") {
30   // Command factory matches this name with that received from the stdin stream
31   m_strMiCmd = "info-gdb-mi-command";
32 
33   // Required by the CMICmdFactory when registering *this command
34   m_pSelfCreatorFn = &CMICmdCmdSupportInfoMiCmdQuery::CreateSelf;
35 }
36 
37 //++
38 //------------------------------------------------------------------------------------
39 // Details: CMICmdCmdSupportInfoMiCmdQuery destructor.
40 // Type:    Overrideable.
41 // Args:    None.
42 // Return:  None.
43 // Throws:  None.
44 //--
~CMICmdCmdSupportInfoMiCmdQuery()45 CMICmdCmdSupportInfoMiCmdQuery::~CMICmdCmdSupportInfoMiCmdQuery() {}
46 
47 //++
48 //------------------------------------------------------------------------------------
49 // Details: The invoker requires this function. The parses the command line
50 // options
51 //          arguments to extract values for each of those arguments.
52 // Type:    Overridden.
53 // Args:    None.
54 // Return:  MIstatus::success - Functional succeeded.
55 //          MIstatus::failure - Functional failed.
56 // Throws:  None.
57 //--
ParseArgs()58 bool CMICmdCmdSupportInfoMiCmdQuery::ParseArgs() {
59   m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgCmdName, true, true));
60   return ParseValidateCmdOptions();
61 }
62 
63 //++
64 //------------------------------------------------------------------------------------
65 // Details: The invoker requires this function. The command does work in this
66 // function.
67 //          The command is likely to communicate with the LLDB SBDebugger in
68 //          here.
69 // Type:    Overridden.
70 // Args:    None.
71 // Return:  MIstatus::success - Functional succeeded.
72 //          MIstatus::failure - Functional failed.
73 // Throws:  None.
74 //--
Execute()75 bool CMICmdCmdSupportInfoMiCmdQuery::Execute() {
76   CMICMDBASE_GETOPTION(pArgNamedCmdName, String, m_constStrArgCmdName);
77   const CMIUtilString &rCmdToQuery(pArgNamedCmdName->GetValue());
78   const MIuint nLen = rCmdToQuery.length();
79   const CMICmdFactory &rCmdFactory = CMICmdFactory::Instance();
80   if ((nLen > 1) && (rCmdToQuery[0] == '-'))
81     m_bCmdFound = rCmdFactory.CmdExist(rCmdToQuery.substr(1, nLen - 1).c_str());
82   else
83     m_bCmdFound = rCmdFactory.CmdExist(rCmdToQuery);
84 
85   return MIstatus::success;
86 }
87 
88 //++
89 //------------------------------------------------------------------------------------
90 // Details: The invoker requires this function. The command prepares a MI Record
91 // Result
92 //          for the work carried out in the Execute().
93 // Type:    Overridden.
94 // Args:    None.
95 // Return:  MIstatus::success - Functional succeeded.
96 //          MIstatus::failure - Functional failed.
97 // Throws:  None.
98 //--
Acknowledge()99 bool CMICmdCmdSupportInfoMiCmdQuery::Acknowledge() {
100   const CMICmnMIValueConst miValueConst(m_bCmdFound ? "true" : "false");
101   const CMICmnMIValueResult miValueResult("exists", miValueConst);
102   const CMICmnMIValueTuple miValueTuple(miValueResult);
103   const CMICmnMIValueResult miValueResult2("command", miValueTuple);
104   const CMICmnMIResultRecord miRecordResult(
105       m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done,
106       miValueResult2);
107   m_miResultRecord = miRecordResult;
108 
109   return MIstatus::success;
110 }
111 
112 //++
113 //------------------------------------------------------------------------------------
114 // Details: Required by the CMICmdFactory when registering *this command. The
115 // factory
116 //          calls this function to create an instance of *this command.
117 // Type:    Static method.
118 // Args:    None.
119 // Return:  CMICmdBase * - Pointer to a new command.
120 // Throws:  None.
121 //--
CreateSelf()122 CMICmdBase *CMICmdCmdSupportInfoMiCmdQuery::CreateSelf() {
123   return new CMICmdCmdSupportInfoMiCmdQuery();
124 }
125