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 "MICmdArgValFile.h"
15 #include "MICmnLLDBDebugSessionInfo.h"
16 #include "MICmnLLDBDebugger.h"
17 #include "MICmnMIResultRecord.h"
18 #include "MICmnMIValueConst.h"
21 //------------------------------------------------------------------------------------
22 // Details: CMICmdCmdEnvironmentCd constructor.
28 CMICmdCmdEnvironmentCd::CMICmdCmdEnvironmentCd()
29 : 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;
38 //------------------------------------------------------------------------------------
39 // Details: CMICmdCmdEnvironmentCd destructor.
40 // Type: Overrideable.
45 CMICmdCmdEnvironmentCd::~CMICmdCmdEnvironmentCd() {}
48 //------------------------------------------------------------------------------------
49 // Details: The invoker requires this function. The parses the command line
51 // arguments to extract values for each of those arguments.
54 // Return: MIstatus::success - Functional succeeded.
55 // MIstatus::failure - Functional failed.
58 bool CMICmdCmdEnvironmentCd::ParseArgs() {
59 m_setCmdArgs.Add(new CMICmdArgValFile(m_constStrArgNamePathDir, true, true));
60 CMICmdArgContext argCntxt(m_cmdData.strMiCmdOption);
61 return ParseValidateCmdOptions();
65 //------------------------------------------------------------------------------------
66 // Details: The invoker requires this function. The command does work in this
68 // The command is likely to communicate with the LLDB SBDebugger in
72 // Return: MIstatus::success - Functional succeeded.
73 // MIstatus::failure - Functional failed.
76 bool CMICmdCmdEnvironmentCd::Execute() {
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());
83 const CMIUtilString &rStrKeyWkDir(
84 m_rLLDBDebugSessionInfo.m_constStrSharedDataKeyWkDir);
85 if (!m_rLLDBDebugSessionInfo.SharedDataAdd<CMIUtilString>(rStrKeyWkDir,
87 SetError(CMIUtilString::Format(MIRSRC(IDS_DBGSESSION_ERR_SHARED_DATA_ADD),
88 m_cmdData.strMiCmd.c_str(),
89 rStrKeyWkDir.c_str()));
90 bOk = MIstatus::failure;
93 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_FNFAILED),
94 m_cmdData.strMiCmd.c_str(),
95 "SetCurrentPlatformSDKRoot()"));
97 lldb::SBTarget sbTarget = m_rLLDBDebugSessionInfo.GetTarget();
98 if (sbTarget.IsValid()) {
99 lldb::SBLaunchInfo sbLaunchInfo = sbTarget.GetLaunchInfo();
100 sbLaunchInfo.SetWorkingDirectory(strWkDir.c_str());
101 sbTarget.SetLaunchInfo(sbLaunchInfo);
108 //------------------------------------------------------------------------------------
109 // Details: The invoker requires this function. The command prepares a MI Record
111 // for the work carried out in the Execute().
114 // Return: MIstatus::success - Functional succeeded.
115 // MIstatus::failure - Functional failed.
118 bool CMICmdCmdEnvironmentCd::Acknowledge() {
119 const CMIUtilString &rStrKeyWkDir(
120 m_rLLDBDebugSessionInfo.m_constStrSharedDataKeyWkDir);
121 CMIUtilString strWkDir;
122 const bool bOk = m_rLLDBDebugSessionInfo.SharedDataRetrieve<CMIUtilString>(
123 rStrKeyWkDir, strWkDir);
125 const CMICmnMIValueConst miValueConst(strWkDir);
126 const CMICmnMIValueResult miValueResult("path", miValueConst);
127 const CMICmnMIResultRecord miRecordResult(
128 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done,
130 m_miResultRecord = miRecordResult;
131 return MIstatus::success;
134 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SHARED_DATA_NOT_FOUND),
135 m_cmdData.strMiCmd.c_str(),
136 rStrKeyWkDir.c_str()));
137 return MIstatus::failure;
141 //------------------------------------------------------------------------------------
142 // Details: Required by the CMICmdFactory when registering *this command. The
144 // calls this function to create an instance of *this command.
145 // Type: Static method.
147 // Return: CMICmdBase * - Pointer to a new command.
150 CMICmdBase *CMICmdCmdEnvironmentCd::CreateSelf() {
151 return new CMICmdCmdEnvironmentCd();