]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/tools/lldb-mi/MICmdCmdSupportInfo.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / tools / lldb-mi / MICmdCmdSupportInfo.cpp
1 //===-- MICmdCmdSupportInfo.cpp ---------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8
9 // Overview:    CMICmdCmdSupportInfoMiCmdQuery          implementation.
10
11 // In-house headers:
12 #include "MICmdCmdSupportInfo.h"
13 #include "MICmdArgValString.h"
14 #include "MICmdFactory.h"
15 #include "MICmnMIResultRecord.h"
16 #include "MICmnMIValueConst.h"
17 #include "MICmnMIValueTuple.h"
18
19 //++
20 // Details: CMICmdCmdSupportInfoMiCmdQuery constructor.
21 // Type:    Method.
22 // Args:    None.
23 // Return:  None.
24 // Throws:  None.
25 //--
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";
30
31   // Required by the CMICmdFactory when registering *this command
32   m_pSelfCreatorFn = &CMICmdCmdSupportInfoMiCmdQuery::CreateSelf;
33 }
34
35 //++
36 // Details: CMICmdCmdSupportInfoMiCmdQuery destructor.
37 // Type:    Overrideable.
38 // Args:    None.
39 // Return:  None.
40 // Throws:  None.
41 //--
42 CMICmdCmdSupportInfoMiCmdQuery::~CMICmdCmdSupportInfoMiCmdQuery() {}
43
44 //++
45 // Details: The invoker requires this function. The parses the command line
46 // options
47 //          arguments to extract values for each of those arguments.
48 // Type:    Overridden.
49 // Args:    None.
50 // Return:  MIstatus::success - Functional succeeded.
51 //          MIstatus::failure - Functional failed.
52 // Throws:  None.
53 //--
54 bool CMICmdCmdSupportInfoMiCmdQuery::ParseArgs() {
55   m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgCmdName, true, true));
56   return ParseValidateCmdOptions();
57 }
58
59 //++
60 // Details: The invoker requires this function. The command does work in this
61 // function.
62 //          The command is likely to communicate with the LLDB SBDebugger in
63 //          here.
64 // Type:    Overridden.
65 // Args:    None.
66 // Return:  MIstatus::success - Functional succeeded.
67 //          MIstatus::failure - Functional failed.
68 // Throws:  None.
69 //--
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());
77   else
78     m_bCmdFound = rCmdFactory.CmdExist(rCmdToQuery);
79
80   return MIstatus::success;
81 }
82
83 //++
84 // Details: The invoker requires this function. The command prepares a MI Record
85 // Result
86 //          for the work carried out in the Execute().
87 // Type:    Overridden.
88 // Args:    None.
89 // Return:  MIstatus::success - Functional succeeded.
90 //          MIstatus::failure - Functional failed.
91 // Throws:  None.
92 //--
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,
100       miValueResult2);
101   m_miResultRecord = miRecordResult;
102
103   return MIstatus::success;
104 }
105
106 //++
107 // Details: Required by the CMICmdFactory when registering *this command. The
108 // factory
109 //          calls this function to create an instance of *this command.
110 // Type:    Static method.
111 // Args:    None.
112 // Return:  CMICmdBase * - Pointer to a new command.
113 // Throws:  None.
114 //--
115 CMICmdBase *CMICmdCmdSupportInfoMiCmdQuery::CreateSelf() {
116   return new CMICmdCmdSupportInfoMiCmdQuery();
117 }