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