]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdCmdEnviro.cpp
Upgrade to Unbound 1.5.4.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdCmdEnviro.cpp
1 //===-- MICmdCmdEnviro.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:        MICmdCmdEnviro.cpp
12 //
13 // Overview:    CMICmdCmdEnvironmentCd          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 "MICmdCmdEnviro.h"
24 #include "MICmnMIResultRecord.h"
25 #include "MICmnMIValueConst.h"
26 #include "MICmnLLDBDebugger.h"
27 #include "MICmnLLDBDebugSessionInfo.h"
28 #include "MICmdArgValFile.h"
29
30 //++ ------------------------------------------------------------------------------------
31 // Details: CMICmdCmdEnvironmentCd constructor.
32 // Type:    Method.
33 // Args:    None.
34 // Return:  None.
35 // Throws:  None.
36 //--
37 CMICmdCmdEnvironmentCd::CMICmdCmdEnvironmentCd(void)
38     : m_constStrArgNamePathDir("pathdir")
39 {
40     // Command factory matches this name with that received from the stdin stream
41     m_strMiCmd = "environment-cd";
42
43     // Required by the CMICmdFactory when registering *this command
44     m_pSelfCreatorFn = &CMICmdCmdEnvironmentCd::CreateSelf;
45 }
46
47 //++ ------------------------------------------------------------------------------------
48 // Details: CMICmdCmdEnvironmentCd destructor.
49 // Type:    Overrideable.
50 // Args:    None.
51 // Return:  None.
52 // Throws:  None.
53 //--
54 CMICmdCmdEnvironmentCd::~CMICmdCmdEnvironmentCd(void)
55 {
56 }
57
58 //++ ------------------------------------------------------------------------------------
59 // Details: The invoker requires this function. The parses the command line options
60 //          arguments to extract values for each of those arguments.
61 // Type:    Overridden.
62 // Args:    None.
63 // Return:  MIstatus::success - Functional succeeded.
64 //          MIstatus::failure - Functional failed.
65 // Throws:  None.
66 //--
67 bool
68 CMICmdCmdEnvironmentCd::ParseArgs(void)
69 {
70     bool bOk = m_setCmdArgs.Add(*(new CMICmdArgValFile(m_constStrArgNamePathDir, true, true)));
71     CMICmdArgContext argCntxt(m_cmdData.strMiCmdOption);
72     return (bOk && ParseValidateCmdOptions());
73 }
74
75 //++ ------------------------------------------------------------------------------------
76 // Details: The invoker requires this function. The command does work in this function.
77 //          The command is likely to communicate with the LLDB SBDebugger in here.
78 // Type:    Overridden.
79 // Args:    None.
80 // Return:  MIstatus::success - Functional succeeded.
81 //          MIstatus::failure - Functional failed.
82 // Throws:  None.
83 //--
84 bool
85 CMICmdCmdEnvironmentCd::Execute(void)
86 {
87     CMICMDBASE_GETOPTION(pArgPathDir, File, m_constStrArgNamePathDir);
88     const CMIUtilString &strWkDir(pArgPathDir->GetValue());
89     CMICmnLLDBDebugger &rDbg(CMICmnLLDBDebugger::Instance());
90     lldb::SBDebugger &rLldbDbg = rDbg.GetTheDebugger();
91     bool bOk = rLldbDbg.SetCurrentPlatformSDKRoot(strWkDir.c_str());
92     if (bOk)
93     {
94         const CMIUtilString &rStrKeyWkDir(m_rLLDBDebugSessionInfo.m_constStrSharedDataKeyWkDir);
95         if (!m_rLLDBDebugSessionInfo.SharedDataAdd<CMIUtilString>(rStrKeyWkDir, strWkDir))
96         {
97             SetError(CMIUtilString::Format(MIRSRC(IDS_DBGSESSION_ERR_SHARED_DATA_ADD), m_cmdData.strMiCmd.c_str(), rStrKeyWkDir.c_str()));
98             bOk = MIstatus::failure;
99         }
100     }
101     else
102         SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_FNFAILED), m_cmdData.strMiCmd.c_str(), "SetCurrentPlatformSDKRoot()"));
103
104     return bOk;
105 }
106
107 //++ ------------------------------------------------------------------------------------
108 // Details: The invoker requires this function. The command prepares a MI Record Result
109 //          for the work carried out in the Execute().
110 // Type:    Overridden.
111 // Args:    None.
112 // Return:  MIstatus::success - Functional succeeded.
113 //          MIstatus::failure - Functional failed.
114 // Throws:  None.
115 //--
116 bool
117 CMICmdCmdEnvironmentCd::Acknowledge(void)
118 {
119     const CMIUtilString &rStrKeyWkDir(m_rLLDBDebugSessionInfo.m_constStrSharedDataKeyWkDir);
120     CMIUtilString strWkDir;
121     const bool bOk = m_rLLDBDebugSessionInfo.SharedDataRetrieve<CMIUtilString>(rStrKeyWkDir, strWkDir);
122     if (bOk)
123     {
124         const CMICmnMIValueConst miValueConst(strWkDir);
125         const CMICmnMIValueResult miValueResult("path", miValueConst);
126         const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult);
127         m_miResultRecord = miRecordResult;
128         return MIstatus::success;
129     }
130
131     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SHARED_DATA_NOT_FOUND), m_cmdData.strMiCmd.c_str(), rStrKeyWkDir.c_str()));
132     return MIstatus::failure;
133 }
134
135 //++ ------------------------------------------------------------------------------------
136 // Details: Required by the CMICmdFactory when registering *this command. The factory
137 //          calls this function to create an instance of *this command.
138 // Type:    Static method.
139 // Args:    None.
140 // Return:  CMICmdBase * - Pointer to a new command.
141 // Throws:  None.
142 //--
143 CMICmdBase *
144 CMICmdCmdEnvironmentCd::CreateSelf(void)
145 {
146     return new CMICmdCmdEnvironmentCd();
147 }