]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdCmdFile.cpp
Merge ^/head r275623 through 275634.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdCmdFile.cpp
1 //===-- MICmdCmdFile.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 //++
11 // File:                MICmdCmdFile.cpp
12 //
13 // Overview:    CMICmdCmdFileExecAndSymbols             implementation.
14 //
15 // Environment: Compilers:      Visual C++ 12.
16 //                                                      gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 //                              Libraries:      See MIReadmetxt. 
18 //
19 // Copyright:   None.
20 //--
21
22 // Third Party Headers:
23 #include <lldb/API/SBStream.h>
24
25 // In-house headers:
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"
33
34 //++ ------------------------------------------------------------------------------------
35 // Details:     CMICmdCmdFileExecAndSymbols constructor.
36 // Type:        Method.
37 // Args:        None.
38 // Return:      None.
39 // Throws:      None.
40 //--
41 CMICmdCmdFileExecAndSymbols::CMICmdCmdFileExecAndSymbols( void )
42 :       m_constStrArgNameFile( "file" )
43 ,       m_constStrArgThreadGrp( "thread-group" )
44 {
45         // Command factory matches this name with that received from the stdin stream
46         m_strMiCmd = "file-exec-and-symbols";
47         
48         // Required by the CMICmdFactory when registering *this command
49         m_pSelfCreatorFn = &CMICmdCmdFileExecAndSymbols::CreateSelf;
50 }
51
52 //++ ------------------------------------------------------------------------------------
53 // Details:     CMICmdCmdFileExecAndSymbols destructor.
54 // Type:        Overrideable.
55 // Args:        None.
56 // Return:      None.
57 // Throws:      None.
58 //--
59 CMICmdCmdFileExecAndSymbols::~CMICmdCmdFileExecAndSymbols( void )
60 {
61 }
62
63 //++ ------------------------------------------------------------------------------------
64 // Details:     The invoker requires this function. The parses the command line options 
65 //                      arguments to extract values for each of those arguments.
66 // Type:        Overridden.
67 // Args:        None.
68 // Return:      MIstatus::success - Functional succeeded.
69 //                      MIstatus::failure - Functional failed.
70 // Throws:      None.
71 //--
72 bool CMICmdCmdFileExecAndSymbols::ParseArgs( void )
73 {
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() );
77 }
78
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
84 // Type:        Overridden.
85 // Args:        None.
86 // Return:      MIstatus::success - Functional succeeded.
87 //                      MIstatus::failure - Functional failed.
88 // Throws:      None.
89 //--
90 bool CMICmdCmdFileExecAndSymbols::Execute( void )
91 {
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;
97         lldb::SBError error;                                                            
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 ) )
105         {
106                 strWkDir = CMIUtilFileStd().StripOffFileName( strExeFilePath );
107                 if( !rSessionInfo.SharedDataAdd< CMIUtilString >( rStrKeyWkDir, strWkDir ) )
108                 {
109                         SetError( CMIUtilString::Format( MIRSRC( IDS_DBGSESSION_ERR_SHARED_DATA_ADD ), m_cmdData.strMiCmd.c_str(), rStrKeyWkDir.c_str() ) );
110                         return MIstatus::failure;
111                 }               
112         }
113         if( !rDbgr.SetCurrentPlatformSDKRoot( strWkDir.c_str() ) )
114         {
115
116                 SetError( CMIUtilString::Format( MIRSRC( IDS_CMD_ERR_FNFAILED ), m_cmdData.strMiCmd.c_str(), "SetCurrentPlatformSDKRoot()" ) );
117                 return MIstatus::failure;
118         }
119         lldb::SBStream err;
120         if( error.Fail() )
121         {
122                 const bool bOk = error.GetDescription( err ); MIunused( bOk );
123         }
124         if( !target.IsValid() )
125         {
126                 SetError( CMIUtilString::Format( MIRSRC( IDS_CMD_ERR_INVALID_TARGET ), m_cmdData.strMiCmd.c_str(), strExeFilePath.c_str(), err.GetData() ) );
127                 return MIstatus::failure;
128         }
129         if( error.Fail() )
130         {
131                 SetError( CMIUtilString::Format( MIRSRC( IDS_CMD_ERR_CREATE_TARGET ), m_cmdData.strMiCmd.c_str(), err.GetData() ) );
132                 return MIstatus::failure;
133         }
134
135         rSessionInfo.m_lldbTarget = target;
136
137         return MIstatus::success;
138 }
139
140 //++ ------------------------------------------------------------------------------------
141 // Details:     The invoker requires this function. The command prepares a MI Record Result
142 //                      for the work carried out in the Execute().
143 // Type:        Overridden.
144 // Args:        None.
145 // Return:      MIstatus::success - Functional succeeded.
146 //                      MIstatus::failure - Functional failed.
147 // Throws:      None.
148 //--
149 bool CMICmdCmdFileExecAndSymbols::Acknowledge( void )
150 {
151         const CMICmnMIResultRecord miRecordResult( m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done );
152         m_miResultRecord = miRecordResult;
153
154         return MIstatus::success;
155 }
156
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.
161 // Args:        None.
162 // Return:      CMICmdBase * - Pointer to a new command.
163 // Throws:      None.
164 //--
165 CMICmdBase * CMICmdCmdFileExecAndSymbols::CreateSelf( void )
166 {
167         return new CMICmdCmdFileExecAndSymbols();
168 }
169
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.
176 // Type:        Overridden.
177 // Args:        None.
178 // Return:      bool - True = Fatal if command fails, false = can continue if command fails.
179 // Throws:      None.
180 //--
181 bool CMICmdCmdFileExecAndSymbols::GetExitAppOnCommandFailure( void ) const
182 {
183         return true;
184 }