1 //===-- MICmdCmdFile.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: MICmdCmdFile.cpp
13 // Overview: CMICmdCmdFileExecAndSymbols implementation.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
22 // Third Party Headers:
23 #include <lldb/API/SBStream.h>
26 #include "MICmdCmdFile.h"
27 #include "MICmnMIResultRecord.h"
28 #include "MICmnLLDBDebugger.h"
29 #include "MICmnLLDBDebugSessionInfo.h"
30 #include "MIUtilFileStd.h"
31 #include "MICmdArgValFile.h"
32 #include "MICmdArgValOptionLong.h"
34 //++ ------------------------------------------------------------------------------------
35 // Details: CMICmdCmdFileExecAndSymbols constructor.
41 CMICmdCmdFileExecAndSymbols::CMICmdCmdFileExecAndSymbols( void )
42 : m_constStrArgNameFile( "file" )
43 , m_constStrArgThreadGrp( "thread-group" )
45 // Command factory matches this name with that received from the stdin stream
46 m_strMiCmd = "file-exec-and-symbols";
48 // Required by the CMICmdFactory when registering *this command
49 m_pSelfCreatorFn = &CMICmdCmdFileExecAndSymbols::CreateSelf;
52 //++ ------------------------------------------------------------------------------------
53 // Details: CMICmdCmdFileExecAndSymbols destructor.
54 // Type: Overrideable.
59 CMICmdCmdFileExecAndSymbols::~CMICmdCmdFileExecAndSymbols( void )
63 //++ ------------------------------------------------------------------------------------
64 // Details: The invoker requires this function. The parses the command line options
65 // arguments to extract values for each of those arguments.
68 // Return: MIstatus::success - Functional succeeded.
69 // MIstatus::failure - Functional failed.
72 bool CMICmdCmdFileExecAndSymbols::ParseArgs( void )
74 bool bOk = m_setCmdArgs.Add( *(new CMICmdArgValOptionLong( m_constStrArgThreadGrp, false, false, CMICmdArgValListBase::eArgValType_ThreadGrp, 1 ) ) );
75 bOk = bOk && m_setCmdArgs.Add( *(new CMICmdArgValFile( m_constStrArgNameFile, true, true ) ) );
76 return (bOk && ParseValidateCmdOptions() );
79 //++ ------------------------------------------------------------------------------------
80 // Details: The invoker requires this function. The command does work in this function.
81 // The command is likely to communicate with the LLDB SBDebugger in here.
82 // Synopsis: -file-exec-and-symbols file
83 // Ref: http://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-File-Commands.html#GDB_002fMI-File-Commands
86 // Return: MIstatus::success - Functional succeeded.
87 // MIstatus::failure - Functional failed.
90 bool CMICmdCmdFileExecAndSymbols::Execute( void )
92 CMICMDBASE_GETOPTION( pArgNamedFile, File, m_constStrArgNameFile );
93 CMICmdArgValFile * pArgFile = static_cast< CMICmdArgValFile * >( pArgNamedFile );
94 const CMIUtilString & strExeFilePath( pArgFile->GetValue() );
95 CMICmnLLDBDebugSessionInfo & rSessionInfo( CMICmnLLDBDebugSessionInfo::Instance() );
96 lldb::SBDebugger & rDbgr = rSessionInfo.m_rLldbDebugger;
98 const MIchar * pTargetTriple = nullptr; // Let LLDB discover the triple required
99 const MIchar * pTargetPlatformName = "";
100 const bool bAddDepModules = false;
101 lldb::SBTarget target = rDbgr.CreateTarget( strExeFilePath.c_str(), pTargetTriple, pTargetPlatformName, bAddDepModules, error );
102 CMIUtilString strWkDir;
103 const CMIUtilString & rStrKeyWkDir( rSessionInfo.m_constStrSharedDataKeyWkDir );
104 if( !rSessionInfo.SharedDataRetrieve< CMIUtilString >( rStrKeyWkDir, strWkDir ) )
106 strWkDir = CMIUtilFileStd().StripOffFileName( strExeFilePath );
107 if( !rSessionInfo.SharedDataAdd< CMIUtilString >( rStrKeyWkDir, strWkDir ) )
109 SetError( CMIUtilString::Format( MIRSRC( IDS_DBGSESSION_ERR_SHARED_DATA_ADD ), m_cmdData.strMiCmd.c_str(), rStrKeyWkDir.c_str() ) );
110 return MIstatus::failure;
113 if( !rDbgr.SetCurrentPlatformSDKRoot( strWkDir.c_str() ) )
116 SetError( CMIUtilString::Format( MIRSRC( IDS_CMD_ERR_FNFAILED ), m_cmdData.strMiCmd.c_str(), "SetCurrentPlatformSDKRoot()" ) );
117 return MIstatus::failure;
122 const bool bOk = error.GetDescription( err ); MIunused( bOk );
124 if( !target.IsValid() )
126 SetError( CMIUtilString::Format( MIRSRC( IDS_CMD_ERR_INVALID_TARGET ), m_cmdData.strMiCmd.c_str(), strExeFilePath.c_str(), err.GetData() ) );
127 return MIstatus::failure;
131 SetError( CMIUtilString::Format( MIRSRC( IDS_CMD_ERR_CREATE_TARGET ), m_cmdData.strMiCmd.c_str(), err.GetData() ) );
132 return MIstatus::failure;
135 rSessionInfo.m_lldbTarget = target;
137 return MIstatus::success;
140 //++ ------------------------------------------------------------------------------------
141 // Details: The invoker requires this function. The command prepares a MI Record Result
142 // for the work carried out in the Execute().
145 // Return: MIstatus::success - Functional succeeded.
146 // MIstatus::failure - Functional failed.
149 bool CMICmdCmdFileExecAndSymbols::Acknowledge( void )
151 const CMICmnMIResultRecord miRecordResult( m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done );
152 m_miResultRecord = miRecordResult;
154 return MIstatus::success;
157 //++ ------------------------------------------------------------------------------------
158 // Details: Required by the CMICmdFactory when registering *this command. The factory
159 // calls this function to create an instance of *this command.
160 // Type: Static method.
162 // Return: CMICmdBase * - Pointer to a new command.
165 CMICmdBase * CMICmdCmdFileExecAndSymbols::CreateSelf( void )
167 return new CMICmdCmdFileExecAndSymbols();
170 //++ ------------------------------------------------------------------------------------
171 // Details: If the MI Driver is not operating via a client i.e. Eclipse but say operating
172 // on a executable passed in as a argument to the drive then what should the driver
173 // do on a command failing? Either continue operating or exit the application.
174 // Override this function where a command failure cannot allow the driver to
175 // continue operating.
178 // Return: bool - True = Fatal if command fails, false = can continue if command fails.
181 bool CMICmdCmdFileExecAndSymbols::GetExitAppOnCommandFailure( void ) const