Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "lldb/lldb-types.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | #include "lldb/Core/SourceManager.h" |
| 14 | #include "lldb/Core/Listener.h" |
| 15 | #include "lldb/Interpreter/CommandInterpreter.h" |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 16 | #include "lldb/Interpreter/CommandObjectMultiword.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 18 | #include "lldb/Target/Target.h" |
| 19 | |
Eli Friedman | ca93cc1 | 2010-06-09 07:37:52 +0000 | [diff] [blame] | 20 | #include "lldb/API/SBBroadcaster.h" |
Eli Friedman | ca93cc1 | 2010-06-09 07:37:52 +0000 | [diff] [blame] | 21 | #include "lldb/API/SBCommandReturnObject.h" |
Eli Friedman | ca93cc1 | 2010-06-09 07:37:52 +0000 | [diff] [blame] | 22 | #include "lldb/API/SBCommandInterpreter.h" |
| 23 | #include "lldb/API/SBProcess.h" |
| 24 | #include "lldb/API/SBTarget.h" |
| 25 | #include "lldb/API/SBListener.h" |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 26 | #include "lldb/API/SBStream.h" |
Eli Friedman | ca93cc1 | 2010-06-09 07:37:52 +0000 | [diff] [blame] | 27 | #include "lldb/API/SBStringList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | |
| 29 | using namespace lldb; |
| 30 | using namespace lldb_private; |
| 31 | |
Jim Ingham | 26c7bf9 | 2014-10-11 00:38:27 +0000 | [diff] [blame^] | 32 | SBCommandInterpreterRunOptions::SBCommandInterpreterRunOptions() |
| 33 | { |
| 34 | m_opaque_up.reset(new CommandInterpreterRunOptions()); |
| 35 | } |
| 36 | |
| 37 | SBCommandInterpreterRunOptions::~SBCommandInterpreterRunOptions() |
| 38 | { |
| 39 | |
| 40 | } |
| 41 | |
| 42 | bool |
| 43 | SBCommandInterpreterRunOptions::GetStopOnContinue () const |
| 44 | { |
| 45 | return m_opaque_up->GetStopOnContinue(); |
| 46 | } |
| 47 | |
| 48 | void |
| 49 | SBCommandInterpreterRunOptions::SetStopOnContinue (bool stop_on_continue) |
| 50 | { |
| 51 | m_opaque_up->SetStopOnContinue(stop_on_continue); |
| 52 | } |
| 53 | |
| 54 | bool |
| 55 | SBCommandInterpreterRunOptions::GetStopOnError () const |
| 56 | { |
| 57 | return m_opaque_up->GetStopOnError(); |
| 58 | } |
| 59 | |
| 60 | void |
| 61 | SBCommandInterpreterRunOptions::SetStopOnError (bool stop_on_error) |
| 62 | { |
| 63 | m_opaque_up->SetStopOnError(stop_on_error); |
| 64 | } |
| 65 | |
| 66 | bool |
| 67 | SBCommandInterpreterRunOptions::GetStopOnCrash () const |
| 68 | { |
| 69 | return m_opaque_up->GetStopOnCrash(); |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | SBCommandInterpreterRunOptions::SetStopOnCrash (bool stop_on_crash) |
| 74 | { |
| 75 | m_opaque_up->SetStopOnCrash(stop_on_crash); |
| 76 | } |
| 77 | |
| 78 | bool |
| 79 | SBCommandInterpreterRunOptions::GetEchoCommands () const |
| 80 | { |
| 81 | return m_opaque_up->GetEchoCommands(); |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | SBCommandInterpreterRunOptions::SetEchoCommands (bool echo_commands) |
| 86 | { |
| 87 | m_opaque_up->SetEchoCommands(echo_commands); |
| 88 | } |
| 89 | |
| 90 | bool |
| 91 | SBCommandInterpreterRunOptions::GetPrintResults () const |
| 92 | { |
| 93 | return m_opaque_up->GetPrintResults(); |
| 94 | } |
| 95 | |
| 96 | void |
| 97 | SBCommandInterpreterRunOptions::SetPrintResults (bool print_results) |
| 98 | { |
| 99 | m_opaque_up->SetPrintResults(print_results); |
| 100 | } |
| 101 | |
| 102 | bool |
| 103 | SBCommandInterpreterRunOptions::GetAddToHistory () const |
| 104 | { |
| 105 | return m_opaque_up->GetAddToHistory(); |
| 106 | } |
| 107 | |
| 108 | void |
| 109 | SBCommandInterpreterRunOptions::SetAddToHistory (bool add_to_history) |
| 110 | { |
| 111 | m_opaque_up->SetAddToHistory(add_to_history); |
| 112 | } |
| 113 | |
| 114 | lldb_private::CommandInterpreterRunOptions * |
| 115 | SBCommandInterpreterRunOptions::get () const |
| 116 | { |
| 117 | return m_opaque_up.get(); |
| 118 | } |
| 119 | |
| 120 | lldb_private::CommandInterpreterRunOptions & |
| 121 | SBCommandInterpreterRunOptions::ref () const |
| 122 | { |
| 123 | return *m_opaque_up.get(); |
| 124 | } |
| 125 | |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 126 | class CommandPluginInterfaceImplementation : public CommandObjectParsed |
| 127 | { |
| 128 | public: |
| 129 | CommandPluginInterfaceImplementation (CommandInterpreter &interpreter, |
| 130 | const char *name, |
| 131 | lldb::SBCommandPluginInterface* backend, |
| 132 | const char *help = NULL, |
| 133 | const char *syntax = NULL, |
| 134 | uint32_t flags = 0) : |
| 135 | CommandObjectParsed (interpreter, name, help, syntax, flags), |
| 136 | m_backend(backend) {} |
| 137 | |
| 138 | virtual bool |
Greg Clayton | 3a18e31 | 2012-10-08 22:41:53 +0000 | [diff] [blame] | 139 | IsRemovable() const { return true; } |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 140 | |
| 141 | protected: |
| 142 | virtual bool |
| 143 | DoExecute (Args& command, CommandReturnObject &result) |
| 144 | { |
| 145 | SBCommandReturnObject sb_return(&result); |
| 146 | SBCommandInterpreter sb_interpreter(&m_interpreter); |
| 147 | SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this()); |
| 148 | bool ret = m_backend->DoExecute (debugger_sb,(char**)command.GetArgumentVector(), sb_return); |
| 149 | sb_return.Release(); |
| 150 | return ret; |
| 151 | } |
| 152 | lldb::SBCommandPluginInterface* m_backend; |
| 153 | }; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 154 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 155 | SBCommandInterpreter::SBCommandInterpreter (CommandInterpreter *interpreter) : |
| 156 | m_opaque_ptr (interpreter) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 157 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 158 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 159 | |
| 160 | if (log) |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 161 | log->Printf ("SBCommandInterpreter::SBCommandInterpreter (interpreter=%p)" |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 162 | " => SBCommandInterpreter(%p)", |
| 163 | static_cast<void*>(interpreter), |
| 164 | static_cast<void*>(m_opaque_ptr)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Greg Clayton | efabb12 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 167 | SBCommandInterpreter::SBCommandInterpreter(const SBCommandInterpreter &rhs) : |
| 168 | m_opaque_ptr (rhs.m_opaque_ptr) |
| 169 | { |
| 170 | } |
| 171 | |
| 172 | const SBCommandInterpreter & |
| 173 | SBCommandInterpreter::operator = (const SBCommandInterpreter &rhs) |
| 174 | { |
| 175 | m_opaque_ptr = rhs.m_opaque_ptr; |
| 176 | return *this; |
| 177 | } |
| 178 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 179 | SBCommandInterpreter::~SBCommandInterpreter () |
| 180 | { |
| 181 | } |
| 182 | |
| 183 | bool |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 184 | SBCommandInterpreter::IsValid() const |
| 185 | { |
| 186 | return m_opaque_ptr != NULL; |
| 187 | } |
| 188 | |
| 189 | |
| 190 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 191 | SBCommandInterpreter::CommandExists (const char *cmd) |
| 192 | { |
Johnny Chen | 872e062 | 2011-12-19 21:16:29 +0000 | [diff] [blame] | 193 | if (cmd && m_opaque_ptr) |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 194 | return m_opaque_ptr->CommandExists (cmd); |
| 195 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | bool |
| 199 | SBCommandInterpreter::AliasExists (const char *cmd) |
| 200 | { |
Johnny Chen | 872e062 | 2011-12-19 21:16:29 +0000 | [diff] [blame] | 201 | if (cmd && m_opaque_ptr) |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 202 | return m_opaque_ptr->AliasExists (cmd); |
| 203 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 206 | bool |
| 207 | SBCommandInterpreter::IsActive () |
| 208 | { |
| 209 | if (m_opaque_ptr) |
| 210 | return m_opaque_ptr->IsActive (); |
| 211 | return false; |
| 212 | } |
| 213 | |
| 214 | const char * |
| 215 | SBCommandInterpreter::GetIOHandlerControlSequence(char ch) |
| 216 | { |
| 217 | if (m_opaque_ptr) |
| 218 | return m_opaque_ptr->GetDebugger().GetTopIOHandlerControlSequence (ch).GetCString(); |
| 219 | return NULL; |
| 220 | } |
| 221 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 222 | lldb::ReturnStatus |
| 223 | SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnObject &result, bool add_to_history) |
| 224 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 225 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 226 | |
| 227 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 228 | log->Printf ("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", SBCommandReturnObject(%p), add_to_history=%i)", |
| 229 | static_cast<void*>(m_opaque_ptr), command_line, |
| 230 | static_cast<void*>(result.get()), add_to_history); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 231 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 232 | result.Clear(); |
Johnny Chen | 872e062 | 2011-12-19 21:16:29 +0000 | [diff] [blame] | 233 | if (command_line && m_opaque_ptr) |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 234 | { |
Greg Clayton | 45a44f3 | 2014-07-15 00:25:59 +0000 | [diff] [blame] | 235 | result.ref().SetInteractive(false); |
Enrico Granata | 5f5ab60 | 2012-05-31 01:09:06 +0000 | [diff] [blame] | 236 | m_opaque_ptr->HandleCommand (command_line, add_to_history ? eLazyBoolYes : eLazyBoolNo, result.ref()); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 237 | } |
| 238 | else |
| 239 | { |
Johnny Chen | 872e062 | 2011-12-19 21:16:29 +0000 | [diff] [blame] | 240 | result->AppendError ("SBCommandInterpreter or the command line is not valid"); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 241 | result->SetStatus (eReturnStatusFailed); |
| 242 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 243 | |
Caroline Tice | 7b9da4a | 2010-10-27 21:23:37 +0000 | [diff] [blame] | 244 | // We need to get the value again, in case the command disabled the log! |
| 245 | log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 246 | if (log) |
| 247 | { |
| 248 | SBStream sstr; |
| 249 | result.GetDescription (sstr); |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 250 | log->Printf ("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", SBCommandReturnObject(%p): %s, add_to_history=%i) => %i", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 251 | static_cast<void*>(m_opaque_ptr), command_line, |
| 252 | static_cast<void*>(result.get()), sstr.GetData(), |
| 253 | add_to_history, result.GetStatus()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 256 | return result.GetStatus(); |
| 257 | } |
| 258 | |
| 259 | int |
| 260 | SBCommandInterpreter::HandleCompletion (const char *current_line, |
| 261 | const char *cursor, |
| 262 | const char *last_char, |
| 263 | int match_start_point, |
| 264 | int max_return_elements, |
| 265 | SBStringList &matches) |
| 266 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 267 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 268 | int num_completions = 0; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 269 | |
Jim Ingham | ac01260 | 2011-12-05 19:24:15 +0000 | [diff] [blame] | 270 | // Sanity check the arguments that are passed in: |
| 271 | // cursor & last_char have to be within the current_line. |
| 272 | if (current_line == NULL || cursor == NULL || last_char == NULL) |
| 273 | return 0; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 274 | |
Jim Ingham | ac01260 | 2011-12-05 19:24:15 +0000 | [diff] [blame] | 275 | if (cursor < current_line || last_char < current_line) |
| 276 | return 0; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 277 | |
Jim Ingham | ac01260 | 2011-12-05 19:24:15 +0000 | [diff] [blame] | 278 | size_t current_line_size = strlen (current_line); |
Saleem Abdulrasool | 3985c8c | 2014-04-02 03:51:35 +0000 | [diff] [blame] | 279 | if (cursor - current_line > static_cast<ptrdiff_t>(current_line_size) || |
| 280 | last_char - current_line > static_cast<ptrdiff_t>(current_line_size)) |
Jim Ingham | ac01260 | 2011-12-05 19:24:15 +0000 | [diff] [blame] | 281 | return 0; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 282 | |
Jim Ingham | 389512d | 2012-06-26 01:21:59 +0000 | [diff] [blame] | 283 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 284 | log->Printf ("SBCommandInterpreter(%p)::HandleCompletion (current_line=\"%s\", cursor at: %" PRId64 ", last char at: %" PRId64 ", match_start_point: %d, max_return_elements: %d)", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 285 | static_cast<void*>(m_opaque_ptr), current_line, |
| 286 | static_cast<uint64_t>(cursor - current_line), |
| 287 | static_cast<uint64_t>(last_char - current_line), |
| 288 | match_start_point, max_return_elements); |
| 289 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 290 | if (m_opaque_ptr) |
| 291 | { |
| 292 | lldb_private::StringList lldb_matches; |
| 293 | num_completions = m_opaque_ptr->HandleCompletion (current_line, cursor, last_char, match_start_point, |
| 294 | max_return_elements, lldb_matches); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 295 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 296 | SBStringList temp_list (&lldb_matches); |
| 297 | matches.AppendList (temp_list); |
| 298 | } |
Jim Ingham | 389512d | 2012-06-26 01:21:59 +0000 | [diff] [blame] | 299 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 300 | log->Printf ("SBCommandInterpreter(%p)::HandleCompletion - Found %d completions.", |
| 301 | static_cast<void*>(m_opaque_ptr), num_completions); |
| 302 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 303 | return num_completions; |
| 304 | } |
| 305 | |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 306 | int |
| 307 | SBCommandInterpreter::HandleCompletion (const char *current_line, |
| 308 | uint32_t cursor_pos, |
| 309 | int match_start_point, |
| 310 | int max_return_elements, |
| 311 | lldb::SBStringList &matches) |
| 312 | { |
| 313 | const char *cursor = current_line + cursor_pos; |
| 314 | const char *last_char = current_line + strlen (current_line); |
| 315 | return HandleCompletion (current_line, cursor, last_char, match_start_point, max_return_elements, matches); |
| 316 | } |
| 317 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 318 | bool |
| 319 | SBCommandInterpreter::HasCommands () |
| 320 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 321 | if (m_opaque_ptr) |
| 322 | return m_opaque_ptr->HasCommands(); |
| 323 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | bool |
| 327 | SBCommandInterpreter::HasAliases () |
| 328 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 329 | if (m_opaque_ptr) |
| 330 | return m_opaque_ptr->HasAliases(); |
| 331 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 335 | SBCommandInterpreter::HasAliasOptions () |
| 336 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 337 | if (m_opaque_ptr) |
| 338 | return m_opaque_ptr->HasAliasOptions (); |
| 339 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 342 | SBProcess |
| 343 | SBCommandInterpreter::GetProcess () |
| 344 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 345 | SBProcess sb_process; |
| 346 | ProcessSP process_sp; |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 347 | if (m_opaque_ptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 348 | { |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 349 | TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); |
| 350 | if (target_sp) |
| 351 | { |
| 352 | Mutex::Locker api_locker(target_sp->GetAPIMutex()); |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 353 | process_sp = target_sp->GetProcessSP(); |
| 354 | sb_process.SetSP(process_sp); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 355 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 356 | } |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 357 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 358 | |
| 359 | if (log) |
| 360 | log->Printf ("SBCommandInterpreter(%p)::GetProcess () => SBProcess(%p)", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 361 | static_cast<void*>(m_opaque_ptr), |
| 362 | static_cast<void*>(process_sp.get())); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 363 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 364 | return sb_process; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 367 | SBDebugger |
| 368 | SBCommandInterpreter::GetDebugger () |
| 369 | { |
| 370 | SBDebugger sb_debugger; |
| 371 | if (m_opaque_ptr) |
| 372 | sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this()); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 373 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 374 | |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 375 | if (log) |
| 376 | log->Printf ("SBCommandInterpreter(%p)::GetDebugger () => SBDebugger(%p)", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 377 | static_cast<void*>(m_opaque_ptr), |
| 378 | static_cast<void*>(sb_debugger.get())); |
| 379 | |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 380 | return sb_debugger; |
| 381 | } |
| 382 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 383 | CommandInterpreter * |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 384 | SBCommandInterpreter::get () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 385 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 386 | return m_opaque_ptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | CommandInterpreter & |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 390 | SBCommandInterpreter::ref () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 391 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 392 | assert (m_opaque_ptr); |
| 393 | return *m_opaque_ptr; |
| 394 | } |
| 395 | |
| 396 | void |
| 397 | SBCommandInterpreter::reset (lldb_private::CommandInterpreter *interpreter) |
| 398 | { |
| 399 | m_opaque_ptr = interpreter; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | void |
| 403 | SBCommandInterpreter::SourceInitFileInHomeDirectory (SBCommandReturnObject &result) |
| 404 | { |
| 405 | result.Clear(); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 406 | if (m_opaque_ptr) |
| 407 | { |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 408 | TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); |
| 409 | Mutex::Locker api_locker; |
| 410 | if (target_sp) |
Jim Ingham | 10ebffa | 2012-05-04 23:02:50 +0000 | [diff] [blame] | 411 | api_locker.Lock(target_sp->GetAPIMutex()); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 412 | m_opaque_ptr->SourceInitFile (false, result.ref()); |
| 413 | } |
| 414 | else |
| 415 | { |
| 416 | result->AppendError ("SBCommandInterpreter is not valid"); |
| 417 | result->SetStatus (eReturnStatusFailed); |
| 418 | } |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 419 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 420 | |
| 421 | if (log) |
| 422 | log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInHomeDirectory (&SBCommandReturnObject(%p))", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 423 | static_cast<void*>(m_opaque_ptr), |
| 424 | static_cast<void*>(result.get())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | void |
| 428 | SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory (SBCommandReturnObject &result) |
| 429 | { |
| 430 | result.Clear(); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 431 | if (m_opaque_ptr) |
| 432 | { |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 433 | TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); |
| 434 | Mutex::Locker api_locker; |
| 435 | if (target_sp) |
Jim Ingham | 10ebffa | 2012-05-04 23:02:50 +0000 | [diff] [blame] | 436 | api_locker.Lock(target_sp->GetAPIMutex()); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 437 | m_opaque_ptr->SourceInitFile (true, result.ref()); |
| 438 | } |
| 439 | else |
| 440 | { |
| 441 | result->AppendError ("SBCommandInterpreter is not valid"); |
| 442 | result->SetStatus (eReturnStatusFailed); |
| 443 | } |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 444 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 445 | |
| 446 | if (log) |
| 447 | log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInCurrentWorkingDirectory (&SBCommandReturnObject(%p))", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 448 | static_cast<void*>(m_opaque_ptr), |
| 449 | static_cast<void*>(result.get())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | SBBroadcaster |
| 453 | SBCommandInterpreter::GetBroadcaster () |
| 454 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 455 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 456 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 457 | SBBroadcaster broadcaster (m_opaque_ptr, false); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 458 | |
| 459 | if (log) |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 460 | log->Printf ("SBCommandInterpreter(%p)::GetBroadcaster() => SBBroadcaster(%p)", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 461 | static_cast<void*>(m_opaque_ptr), static_cast<void*>(broadcaster.get())); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 462 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 463 | return broadcaster; |
| 464 | } |
| 465 | |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 466 | const char * |
| 467 | SBCommandInterpreter::GetBroadcasterClass () |
| 468 | { |
| 469 | return Communication::GetStaticBroadcasterClass().AsCString(); |
| 470 | } |
| 471 | |
Greg Clayton | 9d0402b | 2011-02-20 02:15:07 +0000 | [diff] [blame] | 472 | const char * |
| 473 | SBCommandInterpreter::GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type) |
| 474 | { |
| 475 | return CommandObject::GetArgumentTypeAsCString (arg_type); |
| 476 | } |
| 477 | |
| 478 | const char * |
| 479 | SBCommandInterpreter::GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type) |
| 480 | { |
| 481 | return CommandObject::GetArgumentDescriptionAsCString (arg_type); |
| 482 | } |
| 483 | |
Greg Clayton | a9f7b79 | 2012-02-29 04:21:24 +0000 | [diff] [blame] | 484 | bool |
| 485 | SBCommandInterpreter::SetCommandOverrideCallback (const char *command_name, |
| 486 | lldb::CommandOverrideCallback callback, |
| 487 | void *baton) |
| 488 | { |
| 489 | if (command_name && command_name[0] && m_opaque_ptr) |
| 490 | { |
Greg Clayton | af6f275 | 2012-05-08 04:29:20 +0000 | [diff] [blame] | 491 | std::string command_name_str (command_name); |
| 492 | CommandObject *cmd_obj = m_opaque_ptr->GetCommandObjectForCommand(command_name_str); |
Greg Clayton | a9f7b79 | 2012-02-29 04:21:24 +0000 | [diff] [blame] | 493 | if (cmd_obj) |
| 494 | { |
Greg Clayton | af6f275 | 2012-05-08 04:29:20 +0000 | [diff] [blame] | 495 | assert(command_name_str.empty()); |
Greg Clayton | a9f7b79 | 2012-02-29 04:21:24 +0000 | [diff] [blame] | 496 | cmd_obj->SetOverrideCallback (callback, baton); |
| 497 | return true; |
| 498 | } |
| 499 | } |
| 500 | return false; |
| 501 | } |
Greg Clayton | 9d0402b | 2011-02-20 02:15:07 +0000 | [diff] [blame] | 502 | |
Greg Clayton | dce502e | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 503 | #ifndef LLDB_DISABLE_PYTHON |
Enrico Granata | be93a35 | 2011-08-16 16:49:25 +0000 | [diff] [blame] | 504 | |
Greg Clayton | dce502e | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 505 | // Defined in the SWIG source file |
| 506 | extern "C" void |
| 507 | init_lldb(void); |
| 508 | |
Greg Clayton | 8afa543 | 2013-10-17 00:27:14 +0000 | [diff] [blame] | 509 | // these are the Pythonic implementations of the required callbacks |
| 510 | // these are scripting-language specific, which is why they belong here |
| 511 | // we still need to use function pointers to them instead of relying |
| 512 | // on linkage-time resolution because the SWIG stuff and this file |
| 513 | // get built at different times |
| 514 | extern "C" bool |
| 515 | LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name, |
| 516 | const char *session_dictionary_name, |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 517 | const lldb::StackFrameSP& sb_frame, |
Greg Clayton | 8afa543 | 2013-10-17 00:27:14 +0000 | [diff] [blame] | 518 | const lldb::BreakpointLocationSP& sb_bp_loc); |
Enrico Granata | be93a35 | 2011-08-16 16:49:25 +0000 | [diff] [blame] | 519 | |
Greg Clayton | 8afa543 | 2013-10-17 00:27:14 +0000 | [diff] [blame] | 520 | extern "C" bool |
| 521 | LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name, |
| 522 | const char *session_dictionary_name, |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 523 | const lldb::StackFrameSP& sb_frame, |
Greg Clayton | 8afa543 | 2013-10-17 00:27:14 +0000 | [diff] [blame] | 524 | const lldb::WatchpointSP& sb_wp); |
Greg Clayton | fc36f791 | 2011-03-22 01:14:58 +0000 | [diff] [blame] | 525 | |
Greg Clayton | 8afa543 | 2013-10-17 00:27:14 +0000 | [diff] [blame] | 526 | extern "C" bool |
| 527 | LLDBSwigPythonCallTypeScript (const char *python_function_name, |
| 528 | void *session_dictionary, |
| 529 | const lldb::ValueObjectSP& valobj_sp, |
| 530 | void** pyfunct_wrapper, |
| 531 | std::string& retval); |
| 532 | |
| 533 | extern "C" void* |
| 534 | LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name, |
| 535 | const char *session_dictionary_name, |
| 536 | const lldb::ValueObjectSP& valobj_sp); |
| 537 | |
| 538 | |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 539 | extern "C" void* |
| 540 | LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name, |
| 541 | const char *session_dictionary_name, |
| 542 | const lldb::ThreadPlanSP& thread_plan_sp); |
| 543 | |
| 544 | extern "C" bool |
| 545 | LLDBSWIGPythonCallThreadPlan (void *implementor, |
| 546 | const char *method_name, |
| 547 | Event *event_sp, |
| 548 | bool &got_error); |
| 549 | |
Greg Clayton | 8afa543 | 2013-10-17 00:27:14 +0000 | [diff] [blame] | 550 | extern "C" uint32_t |
| 551 | LLDBSwigPython_CalculateNumChildren (void *implementor); |
| 552 | |
| 553 | extern "C" void * |
| 554 | LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx); |
| 555 | |
| 556 | extern "C" int |
| 557 | LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name); |
| 558 | |
| 559 | extern "C" void * |
| 560 | LLDBSWIGPython_CastPyObjectToSBValue (void* data); |
| 561 | |
| 562 | extern lldb::ValueObjectSP |
| 563 | LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data); |
| 564 | |
| 565 | extern "C" bool |
| 566 | LLDBSwigPython_UpdateSynthProviderInstance (void* implementor); |
| 567 | |
| 568 | extern "C" bool |
| 569 | LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor); |
| 570 | |
Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 571 | extern "C" void * |
| 572 | LLDBSwigPython_GetValueSynthProviderInstance (void* implementor); |
| 573 | |
Greg Clayton | 8afa543 | 2013-10-17 00:27:14 +0000 | [diff] [blame] | 574 | extern "C" bool |
| 575 | LLDBSwigPythonCallCommand (const char *python_function_name, |
| 576 | const char *session_dictionary_name, |
| 577 | lldb::DebuggerSP& debugger, |
| 578 | const char* args, |
Enrico Granata | 06be059 | 2014-10-01 21:47:29 +0000 | [diff] [blame] | 579 | lldb_private::CommandReturnObject &cmd_retobj, |
| 580 | lldb::ExecutionContextRefSP exe_ctx_ref_sp); |
Greg Clayton | 8afa543 | 2013-10-17 00:27:14 +0000 | [diff] [blame] | 581 | |
| 582 | extern "C" bool |
| 583 | LLDBSwigPythonCallModuleInit (const char *python_module_name, |
| 584 | const char *session_dictionary_name, |
| 585 | lldb::DebuggerSP& debugger); |
| 586 | |
| 587 | extern "C" void* |
| 588 | LLDBSWIGPythonCreateOSPlugin (const char *python_class_name, |
| 589 | const char *session_dictionary_name, |
| 590 | const lldb::ProcessSP& process_sp); |
| 591 | |
| 592 | extern "C" bool |
| 593 | LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name, |
| 594 | const char* session_dictionary_name, |
| 595 | lldb::ProcessSP& process, |
| 596 | std::string& output); |
| 597 | |
| 598 | extern "C" bool |
| 599 | LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name, |
| 600 | const char* session_dictionary_name, |
| 601 | lldb::ThreadSP& thread, |
| 602 | std::string& output); |
| 603 | |
| 604 | extern "C" bool |
| 605 | LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name, |
| 606 | const char* session_dictionary_name, |
| 607 | lldb::TargetSP& target, |
| 608 | std::string& output); |
| 609 | |
| 610 | extern "C" bool |
| 611 | LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name, |
| 612 | const char* session_dictionary_name, |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 613 | lldb::StackFrameSP& frame, |
Greg Clayton | 8afa543 | 2013-10-17 00:27:14 +0000 | [diff] [blame] | 614 | std::string& output); |
| 615 | |
| 616 | extern "C" void* |
| 617 | LLDBSWIGPython_GetDynamicSetting (void* module, |
| 618 | const char* setting, |
| 619 | const lldb::TargetSP& target_sp); |
| 620 | |
Greg Clayton | dce502e | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 621 | |
| 622 | #endif |
| 623 | |
Greg Clayton | fc36f791 | 2011-03-22 01:14:58 +0000 | [diff] [blame] | 624 | void |
| 625 | SBCommandInterpreter::InitializeSWIG () |
| 626 | { |
| 627 | static bool g_initialized = false; |
| 628 | if (!g_initialized) |
| 629 | { |
| 630 | g_initialized = true; |
Greg Clayton | dce502e | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 631 | #ifndef LLDB_DISABLE_PYTHON |
Greg Clayton | 8afa543 | 2013-10-17 00:27:14 +0000 | [diff] [blame] | 632 | ScriptInterpreter::InitializeInterpreter (init_lldb, |
| 633 | LLDBSwigPythonBreakpointCallbackFunction, |
| 634 | LLDBSwigPythonWatchpointCallbackFunction, |
| 635 | LLDBSwigPythonCallTypeScript, |
| 636 | LLDBSwigPythonCreateSyntheticProvider, |
| 637 | LLDBSwigPython_CalculateNumChildren, |
| 638 | LLDBSwigPython_GetChildAtIndex, |
| 639 | LLDBSwigPython_GetIndexOfChildWithName, |
| 640 | LLDBSWIGPython_CastPyObjectToSBValue, |
| 641 | LLDBSWIGPython_GetValueObjectSPFromSBValue, |
| 642 | LLDBSwigPython_UpdateSynthProviderInstance, |
| 643 | LLDBSwigPython_MightHaveChildrenSynthProviderInstance, |
Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 644 | LLDBSwigPython_GetValueSynthProviderInstance, |
Greg Clayton | 8afa543 | 2013-10-17 00:27:14 +0000 | [diff] [blame] | 645 | LLDBSwigPythonCallCommand, |
| 646 | LLDBSwigPythonCallModuleInit, |
| 647 | LLDBSWIGPythonCreateOSPlugin, |
| 648 | LLDBSWIGPythonRunScriptKeywordProcess, |
| 649 | LLDBSWIGPythonRunScriptKeywordThread, |
| 650 | LLDBSWIGPythonRunScriptKeywordTarget, |
| 651 | LLDBSWIGPythonRunScriptKeywordFrame, |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 652 | LLDBSWIGPython_GetDynamicSetting, |
| 653 | LLDBSwigPythonCreateScriptedThreadPlan, |
| 654 | LLDBSWIGPythonCallThreadPlan); |
Greg Clayton | dce502e | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 655 | #endif |
Greg Clayton | fc36f791 | 2011-03-22 01:14:58 +0000 | [diff] [blame] | 656 | } |
| 657 | } |
Greg Clayton | a9f7b79 | 2012-02-29 04:21:24 +0000 | [diff] [blame] | 658 | |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 659 | lldb::SBCommand |
| 660 | SBCommandInterpreter::AddMultiwordCommand (const char* name, const char* help) |
| 661 | { |
| 662 | CommandObjectMultiword *new_command = new CommandObjectMultiword(*m_opaque_ptr,name,help); |
| 663 | new_command->SetRemovable (true); |
| 664 | lldb::CommandObjectSP new_command_sp(new_command); |
| 665 | if (new_command_sp && m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) |
| 666 | return lldb::SBCommand(new_command_sp); |
| 667 | return lldb::SBCommand(); |
| 668 | } |
| 669 | |
| 670 | lldb::SBCommand |
| 671 | SBCommandInterpreter::AddCommand (const char* name, lldb::SBCommandPluginInterface* impl, const char* help) |
| 672 | { |
| 673 | lldb::CommandObjectSP new_command_sp; |
| 674 | new_command_sp.reset(new CommandPluginInterfaceImplementation(*m_opaque_ptr,name,impl,help)); |
| 675 | |
| 676 | if (new_command_sp && m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) |
| 677 | return lldb::SBCommand(new_command_sp); |
| 678 | return lldb::SBCommand(); |
| 679 | } |
| 680 | |
| 681 | SBCommand::SBCommand () |
| 682 | {} |
| 683 | |
| 684 | SBCommand::SBCommand (lldb::CommandObjectSP cmd_sp) : m_opaque_sp (cmd_sp) |
| 685 | {} |
| 686 | |
| 687 | bool |
| 688 | SBCommand::IsValid () |
| 689 | { |
| 690 | return (bool)m_opaque_sp; |
| 691 | } |
| 692 | |
| 693 | const char* |
| 694 | SBCommand::GetName () |
| 695 | { |
| 696 | if (IsValid ()) |
| 697 | return m_opaque_sp->GetCommandName (); |
| 698 | return NULL; |
| 699 | } |
| 700 | |
| 701 | const char* |
| 702 | SBCommand::GetHelp () |
| 703 | { |
| 704 | if (IsValid ()) |
| 705 | return m_opaque_sp->GetHelp (); |
| 706 | return NULL; |
| 707 | } |
| 708 | |
| 709 | lldb::SBCommand |
| 710 | SBCommand::AddMultiwordCommand (const char* name, const char* help) |
| 711 | { |
| 712 | if (!IsValid ()) |
| 713 | return lldb::SBCommand(); |
| 714 | if (m_opaque_sp->IsMultiwordObject() == false) |
| 715 | return lldb::SBCommand(); |
| 716 | CommandObjectMultiword *new_command = new CommandObjectMultiword(m_opaque_sp->GetCommandInterpreter(),name,help); |
| 717 | new_command->SetRemovable (true); |
| 718 | lldb::CommandObjectSP new_command_sp(new_command); |
| 719 | if (new_command_sp && m_opaque_sp->LoadSubCommand(name,new_command_sp)) |
| 720 | return lldb::SBCommand(new_command_sp); |
| 721 | return lldb::SBCommand(); |
| 722 | } |
| 723 | |
| 724 | lldb::SBCommand |
| 725 | SBCommand::AddCommand (const char* name, lldb::SBCommandPluginInterface *impl, const char* help) |
| 726 | { |
| 727 | if (!IsValid ()) |
| 728 | return lldb::SBCommand(); |
| 729 | if (m_opaque_sp->IsMultiwordObject() == false) |
| 730 | return lldb::SBCommand(); |
| 731 | lldb::CommandObjectSP new_command_sp; |
| 732 | new_command_sp.reset(new CommandPluginInterfaceImplementation(m_opaque_sp->GetCommandInterpreter(),name,impl,help)); |
| 733 | if (new_command_sp && m_opaque_sp->LoadSubCommand(name,new_command_sp)) |
| 734 | return lldb::SBCommand(new_command_sp); |
| 735 | return lldb::SBCommand(); |
| 736 | } |
| 737 | |