]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdCmdEnviro.cpp
Merge OpenSSL 1.0.2e.
[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 // Overview:    CMICmdCmdEnvironmentCd          implementation.
11
12 // In-house headers:
13 #include "MICmdCmdEnviro.h"
14 #include "MICmnMIResultRecord.h"
15 #include "MICmnMIValueConst.h"
16 #include "MICmnLLDBDebugger.h"
17 #include "MICmnLLDBDebugSessionInfo.h"
18 #include "MICmdArgValFile.h"
19
20 //++ ------------------------------------------------------------------------------------
21 // Details: CMICmdCmdEnvironmentCd constructor.
22 // Type:    Method.
23 // Args:    None.
24 // Return:  None.
25 // Throws:  None.
26 //--
27 CMICmdCmdEnvironmentCd::CMICmdCmdEnvironmentCd(void)
28     : m_constStrArgNamePathDir("pathdir")
29 {
30     // Command factory matches this name with that received from the stdin stream
31     m_strMiCmd = "environment-cd";
32
33     // Required by the CMICmdFactory when registering *this command
34     m_pSelfCreatorFn = &CMICmdCmdEnvironmentCd::CreateSelf;
35 }
36
37 //++ ------------------------------------------------------------------------------------
38 // Details: CMICmdCmdEnvironmentCd destructor.
39 // Type:    Overrideable.
40 // Args:    None.
41 // Return:  None.
42 // Throws:  None.
43 //--
44 CMICmdCmdEnvironmentCd::~CMICmdCmdEnvironmentCd(void)
45 {
46 }
47
48 //++ ------------------------------------------------------------------------------------
49 // Details: The invoker requires this function. The parses the command line options
50 //          arguments to extract values for each of those arguments.
51 // Type:    Overridden.
52 // Args:    None.
53 // Return:  MIstatus::success - Functional succeeded.
54 //          MIstatus::failure - Functional failed.
55 // Throws:  None.
56 //--
57 bool
58 CMICmdCmdEnvironmentCd::ParseArgs(void)
59 {
60     bool bOk = m_setCmdArgs.Add(*(new CMICmdArgValFile(m_constStrArgNamePathDir, true, true)));
61     CMICmdArgContext argCntxt(m_cmdData.strMiCmdOption);
62     return (bOk && ParseValidateCmdOptions());
63 }
64
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.
68 // Type:    Overridden.
69 // Args:    None.
70 // Return:  MIstatus::success - Functional succeeded.
71 //          MIstatus::failure - Functional failed.
72 // Throws:  None.
73 //--
74 bool
75 CMICmdCmdEnvironmentCd::Execute(void)
76 {
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());
82     if (bOk)
83     {
84         const CMIUtilString &rStrKeyWkDir(m_rLLDBDebugSessionInfo.m_constStrSharedDataKeyWkDir);
85         if (!m_rLLDBDebugSessionInfo.SharedDataAdd<CMIUtilString>(rStrKeyWkDir, strWkDir))
86         {
87             SetError(CMIUtilString::Format(MIRSRC(IDS_DBGSESSION_ERR_SHARED_DATA_ADD), m_cmdData.strMiCmd.c_str(), rStrKeyWkDir.c_str()));
88             bOk = MIstatus::failure;
89         }
90     }
91     else
92         SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_FNFAILED), m_cmdData.strMiCmd.c_str(), "SetCurrentPlatformSDKRoot()"));
93
94     return bOk;
95 }
96
97 //++ ------------------------------------------------------------------------------------
98 // Details: The invoker requires this function. The command prepares a MI Record Result
99 //          for the work carried out in the Execute().
100 // Type:    Overridden.
101 // Args:    None.
102 // Return:  MIstatus::success - Functional succeeded.
103 //          MIstatus::failure - Functional failed.
104 // Throws:  None.
105 //--
106 bool
107 CMICmdCmdEnvironmentCd::Acknowledge(void)
108 {
109     const CMIUtilString &rStrKeyWkDir(m_rLLDBDebugSessionInfo.m_constStrSharedDataKeyWkDir);
110     CMIUtilString strWkDir;
111     const bool bOk = m_rLLDBDebugSessionInfo.SharedDataRetrieve<CMIUtilString>(rStrKeyWkDir, strWkDir);
112     if (bOk)
113     {
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;
119     }
120
121     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SHARED_DATA_NOT_FOUND), m_cmdData.strMiCmd.c_str(), rStrKeyWkDir.c_str()));
122     return MIstatus::failure;
123 }
124
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.
129 // Args:    None.
130 // Return:  CMICmdBase * - Pointer to a new command.
131 // Throws:  None.
132 //--
133 CMICmdBase *
134 CMICmdCmdEnvironmentCd::CreateSelf(void)
135 {
136     return new CMICmdCmdEnvironmentCd();
137 }