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 //===----------------------------------------------------------------------===//
11 // File: MICmdCmdEnviro.cpp
13 // Overview: CMICmdCmdEnvironmentCd implementation.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
23 #include "MICmdCmdEnviro.h"
24 #include "MICmnMIResultRecord.h"
25 #include "MICmnMIValueConst.h"
26 #include "MICmnLLDBDebugger.h"
27 #include "MICmnLLDBDebugSessionInfo.h"
28 #include "MICmdArgValFile.h"
30 //++ ------------------------------------------------------------------------------------
31 // Details: CMICmdCmdEnvironmentCd constructor.
37 CMICmdCmdEnvironmentCd::CMICmdCmdEnvironmentCd(void)
38 : m_constStrArgNamePathDir("pathdir")
40 // Command factory matches this name with that received from the stdin stream
41 m_strMiCmd = "environment-cd";
43 // Required by the CMICmdFactory when registering *this command
44 m_pSelfCreatorFn = &CMICmdCmdEnvironmentCd::CreateSelf;
47 //++ ------------------------------------------------------------------------------------
48 // Details: CMICmdCmdEnvironmentCd destructor.
49 // Type: Overrideable.
54 CMICmdCmdEnvironmentCd::~CMICmdCmdEnvironmentCd(void)
58 //++ ------------------------------------------------------------------------------------
59 // Details: The invoker requires this function. The parses the command line options
60 // arguments to extract values for each of those arguments.
63 // Return: MIstatus::success - Functional succeeded.
64 // MIstatus::failure - Functional failed.
68 CMICmdCmdEnvironmentCd::ParseArgs(void)
70 bool bOk = m_setCmdArgs.Add(*(new CMICmdArgValFile(m_constStrArgNamePathDir, true, true)));
71 CMICmdArgContext argCntxt(m_cmdData.strMiCmdOption);
72 return (bOk && ParseValidateCmdOptions());
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.
80 // Return: MIstatus::success - Functional succeeded.
81 // MIstatus::failure - Functional failed.
85 CMICmdCmdEnvironmentCd::Execute(void)
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());
94 const CMIUtilString &rStrKeyWkDir(m_rLLDBDebugSessionInfo.m_constStrSharedDataKeyWkDir);
95 if (!m_rLLDBDebugSessionInfo.SharedDataAdd<CMIUtilString>(rStrKeyWkDir, strWkDir))
97 SetError(CMIUtilString::Format(MIRSRC(IDS_DBGSESSION_ERR_SHARED_DATA_ADD), m_cmdData.strMiCmd.c_str(), rStrKeyWkDir.c_str()));
98 bOk = MIstatus::failure;
102 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_FNFAILED), m_cmdData.strMiCmd.c_str(), "SetCurrentPlatformSDKRoot()"));
107 //++ ------------------------------------------------------------------------------------
108 // Details: The invoker requires this function. The command prepares a MI Record Result
109 // for the work carried out in the Execute().
112 // Return: MIstatus::success - Functional succeeded.
113 // MIstatus::failure - Functional failed.
117 CMICmdCmdEnvironmentCd::Acknowledge(void)
119 const CMIUtilString &rStrKeyWkDir(m_rLLDBDebugSessionInfo.m_constStrSharedDataKeyWkDir);
120 CMIUtilString strWkDir;
121 const bool bOk = m_rLLDBDebugSessionInfo.SharedDataRetrieve<CMIUtilString>(rStrKeyWkDir, strWkDir);
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;
131 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SHARED_DATA_NOT_FOUND), m_cmdData.strMiCmd.c_str(), rStrKeyWkDir.c_str()));
132 return MIstatus::failure;
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.
140 // Return: CMICmdBase * - Pointer to a new command.
144 CMICmdCmdEnvironmentCd::CreateSelf(void)
146 return new CMICmdCmdEnvironmentCd();