SBCommandInterpreter.cpp revision 63094e0bb161580564954dee512955c1c79d3476
1//===-- SBCommandInterpreter.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#include "lldb/lldb-types.h" 11#include "lldb/Interpreter/Args.h" 12#include "lldb/Core/SourceManager.h" 13#include "lldb/Core/Listener.h" 14#include "lldb/Interpreter/CommandInterpreter.h" 15#include "lldb/Interpreter/CommandReturnObject.h" 16#include "lldb/Target/Target.h" 17 18#include "lldb/API/SBBroadcaster.h" 19#include "lldb/API/SBDebugger.h" 20#include "lldb/API/SBCommandReturnObject.h" 21#include "lldb/API/SBCommandContext.h" 22#include "lldb/API/SBSourceManager.h" 23#include "lldb/API/SBCommandInterpreter.h" 24#include "lldb/API/SBProcess.h" 25#include "lldb/API/SBTarget.h" 26#include "lldb/API/SBListener.h" 27#include "lldb/API/SBStringList.h" 28 29using namespace lldb; 30using namespace lldb_private; 31 32 33SBCommandInterpreter::SBCommandInterpreter (CommandInterpreter *interpreter) : 34 m_opaque_ptr (interpreter) 35{ 36} 37 38SBCommandInterpreter::~SBCommandInterpreter () 39{ 40} 41 42bool 43SBCommandInterpreter::IsValid() const 44{ 45 return m_opaque_ptr != NULL; 46} 47 48 49bool 50SBCommandInterpreter::CommandExists (const char *cmd) 51{ 52 if (m_opaque_ptr) 53 return m_opaque_ptr->CommandExists (cmd); 54 return false; 55} 56 57bool 58SBCommandInterpreter::AliasExists (const char *cmd) 59{ 60 if (m_opaque_ptr) 61 return m_opaque_ptr->AliasExists (cmd); 62 return false; 63} 64 65bool 66SBCommandInterpreter::UserCommandExists (const char *cmd) 67{ 68 if (m_opaque_ptr) 69 return m_opaque_ptr->UserCommandExists (cmd); 70 return false; 71} 72 73lldb::ReturnStatus 74SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnObject &result, bool add_to_history) 75{ 76 result.Clear(); 77 if (m_opaque_ptr) 78 { 79 m_opaque_ptr->HandleCommand (command_line, add_to_history, result.ref()); 80 } 81 else 82 { 83 result->AppendError ("SBCommandInterpreter is not valid"); 84 result->SetStatus (eReturnStatusFailed); 85 } 86 return result.GetStatus(); 87} 88 89int 90SBCommandInterpreter::HandleCompletion (const char *current_line, 91 const char *cursor, 92 const char *last_char, 93 int match_start_point, 94 int max_return_elements, 95 SBStringList &matches) 96{ 97 int num_completions = 0; 98 if (m_opaque_ptr) 99 { 100 lldb_private::StringList lldb_matches; 101 num_completions = m_opaque_ptr->HandleCompletion (current_line, cursor, last_char, match_start_point, 102 max_return_elements, lldb_matches); 103 104 SBStringList temp_list (&lldb_matches); 105 matches.AppendList (temp_list); 106 } 107 return num_completions; 108} 109 110const char ** 111SBCommandInterpreter::GetEnvironmentVariables () 112{ 113 if (m_opaque_ptr) 114 { 115 const Args *env_vars = m_opaque_ptr->GetEnvironmentVariables(); 116 if (env_vars) 117 return env_vars->GetConstArgumentVector (); 118 } 119 return NULL; 120} 121 122bool 123SBCommandInterpreter::HasCommands () 124{ 125 if (m_opaque_ptr) 126 return m_opaque_ptr->HasCommands(); 127 return false; 128} 129 130bool 131SBCommandInterpreter::HasAliases () 132{ 133 if (m_opaque_ptr) 134 return m_opaque_ptr->HasAliases(); 135 return false; 136} 137 138bool 139SBCommandInterpreter::HasUserCommands () 140{ 141 if (m_opaque_ptr) 142 return m_opaque_ptr->HasUserCommands (); 143 return false; 144} 145 146bool 147SBCommandInterpreter::HasAliasOptions () 148{ 149 if (m_opaque_ptr) 150 return m_opaque_ptr->HasAliasOptions (); 151 return false; 152} 153 154bool 155SBCommandInterpreter::HasInterpreterVariables () 156{ 157 if (m_opaque_ptr) 158 return m_opaque_ptr->HasInterpreterVariables (); 159 return false; 160} 161 162SBProcess 163SBCommandInterpreter::GetProcess () 164{ 165 SBProcess process; 166 if (m_opaque_ptr) 167 { 168 Debugger &debugger = m_opaque_ptr->GetDebugger(); 169 Target *target = debugger.GetCurrentTarget().get(); 170 if (target) 171 process.SetProcess(target->GetProcessSP()); 172 } 173 return process; 174} 175 176ssize_t 177SBCommandInterpreter::WriteToScriptInterpreter (const char *src) 178{ 179 if (m_opaque_ptr && src && src[0]) 180 return WriteToScriptInterpreter (src, strlen(src)); 181 return 0; 182} 183 184ssize_t 185SBCommandInterpreter::WriteToScriptInterpreter (const char *src, size_t src_len) 186{ 187 if (m_opaque_ptr && src && src[0]) 188 { 189 ScriptInterpreter *script_interpreter = m_opaque_ptr->GetScriptInterpreter(); 190 if (script_interpreter) 191 return ::write (script_interpreter->GetMasterFileDescriptor(), src, src_len); 192 } 193 return 0; 194} 195 196 197CommandInterpreter * 198SBCommandInterpreter::get () 199{ 200 return m_opaque_ptr; 201} 202 203CommandInterpreter & 204SBCommandInterpreter::ref () 205{ 206 assert (m_opaque_ptr); 207 return *m_opaque_ptr; 208} 209 210void 211SBCommandInterpreter::reset (lldb_private::CommandInterpreter *interpreter) 212{ 213 m_opaque_ptr = interpreter; 214} 215 216void 217SBCommandInterpreter::SourceInitFileInHomeDirectory (SBCommandReturnObject &result) 218{ 219 result.Clear(); 220 if (m_opaque_ptr) 221 { 222 m_opaque_ptr->SourceInitFile (false, result.ref()); 223 } 224 else 225 { 226 result->AppendError ("SBCommandInterpreter is not valid"); 227 result->SetStatus (eReturnStatusFailed); 228 } 229} 230 231void 232SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory (SBCommandReturnObject &result) 233{ 234 result.Clear(); 235 if (m_opaque_ptr) 236 { 237 m_opaque_ptr->SourceInitFile (true, result.ref()); 238 } 239 else 240 { 241 result->AppendError ("SBCommandInterpreter is not valid"); 242 result->SetStatus (eReturnStatusFailed); 243 } 244} 245 246SBBroadcaster 247SBCommandInterpreter::GetBroadcaster () 248{ 249 SBBroadcaster broadcaster (m_opaque_ptr, false); 250 return broadcaster; 251} 252 253