1 //===-- MICmdCmdEnviro.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 //===----------------------------------------------------------------------===//
10 // Overview: CMICmdCmdEnvironmentCd implementation.
13 #include "MICmdCmdEnviro.h"
14 #include "MICmnMIResultRecord.h"
15 #include "MICmnMIValueConst.h"
16 #include "MICmnLLDBDebugger.h"
17 #include "MICmnLLDBDebugSessionInfo.h"
18 #include "MICmdArgValFile.h"
20 //++ ------------------------------------------------------------------------------------
21 // Details: CMICmdCmdEnvironmentCd constructor.
27 CMICmdCmdEnvironmentCd::CMICmdCmdEnvironmentCd(void)
28 : m_constStrArgNamePathDir("pathdir")
30 // Command factory matches this name with that received from the stdin stream
31 m_strMiCmd = "environment-cd";
33 // Required by the CMICmdFactory when registering *this command
34 m_pSelfCreatorFn = &CMICmdCmdEnvironmentCd::CreateSelf;
37 //++ ------------------------------------------------------------------------------------
38 // Details: CMICmdCmdEnvironmentCd destructor.
39 // Type: Overrideable.
44 CMICmdCmdEnvironmentCd::~CMICmdCmdEnvironmentCd(void)
48 //++ ------------------------------------------------------------------------------------
49 // Details: The invoker requires this function. The parses the command line options
50 // arguments to extract values for each of those arguments.
53 // Return: MIstatus::success - Functional succeeded.
54 // MIstatus::failure - Functional failed.
58 CMICmdCmdEnvironmentCd::ParseArgs(void)
60 bool bOk = m_setCmdArgs.Add(*(new CMICmdArgValFile(m_constStrArgNamePathDir, true, true)));
61 CMICmdArgContext argCntxt(m_cmdData.strMiCmdOption);
62 return (bOk && ParseValidateCmdOptions());
65 //++ ------------------------------------------------------------------------------------
66 // Details: The invoker requires this function. The command does work in this function.
67 // The command is likely to communicate with the LLDB SBDebugger in here.
70 // Return: MIstatus::success - Functional succeeded.
71 // MIstatus::failure - Functional failed.
75 CMICmdCmdEnvironmentCd::Execute(void)
77 CMICMDBASE_GETOPTION(pArgPathDir, File, m_constStrArgNamePathDir);
78 const CMIUtilString &strWkDir(pArgPathDir->GetValue());
79 CMICmnLLDBDebugger &rDbg(CMICmnLLDBDebugger::Instance());
80 lldb::SBDebugger &rLldbDbg = rDbg.GetTheDebugger();
81 bool bOk = rLldbDbg.SetCurrentPlatformSDKRoot(strWkDir.c_str());
84 const CMIUtilString &rStrKeyWkDir(m_rLLDBDebugSessionInfo.m_constStrSharedDataKeyWkDir);
85 if (!m_rLLDBDebugSessionInfo.SharedDataAdd<CMIUtilString>(rStrKeyWkDir, strWkDir))
87 SetError(CMIUtilString::Format(MIRSRC(IDS_DBGSESSION_ERR_SHARED_DATA_ADD), m_cmdData.strMiCmd.c_str(), rStrKeyWkDir.c_str()));
88 bOk = MIstatus::failure;
92 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_FNFAILED), m_cmdData.strMiCmd.c_str(), "SetCurrentPlatformSDKRoot()"));
97 //++ ------------------------------------------------------------------------------------
98 // Details: The invoker requires this function. The command prepares a MI Record Result
99 // for the work carried out in the Execute().
102 // Return: MIstatus::success - Functional succeeded.
103 // MIstatus::failure - Functional failed.
107 CMICmdCmdEnvironmentCd::Acknowledge(void)
109 const CMIUtilString &rStrKeyWkDir(m_rLLDBDebugSessionInfo.m_constStrSharedDataKeyWkDir);
110 CMIUtilString strWkDir;
111 const bool bOk = m_rLLDBDebugSessionInfo.SharedDataRetrieve<CMIUtilString>(rStrKeyWkDir, strWkDir);
114 const CMICmnMIValueConst miValueConst(strWkDir);
115 const CMICmnMIValueResult miValueResult("path", miValueConst);
116 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult);
117 m_miResultRecord = miRecordResult;
118 return MIstatus::success;
121 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SHARED_DATA_NOT_FOUND), m_cmdData.strMiCmd.c_str(), rStrKeyWkDir.c_str()));
122 return MIstatus::failure;
125 //++ ------------------------------------------------------------------------------------
126 // Details: Required by the CMICmdFactory when registering *this command. The factory
127 // calls this function to create an instance of *this command.
128 // Type: Static method.
130 // Return: CMICmdBase * - Pointer to a new command.
134 CMICmdCmdEnvironmentCd::CreateSelf(void)
136 return new CMICmdCmdEnvironmentCd();